MessageHandler.c 904 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436
  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)
  675. {
  676. int result = PASS;
  677. char* errMsg = NULL;
  678. char sqlStr[8192];
  679. sprintf(sqlStr, "insert into report_deduct_info(transactionId, creditNo, deductResult, isDonateInvoice, isUploaded) values('%d', '%s', '%d', '%d', '0');", txId, creditNo, deductResult, isDonateInvoice);
  680. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  681. {
  682. result = FAIL;
  683. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  684. }
  685. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  686. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  687. {
  688. result = FAIL;
  689. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  690. }
  691. return result;
  692. }
  693. int OCPP_update_deduct_info(int txId, char *creditNo)
  694. {
  695. int result = PASS;
  696. char* errMsg = NULL;
  697. char sqlStr[8192];
  698. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  699. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  700. {
  701. result = FAIL;
  702. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  703. }
  704. return result;
  705. }
  706. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  707. {
  708. json_object *deductData = json_object_new_object();
  709. json_object_object_add(deductData, "txId", json_object_new_int(atoi(columnValue[1])));
  710. json_object_object_add(deductData, "creditNo", json_object_new_string(columnValue[2]));
  711. json_object_object_add(deductData, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  712. json_object_object_add(deductData, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  713. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  714. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"ID_CreditDeductResult");
  715. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(deductData, JSON_C_TO_STRING_PLAIN));
  716. json_object_put(deductData);
  717. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  718. return 0;
  719. }
  720. void OCPP_query_deduct_info()
  721. {
  722. int rc = 0;
  723. char sql[100];
  724. char zErrMsg[100];
  725. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  726. /* Execute SQL statement */
  727. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  728. if( rc != SQLITE_OK )
  729. {
  730. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  731. }
  732. }
  733. //==========================================
  734. // Check time passed since today
  735. //==========================================
  736. long long DiffTimebWithNow(struct timeb ST)
  737. {
  738. //return milli-second
  739. struct timeb ET;
  740. long long StartTime,StopTime;
  741. ftime(&ET);
  742. StartTime=(long long)ST.time;
  743. StopTime=(long long)ET.time;
  744. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  745. }
  746. int getTimePassSinceToday(uint8_t gun_index)
  747. {
  748. int result = -1;
  749. static time_t lastTime[4];
  750. time_t t;
  751. struct tm *tmStartToday;
  752. struct timeb tbStartToday;
  753. t=time(NULL);
  754. if(difftime(t, lastTime[gun_index])>0)
  755. {
  756. tmStartToday=localtime(&t);
  757. tmStartToday->tm_hour = 0;
  758. tmStartToday->tm_min = 0;
  759. tmStartToday->tm_sec = 0;
  760. tbStartToday.time = mktime(tmStartToday);
  761. tbStartToday.millitm = 0;
  762. result = DiffTimebWithNow(tbStartToday)/1000;
  763. lastTime[gun_index] = t;
  764. }
  765. return result;
  766. }
  767. void getNowDatetime(uint8_t *data)
  768. {
  769. time_t t = time(NULL);
  770. struct tm tm = *localtime(&t);
  771. 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);
  772. }
  773. int syncDateTimeRTC(uint8_t *data)
  774. {
  775. struct ParsingResult
  776. {
  777. int result;
  778. int scanedElement;
  779. int year;
  780. int month;
  781. int mday;
  782. int hour;
  783. int min;
  784. int sec;
  785. int tz_hour;
  786. int tz_min;
  787. float minSec;
  788. }result;
  789. struct tm tmOrg;
  790. struct tm *tmTarget;
  791. struct timeb tbTarget;
  792. char buf[128];
  793. memset(&result, 0x00, sizeof(struct ParsingResult));
  794. result.result = PASS;
  795. if(strstr((char*)data, ".") != NULL)
  796. {
  797. // Original data with mini second
  798. if(strstr((char*)data, "Z") != NULL)
  799. {
  800. // Original data with Z
  801. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  802. &result.year,
  803. &result.month,
  804. &result.mday,
  805. &result.hour,
  806. &result.min,
  807. &result.sec,
  808. &result.minSec);
  809. }
  810. else
  811. {
  812. // Original data without Z
  813. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  814. &result.year,
  815. &result.month,
  816. &result.mday,
  817. &result.hour,
  818. &result.min,
  819. &result.sec,
  820. &result.minSec,
  821. &result.tz_hour,
  822. &result.tz_min);
  823. }
  824. }
  825. else
  826. {
  827. // Original data without mini second
  828. if(strstr((char*)data, "Z") != NULL)
  829. {
  830. // Original data with Z
  831. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  832. &result.year,
  833. &result.month,
  834. &result.mday,
  835. &result.hour,
  836. &result.min,
  837. &result.sec);
  838. }
  839. else
  840. {
  841. // Original data without Z
  842. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  843. &result.year,
  844. &result.month,
  845. &result.mday,
  846. &result.hour,
  847. &result.min,
  848. &result.sec,
  849. &result.tz_hour,
  850. &result.tz_min);
  851. }
  852. }
  853. tmOrg.tm_year = result.year - 1900;
  854. tmOrg.tm_mon = result.month - 1;
  855. tmOrg.tm_mday = result.mday;
  856. tmOrg.tm_hour = result.hour;
  857. tmOrg.tm_min = result.min;
  858. tmOrg.tm_sec = result.sec;
  859. tmOrg.tm_gmtoff = 0;
  860. tbTarget.time = mktime(&tmOrg);
  861. tbTarget.timezone = 0;
  862. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  863. tmTarget = gmtime(&tbTarget.time);
  864. 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);
  865. //DEBUG_INFO(" org date time: %s\n", data);
  866. //DEBUG_INFO("parse date time: %s\n", buf);
  867. system(buf);
  868. system("/sbin/hwclock -w --systohc");
  869. if(result.scanedElement < 6)
  870. result.result = FAIL;
  871. return result.result;
  872. }
  873. //==========================================
  874. // GetCompositeSchedule logic related function
  875. //==========================================
  876. int DiffTimebSec(struct timeb ST, struct timeb ET)
  877. {
  878. //return milli-second
  879. unsigned int StartTime,StopTime;
  880. StartTime=(unsigned int)ST.time;
  881. StopTime=(unsigned int)ET.time;
  882. return (StopTime-StartTime);
  883. }
  884. int DiffTimebWithNowSec(struct timeb ST)
  885. {
  886. //return milli-second
  887. struct timeb ET;
  888. unsigned int StartTime,StopTime;
  889. ftime(&ET);
  890. StartTime=(unsigned int)ST.time;
  891. StopTime=(unsigned int)ET.time;
  892. return (StopTime-StartTime);
  893. }
  894. int getStartStop(uint8_t *start, uint8_t *stop)
  895. {
  896. int result = -1;
  897. struct tm tmStart;
  898. struct timeb tbStart;
  899. struct tm tmStop;
  900. struct timeb tbStop;
  901. 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) &&
  902. (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))
  903. {
  904. //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);
  905. //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);
  906. tmStart.tm_year -= 1900;
  907. tmStart.tm_mon -= 1;
  908. tbStart.time = mktime(&tmStart);
  909. tbStart.millitm = 0;
  910. tmStop.tm_year -= 1900;
  911. tmStop.tm_mon -= 1;
  912. tbStop.time = mktime(&tmStop);
  913. tbStop.millitm = 0;
  914. result = DiffTimebSec(tbStart, tbStop);
  915. //DEBUG_INFO("getStartStop(): %d\n", result);
  916. }
  917. else
  918. {
  919. DEBUG_WARN("Start or stop date parsing error.\r\n");
  920. }
  921. return result;
  922. }
  923. int isOvertNow(uint8_t *start)
  924. {
  925. int result = NO;
  926. struct ParsingResult
  927. {
  928. int result;
  929. int scanedElement;
  930. int year;
  931. int month;
  932. int mday;
  933. int hour;
  934. int min;
  935. int sec;
  936. int tz_hour;
  937. int tz_min;
  938. float minSec;
  939. }parsingResult;
  940. struct tm tmStart;
  941. struct timeb tbStart;
  942. if(strstr((char*)start, ".") != NULL)
  943. {
  944. // Original data with mini second
  945. if(strstr((char*)start, "Z") != NULL)
  946. {
  947. // Original data with Z
  948. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  949. &parsingResult.year,
  950. &parsingResult.month,
  951. &parsingResult.mday,
  952. &parsingResult.hour,
  953. &parsingResult.min,
  954. &parsingResult.sec,
  955. &parsingResult.minSec);
  956. }
  957. else
  958. {
  959. // Original data without Z
  960. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  961. &parsingResult.year,
  962. &parsingResult.month,
  963. &parsingResult.mday,
  964. &parsingResult.hour,
  965. &parsingResult.min,
  966. &parsingResult.sec,
  967. &parsingResult.minSec,
  968. &parsingResult.tz_hour,
  969. &parsingResult.tz_min);
  970. }
  971. }
  972. else
  973. {
  974. // Original data without mini second
  975. if(strstr((char*)start, "Z") != NULL)
  976. {
  977. // Original data with Z
  978. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  979. &parsingResult.year,
  980. &parsingResult.month,
  981. &parsingResult.mday,
  982. &parsingResult.hour,
  983. &parsingResult.min,
  984. &parsingResult.sec);
  985. }
  986. else
  987. {
  988. // Original data without Z
  989. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  990. &parsingResult.year,
  991. &parsingResult.month,
  992. &parsingResult.mday,
  993. &parsingResult.hour,
  994. &parsingResult.min,
  995. &parsingResult.sec,
  996. &parsingResult.tz_hour,
  997. &parsingResult.tz_min);
  998. }
  999. }
  1000. if(parsingResult.scanedElement >= 6)
  1001. {
  1002. tmStart.tm_year = parsingResult.year - 1900;
  1003. tmStart.tm_mon = parsingResult.month - 1;
  1004. tmStart.tm_mday = parsingResult.mday;
  1005. tmStart.tm_hour = parsingResult.hour;
  1006. tmStart.tm_min = parsingResult.min;
  1007. tmStart.tm_sec = parsingResult.sec;
  1008. tmStart.tm_gmtoff = 0;
  1009. tbStart.time = mktime(&tmStart);
  1010. tbStart.timezone = 0;
  1011. tbStart.millitm = 0;
  1012. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1013. if(DiffTimebWithNowSec(tbStart) <= 0)
  1014. result = NO;
  1015. else
  1016. result = YES;
  1017. }
  1018. else
  1019. {
  1020. DEBUG_WARN("Start date parsing error.\n");
  1021. }
  1022. return result;
  1023. }
  1024. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1025. {
  1026. int result = -1;
  1027. struct tm tmStart;
  1028. struct timeb tbStart;
  1029. struct tm tmStop;
  1030. struct timeb tbStop;
  1031. 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) &&
  1032. (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))
  1033. {
  1034. tmStart.tm_year -= 1900;
  1035. tmStart.tm_mon -= 1;
  1036. tbStart.time = mktime(&tmStart);
  1037. tbStart.millitm = 0;
  1038. tmStop.tm_year -= 1900;
  1039. tmStop.tm_mon -= 1;
  1040. tbStop.time = mktime(&tmStop);
  1041. tbStop.millitm = 0;
  1042. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1043. }
  1044. return result;
  1045. }
  1046. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1047. {
  1048. FILE *fp;
  1049. char profileFileName[128];
  1050. char *line = NULL;
  1051. size_t len = 0;
  1052. time_t CurrentTime;
  1053. struct tm *tmComposite;
  1054. struct StructChargingProfile maxProfile;
  1055. uint8_t limitMax=0;
  1056. int compositePeriodIdx = 0;
  1057. CurrentTime = time(NULL);
  1058. tmComposite=localtime(&CurrentTime);
  1059. 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);
  1060. if(isUnitA)
  1061. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1062. else
  1063. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1064. compositeProfile->ChargingSchedule.Duration = durationReq;
  1065. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1066. {
  1067. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1068. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1069. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1070. }
  1071. compositeProfile->ChargingProfileId = 0;
  1072. compositeProfile->StackLevel = 99 ;
  1073. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1074. maxProfile.ChargingProfileId = -1;
  1075. maxProfile.ChargingSchedule.Duration = -1;
  1076. system("rm -f /tmp/*.json");
  1077. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1078. // Search max profile
  1079. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1080. if((access(profileFileName, F_OK))!=-1)
  1081. {
  1082. fp = fopen(profileFileName, "r");
  1083. while(getline(&line, &len, fp) != -1)
  1084. {
  1085. json_object *obj = NULL;
  1086. obj = json_tokener_parse(line);
  1087. if(is_error(obj))
  1088. {
  1089. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1090. }
  1091. else
  1092. {
  1093. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1094. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1095. )
  1096. {
  1097. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1098. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1099. )
  1100. {
  1101. struct tm tmFrom, tmTo;
  1102. struct timeb tbFrom, tbTo;
  1103. 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) &&
  1104. (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))
  1105. {
  1106. tmFrom.tm_year -= 1900;
  1107. tmFrom.tm_mon -= 1;
  1108. tbFrom.time = mktime(&tmFrom);
  1109. tmTo.tm_year -= 1900;
  1110. tmTo.tm_mon -= 1;
  1111. tbTo.time = mktime(&tmTo);
  1112. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1113. {
  1114. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1115. {
  1116. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1117. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1118. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1119. }
  1120. maxProfile.ChargingProfileId = -1;
  1121. maxProfile.StackLevel = -1;
  1122. if(maxProfile.ChargingProfileId == -1)
  1123. DEBUG_INFO("MaxProfile found.\n");
  1124. else
  1125. DEBUG_INFO("MaxProfile updated.\n");
  1126. // Required item
  1127. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1128. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1129. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1130. if(isUnitA)
  1131. {
  1132. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1133. 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++)
  1134. {
  1135. 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"));
  1136. 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?
  1137. 3:
  1138. 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")));
  1139. 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")));
  1140. }
  1141. }
  1142. else
  1143. {
  1144. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1145. 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++)
  1146. {
  1147. 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"));
  1148. 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?
  1149. 3:
  1150. 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")));
  1151. 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));
  1152. }
  1153. }
  1154. // Optional item
  1155. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1156. {
  1157. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1158. }
  1159. else
  1160. {
  1161. sprintf((char*)maxProfile.ValidFrom, " ");
  1162. }
  1163. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1164. {
  1165. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1166. }
  1167. else
  1168. {
  1169. sprintf((char*)maxProfile.ValidTo, " ");
  1170. }
  1171. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1172. {
  1173. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1174. }
  1175. else
  1176. {
  1177. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1178. }
  1179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1180. {
  1181. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1182. }
  1183. else
  1184. {
  1185. maxProfile.TransactionId = -1;
  1186. }
  1187. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1188. {
  1189. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1190. }
  1191. else
  1192. {
  1193. maxProfile.ChargingSchedule.Duration = 86400;
  1194. }
  1195. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1196. {
  1197. 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")));
  1198. }
  1199. else
  1200. {
  1201. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1202. }
  1203. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1204. {
  1205. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1206. }
  1207. else
  1208. {
  1209. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1210. }
  1211. }
  1212. }
  1213. }
  1214. else
  1215. {
  1216. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1217. {
  1218. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1219. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1220. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1221. }
  1222. maxProfile.ChargingProfileId = -1;
  1223. maxProfile.StackLevel = -1;
  1224. if(maxProfile.ChargingProfileId == -1)
  1225. DEBUG_INFO("MaxProfile found.\n");
  1226. else
  1227. DEBUG_INFO("MaxProfile updated.\n");
  1228. // Required item
  1229. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1230. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1231. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1232. if(isUnitA)
  1233. {
  1234. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1235. 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++)
  1236. {
  1237. 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"));
  1238. 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?
  1239. 3:
  1240. 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")));
  1241. 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")));
  1242. }
  1243. }
  1244. else
  1245. {
  1246. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1247. 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++)
  1248. {
  1249. 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"));
  1250. 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?
  1251. 3:
  1252. 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")));
  1253. 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));
  1254. }
  1255. }
  1256. // Optional item
  1257. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1258. {
  1259. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1260. }
  1261. else
  1262. {
  1263. sprintf((char*)maxProfile.ValidFrom, " ");
  1264. }
  1265. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1266. {
  1267. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1268. }
  1269. else
  1270. {
  1271. sprintf((char*)maxProfile.ValidTo, " ");
  1272. }
  1273. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1274. {
  1275. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1276. }
  1277. else
  1278. {
  1279. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1280. }
  1281. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1282. {
  1283. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1284. }
  1285. else
  1286. {
  1287. maxProfile.TransactionId = -1;
  1288. }
  1289. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1290. {
  1291. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1292. }
  1293. else
  1294. {
  1295. maxProfile.ChargingSchedule.Duration = 86400;
  1296. }
  1297. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1298. {
  1299. 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")));
  1300. }
  1301. else
  1302. {
  1303. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1304. }
  1305. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1306. {
  1307. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1308. }
  1309. else
  1310. {
  1311. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1312. }
  1313. }
  1314. }
  1315. }
  1316. json_object_put(obj);
  1317. }
  1318. fclose(fp);
  1319. /*
  1320. if(maxProfile.ChargingProfileId !=-1)
  1321. {
  1322. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1323. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1324. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1325. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1326. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1327. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1328. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1329. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1330. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1331. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1332. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1333. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1334. {
  1335. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1336. {
  1337. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1338. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1339. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1340. }
  1341. }
  1342. }
  1343. else
  1344. DEBUG_INFO("MaxProfile not found.\n");
  1345. DEBUG_INFO("------------------------------------\n");*/
  1346. }
  1347. if(maxProfile.ChargingProfileId != -1)
  1348. {
  1349. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1350. {
  1351. if(maxProfile.ChargingSchedule.Duration != -1)
  1352. {
  1353. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1354. 0:
  1355. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1356. }
  1357. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1358. {
  1359. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1360. {
  1361. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1362. 0:
  1363. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1364. if(idxPeriod > 0)
  1365. {
  1366. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1367. {
  1368. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1369. }
  1370. }
  1371. }
  1372. }
  1373. }
  1374. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1375. {
  1376. if(maxProfile.ChargingSchedule.Duration != -1)
  1377. {
  1378. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1379. }
  1380. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1381. {
  1382. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1383. {
  1384. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1385. if(idxPeriod > 0)
  1386. {
  1387. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1388. {
  1389. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1390. }
  1391. }
  1392. }
  1393. }
  1394. }
  1395. else
  1396. {
  1397. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1398. {
  1399. if(maxProfile.ChargingSchedule.Duration != -1)
  1400. {
  1401. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1402. 0:
  1403. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1404. }
  1405. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1406. {
  1407. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1408. {
  1409. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1410. 0:
  1411. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1412. if(idxPeriod > 0)
  1413. {
  1414. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1415. {
  1416. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1417. }
  1418. }
  1419. }
  1420. }
  1421. }
  1422. else
  1423. {
  1424. if(maxProfile.ChargingSchedule.Duration != -1)
  1425. {
  1426. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1427. 0:
  1428. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1429. }
  1430. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1431. {
  1432. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1433. {
  1434. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1435. 0:
  1436. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1437. if(idxPeriod > 0)
  1438. {
  1439. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1440. {
  1441. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1442. }
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. /*
  1449. DEBUG_INFO("MaxProfile after align.\n");
  1450. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1451. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1452. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1453. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1454. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1455. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1456. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1457. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1458. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1459. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1460. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1461. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1462. {
  1463. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1464. {
  1465. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1466. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1467. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1468. }
  1469. }
  1470. DEBUG_INFO("------------------------------------\n");*/
  1471. }
  1472. // Find each profile period quantity
  1473. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1474. {
  1475. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1476. limitMax = idx+1;
  1477. }
  1478. if(maxProfile.ChargingProfileId != -1)
  1479. {
  1480. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1481. {
  1482. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1483. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1484. (maxProfile.ChargingSchedule.Duration > 0))
  1485. {
  1486. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1487. {
  1488. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1489. compositePeriodIdx++;
  1490. }
  1491. else
  1492. {
  1493. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1494. }
  1495. }
  1496. }
  1497. }
  1498. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1499. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1500. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1501. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1502. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1503. {
  1504. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1505. {
  1506. compositeProfile->ChargingProfileId = 1;
  1507. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1508. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1509. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1510. }
  1511. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1512. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1513. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1514. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1515. }
  1516. if(line)
  1517. free(line);
  1518. }
  1519. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1520. {
  1521. FILE *fp;
  1522. char profileFileName[128];
  1523. char *line = NULL;
  1524. size_t len = 0;
  1525. time_t CurrentTime;
  1526. struct tm *tmComposite;
  1527. struct StructChargingProfile maxProfile;
  1528. struct StructChargingProfile defaultTxProfile;
  1529. struct StructChargingProfile txProfile;
  1530. struct StructChargingSchedulePeriod tmpPeriod;
  1531. uint8_t limitMax=0;
  1532. uint8_t limitDef=0;
  1533. uint8_t limitTx=0;
  1534. int compositePeriodIdx = 0;
  1535. CurrentTime = time(NULL);
  1536. tmComposite=localtime(&CurrentTime);
  1537. 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);
  1538. if(isUnitA)
  1539. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1540. else
  1541. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1542. compositeProfile->ChargingSchedule.Duration = durationReq;
  1543. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1544. {
  1545. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1546. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1547. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1548. }
  1549. compositeProfile->ChargingProfileId = 0;
  1550. compositeProfile->StackLevel = 99 ;
  1551. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1552. maxProfile.ChargingProfileId = -1;
  1553. defaultTxProfile.ChargingProfileId = -1;
  1554. txProfile.ChargingProfileId = -1;
  1555. maxProfile.ChargingSchedule.Duration = -1;
  1556. defaultTxProfile.ChargingSchedule.Duration = -1;
  1557. txProfile.ChargingSchedule.Duration = -1;
  1558. system("rm -f /tmp/*.json");
  1559. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1560. /*
  1561. * Search valid charging profile
  1562. */
  1563. //DEBUG_INFO("====================================\n");
  1564. // Search tx profile
  1565. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1566. if((access(profileFileName, F_OK))!=-1)
  1567. {
  1568. fp = fopen(profileFileName, "r");
  1569. while(getline(&line, &len, fp) != -1)
  1570. {
  1571. json_object *obj = NULL;
  1572. obj = json_tokener_parse(line);
  1573. if(is_error(obj))
  1574. {
  1575. DEBUG_ERROR("Parse txProfile from file error.\n");
  1576. }
  1577. else
  1578. {
  1579. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1580. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1581. )
  1582. {
  1583. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1584. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1585. )
  1586. {
  1587. struct tm tmFrom, tmTo;
  1588. struct timeb tbFrom, tbTo;
  1589. 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) &&
  1590. (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))
  1591. {
  1592. tmFrom.tm_year -= 1900;
  1593. tmFrom.tm_mon -= 1;
  1594. tbFrom.time = mktime(&tmFrom);
  1595. tmTo.tm_year -= 1900;
  1596. tmTo.tm_mon -= 1;
  1597. tbTo.time = mktime(&tmTo);
  1598. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1599. {
  1600. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1601. {
  1602. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1603. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1604. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1605. }
  1606. txProfile.ChargingProfileId = -1;
  1607. txProfile.StackLevel = -1;
  1608. if(txProfile.ChargingProfileId == -1)
  1609. DEBUG_INFO("TxProfile found.\n");
  1610. else
  1611. DEBUG_INFO("TxProfile updated.\n");
  1612. // Required item
  1613. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1614. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1615. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1616. if(isUnitA)
  1617. {
  1618. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1619. 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++)
  1620. {
  1621. 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"));
  1622. 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?
  1623. 3:
  1624. 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")));
  1625. 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")));
  1626. }
  1627. }
  1628. else
  1629. {
  1630. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1631. 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++)
  1632. {
  1633. 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"));
  1634. 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?
  1635. 3:
  1636. 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")));
  1637. 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));
  1638. }
  1639. }
  1640. // Optional item
  1641. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1642. {
  1643. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1644. }
  1645. else
  1646. {
  1647. sprintf((char*)txProfile.ValidFrom, " ");
  1648. }
  1649. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1650. {
  1651. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1652. }
  1653. else
  1654. {
  1655. sprintf((char*)txProfile.ValidTo, " ");
  1656. }
  1657. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1658. {
  1659. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1660. }
  1661. else
  1662. {
  1663. sprintf((char*)txProfile.RecurrencyKind, " ");
  1664. }
  1665. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1666. {
  1667. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1668. }
  1669. else
  1670. {
  1671. txProfile.TransactionId = -1;
  1672. }
  1673. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1674. {
  1675. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1676. }
  1677. else
  1678. {
  1679. txProfile.ChargingSchedule.Duration = 86400;
  1680. }
  1681. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1682. {
  1683. 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")));
  1684. }
  1685. else
  1686. {
  1687. 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));
  1688. }
  1689. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1690. {
  1691. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1692. }
  1693. else
  1694. {
  1695. txProfile.ChargingSchedule.MinChargingRate = -1;
  1696. }
  1697. }
  1698. }
  1699. }
  1700. else
  1701. {
  1702. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1703. {
  1704. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1705. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1706. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1707. }
  1708. txProfile.ChargingProfileId = -1;
  1709. txProfile.StackLevel = -1;
  1710. if(txProfile.ChargingProfileId == -1)
  1711. DEBUG_INFO("TxProfile found.\n");
  1712. else
  1713. DEBUG_INFO("TxProfile updated.\n");
  1714. // Required item
  1715. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1716. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1717. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1718. if(isUnitA)
  1719. {
  1720. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1721. 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++)
  1722. {
  1723. 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"));
  1724. 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?
  1725. 3:
  1726. 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")));
  1727. 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")));
  1728. }
  1729. }
  1730. else
  1731. {
  1732. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1733. 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++)
  1734. {
  1735. 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"));
  1736. 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?
  1737. 3:
  1738. 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")));
  1739. 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));
  1740. }
  1741. }
  1742. // Optional item
  1743. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1744. {
  1745. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1746. }
  1747. else
  1748. {
  1749. sprintf((char*)txProfile.ValidFrom, " ");
  1750. }
  1751. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1752. {
  1753. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1754. }
  1755. else
  1756. {
  1757. sprintf((char*)txProfile.ValidTo, " ");
  1758. }
  1759. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1760. {
  1761. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1762. }
  1763. else
  1764. {
  1765. sprintf((char*)txProfile.RecurrencyKind, " ");
  1766. }
  1767. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1768. {
  1769. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1770. }
  1771. else
  1772. {
  1773. txProfile.TransactionId = -1;
  1774. }
  1775. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1776. {
  1777. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1778. }
  1779. else
  1780. {
  1781. txProfile.ChargingSchedule.Duration = 86400;
  1782. }
  1783. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1784. {
  1785. 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")));
  1786. }
  1787. else
  1788. {
  1789. 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));
  1790. }
  1791. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1792. {
  1793. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1794. }
  1795. else
  1796. {
  1797. txProfile.ChargingSchedule.MinChargingRate = -1;
  1798. }
  1799. }
  1800. }
  1801. }
  1802. json_object_put(obj);
  1803. }
  1804. fclose(fp);
  1805. /*
  1806. if(txProfile.ChargingProfileId != -1)
  1807. {
  1808. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1809. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1810. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1811. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1812. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1813. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1814. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1815. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1816. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1817. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1818. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1819. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1820. {
  1821. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1822. {
  1823. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1824. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1825. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1826. }
  1827. }
  1828. }
  1829. else
  1830. DEBUG_INFO("TxProfile not found.\n");*/
  1831. }
  1832. // Search default tx profile
  1833. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1834. if((access(profileFileName, F_OK))==-1)
  1835. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1836. if((access(profileFileName, F_OK))!=-1)
  1837. {
  1838. fp = fopen(profileFileName, "r");
  1839. while(getline(&line, &len, fp) != -1)
  1840. {
  1841. json_object *obj = NULL;
  1842. obj = json_tokener_parse(line);
  1843. if(is_error(obj))
  1844. {
  1845. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1846. }
  1847. else
  1848. {
  1849. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1850. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1851. )
  1852. {
  1853. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1854. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1855. )
  1856. {
  1857. struct tm tmFrom, tmTo;
  1858. struct timeb tbFrom, tbTo;
  1859. 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) &&
  1860. (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))
  1861. {
  1862. tmFrom.tm_year -= 1900;
  1863. tmFrom.tm_mon -= 1;
  1864. tbFrom.time = mktime(&tmFrom);
  1865. tmTo.tm_year -= 1900;
  1866. tmTo.tm_mon -= 1;
  1867. tbTo.time = mktime(&tmTo);
  1868. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1869. {
  1870. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1871. {
  1872. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1873. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1874. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1875. }
  1876. defaultTxProfile.ChargingProfileId = -1;
  1877. defaultTxProfile.StackLevel = -1;
  1878. if(defaultTxProfile.ChargingProfileId == -1)
  1879. DEBUG_INFO("TxDefaultProfile found.\n");
  1880. else
  1881. DEBUG_INFO("TxDefaultProfile updated.\n");
  1882. // Required item
  1883. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1884. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1885. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1886. if(isUnitA)
  1887. {
  1888. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1889. 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++)
  1890. {
  1891. 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"));
  1892. 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?
  1893. 3:
  1894. 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")));
  1895. 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")));
  1896. }
  1897. }
  1898. else
  1899. {
  1900. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1901. 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++)
  1902. {
  1903. 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"));
  1904. 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?
  1905. 3:
  1906. 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")));
  1907. 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));
  1908. }
  1909. }
  1910. // Optional item
  1911. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1912. {
  1913. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1914. }
  1915. else
  1916. {
  1917. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1918. }
  1919. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1920. {
  1921. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1922. }
  1923. else
  1924. {
  1925. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1926. }
  1927. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1928. {
  1929. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1930. }
  1931. else
  1932. {
  1933. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1934. }
  1935. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1936. {
  1937. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1938. }
  1939. else
  1940. {
  1941. defaultTxProfile.TransactionId = -1;
  1942. }
  1943. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1944. {
  1945. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1946. }
  1947. else
  1948. {
  1949. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1950. }
  1951. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1952. {
  1953. 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")));
  1954. }
  1955. else
  1956. {
  1957. 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));
  1958. }
  1959. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1960. {
  1961. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1962. }
  1963. else
  1964. {
  1965. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1966. }
  1967. }
  1968. }
  1969. }
  1970. else
  1971. {
  1972. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1973. {
  1974. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1975. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1976. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1977. }
  1978. defaultTxProfile.ChargingProfileId = -1;
  1979. defaultTxProfile.StackLevel = -1;
  1980. if(defaultTxProfile.ChargingProfileId == -1)
  1981. DEBUG_INFO("TxDefaultProfile found.\n");
  1982. else
  1983. DEBUG_INFO("TxDefaultProfile updated.\n");
  1984. // Required item
  1985. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1986. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1987. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1988. if(isUnitA)
  1989. {
  1990. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1991. 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++)
  1992. {
  1993. 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"));
  1994. 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?
  1995. 3:
  1996. 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")));
  1997. 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")));
  1998. }
  1999. }
  2000. else
  2001. {
  2002. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2003. 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++)
  2004. {
  2005. 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"));
  2006. 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?
  2007. 3:
  2008. 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")));
  2009. 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));
  2010. }
  2011. }
  2012. // Optional item
  2013. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2014. {
  2015. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2016. }
  2017. else
  2018. {
  2019. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2020. }
  2021. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2022. {
  2023. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2024. }
  2025. else
  2026. {
  2027. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2028. }
  2029. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2030. {
  2031. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2032. }
  2033. else
  2034. {
  2035. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2036. }
  2037. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2038. {
  2039. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2040. }
  2041. else
  2042. {
  2043. defaultTxProfile.TransactionId = -1;
  2044. }
  2045. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2046. {
  2047. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2048. }
  2049. else
  2050. {
  2051. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2052. }
  2053. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2054. {
  2055. 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")));
  2056. }
  2057. else
  2058. {
  2059. 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));
  2060. }
  2061. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2062. {
  2063. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2064. }
  2065. else
  2066. {
  2067. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2068. }
  2069. }
  2070. }
  2071. }
  2072. json_object_put(obj);
  2073. }
  2074. fclose(fp);
  2075. /*
  2076. if(defaultTxProfile.ChargingProfileId != -1)
  2077. {
  2078. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2079. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2080. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2081. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2082. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2083. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2084. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2085. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2086. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2087. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2088. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2089. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2090. {
  2091. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2092. {
  2093. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2094. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2095. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2096. }
  2097. }
  2098. }
  2099. else
  2100. DEBUG_INFO("TxDefaultProfile not found.\n");
  2101. DEBUG_INFO("------------------------------------\n");*/
  2102. }
  2103. // Search max profile
  2104. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2105. if((access(profileFileName, F_OK))!=-1)
  2106. {
  2107. fp = fopen(profileFileName, "r");
  2108. while(getline(&line, &len, fp) != -1)
  2109. {
  2110. json_object *obj = NULL;
  2111. obj = json_tokener_parse(line);
  2112. if(is_error(obj))
  2113. {
  2114. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2115. }
  2116. else
  2117. {
  2118. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2119. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2120. )
  2121. {
  2122. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2123. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2124. )
  2125. {
  2126. struct tm tmFrom, tmTo;
  2127. struct timeb tbFrom, tbTo;
  2128. 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) &&
  2129. (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))
  2130. {
  2131. tmFrom.tm_year -= 1900;
  2132. tmFrom.tm_mon -= 1;
  2133. tbFrom.time = mktime(&tmFrom);
  2134. tmTo.tm_year -= 1900;
  2135. tmTo.tm_mon -= 1;
  2136. tbTo.time = mktime(&tmTo);
  2137. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2138. {
  2139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2140. {
  2141. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2142. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2143. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2144. }
  2145. maxProfile.ChargingProfileId = -1;
  2146. maxProfile.StackLevel = -1;
  2147. if(maxProfile.ChargingProfileId == -1)
  2148. DEBUG_INFO("MaxProfile found.\n");
  2149. else
  2150. DEBUG_INFO("MaxProfile updated.\n");
  2151. // Required item
  2152. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2153. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2154. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2155. if(isUnitA)
  2156. {
  2157. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2158. 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++)
  2159. {
  2160. 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"));
  2161. 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?
  2162. 3:
  2163. 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")));
  2164. 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")));
  2165. }
  2166. }
  2167. else
  2168. {
  2169. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2170. 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++)
  2171. {
  2172. 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"));
  2173. 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?
  2174. 3:
  2175. 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")));
  2176. 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));
  2177. }
  2178. }
  2179. // Optional item
  2180. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2181. {
  2182. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2183. }
  2184. else
  2185. {
  2186. sprintf((char*)maxProfile.ValidFrom, " ");
  2187. }
  2188. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2189. {
  2190. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2191. }
  2192. else
  2193. {
  2194. sprintf((char*)maxProfile.ValidTo, " ");
  2195. }
  2196. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2197. {
  2198. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2199. }
  2200. else
  2201. {
  2202. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2203. }
  2204. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2205. {
  2206. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2207. }
  2208. else
  2209. {
  2210. maxProfile.TransactionId = -1;
  2211. }
  2212. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2213. {
  2214. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2215. }
  2216. else
  2217. {
  2218. maxProfile.ChargingSchedule.Duration = 86400;
  2219. }
  2220. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2221. {
  2222. 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")));
  2223. }
  2224. else
  2225. {
  2226. 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));
  2227. }
  2228. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2229. {
  2230. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2231. }
  2232. else
  2233. {
  2234. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2235. }
  2236. }
  2237. }
  2238. }
  2239. else
  2240. {
  2241. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2242. {
  2243. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2244. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2245. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2246. }
  2247. maxProfile.ChargingProfileId = -1;
  2248. maxProfile.StackLevel = -1;
  2249. if(maxProfile.ChargingProfileId == -1)
  2250. DEBUG_INFO("MaxProfile found.\n");
  2251. else
  2252. DEBUG_INFO("MaxProfile updated.\n");
  2253. // Required item
  2254. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2255. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2256. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2257. if(isUnitA)
  2258. {
  2259. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2260. 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++)
  2261. {
  2262. 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"));
  2263. 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?
  2264. 3:
  2265. 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")));
  2266. 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")));
  2267. }
  2268. }
  2269. else
  2270. {
  2271. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2272. 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++)
  2273. {
  2274. 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"));
  2275. 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?
  2276. 3:
  2277. 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")));
  2278. 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));
  2279. }
  2280. }
  2281. // Optional item
  2282. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2283. {
  2284. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2285. }
  2286. else
  2287. {
  2288. sprintf((char*)maxProfile.ValidFrom, " ");
  2289. }
  2290. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2291. {
  2292. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2293. }
  2294. else
  2295. {
  2296. sprintf((char*)maxProfile.ValidTo, " ");
  2297. }
  2298. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2299. {
  2300. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2301. }
  2302. else
  2303. {
  2304. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2305. }
  2306. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2307. {
  2308. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2309. }
  2310. else
  2311. {
  2312. maxProfile.TransactionId = -1;
  2313. }
  2314. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2315. {
  2316. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2317. }
  2318. else
  2319. {
  2320. maxProfile.ChargingSchedule.Duration = 86400;
  2321. }
  2322. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2323. {
  2324. 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")));
  2325. }
  2326. else
  2327. {
  2328. 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));
  2329. }
  2330. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2331. {
  2332. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2333. }
  2334. else
  2335. {
  2336. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2337. }
  2338. }
  2339. }
  2340. }
  2341. json_object_put(obj);
  2342. }
  2343. fclose(fp);
  2344. /*
  2345. if(maxProfile.ChargingProfileId !=-1)
  2346. {
  2347. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2348. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2349. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2350. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2351. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2352. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2353. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2354. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2355. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2356. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2357. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2358. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2359. {
  2360. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2361. {
  2362. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2363. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2364. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2365. }
  2366. }
  2367. }
  2368. else
  2369. DEBUG_INFO("MaxProfile not found.\n");
  2370. DEBUG_INFO("------------------------------------\n");*/
  2371. }
  2372. /*
  2373. * Align found profile start schedule & periods
  2374. */
  2375. //DEBUG_INFO("====================================\n");
  2376. /*
  2377. // For local test usage, force modify found profile start schedule info
  2378. 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);
  2379. 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);
  2380. 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);
  2381. */
  2382. if(txProfile.ChargingProfileId != -1)
  2383. {
  2384. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2385. {
  2386. if(txProfile.ChargingSchedule.Duration != -1)
  2387. {
  2388. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2389. 0:
  2390. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2391. }
  2392. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2393. {
  2394. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2395. {
  2396. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2397. 0:
  2398. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2399. if(idxPeriod > 0)
  2400. {
  2401. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2402. {
  2403. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2410. {
  2411. if(txProfile.ChargingSchedule.Duration != -1)
  2412. {
  2413. 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?
  2414. 0:
  2415. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2416. }
  2417. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2418. {
  2419. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2420. {
  2421. 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?
  2422. 0:
  2423. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2424. if(idxPeriod > 0)
  2425. {
  2426. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2427. {
  2428. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. else
  2435. {
  2436. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2437. {
  2438. if(txProfile.ChargingSchedule.Duration != -1)
  2439. {
  2440. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2441. 0:
  2442. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2443. }
  2444. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2445. {
  2446. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2447. {
  2448. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2449. 0:
  2450. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2451. if(idxPeriod > 0)
  2452. {
  2453. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2454. {
  2455. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2456. }
  2457. }
  2458. }
  2459. }
  2460. }
  2461. else
  2462. {
  2463. if(txProfile.ChargingSchedule.Duration != -1)
  2464. {
  2465. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2466. 0:
  2467. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2468. }
  2469. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2470. {
  2471. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2472. {
  2473. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2474. 0:
  2475. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2476. if(idxPeriod > 0)
  2477. {
  2478. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2479. {
  2480. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2481. }
  2482. }
  2483. }
  2484. }
  2485. }
  2486. }
  2487. /*
  2488. DEBUG_INFO("txProfile after align.\n");
  2489. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2490. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2491. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2492. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2493. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2494. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2495. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2496. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2497. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2498. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2499. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2500. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2501. {
  2502. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2503. {
  2504. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2505. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2506. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2507. }
  2508. }*/
  2509. }
  2510. if(defaultTxProfile.ChargingProfileId != -1)
  2511. {
  2512. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2513. {
  2514. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2515. {
  2516. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2517. 0:
  2518. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2519. }
  2520. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2521. {
  2522. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2523. {
  2524. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2525. 0:
  2526. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2527. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2528. {
  2529. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2530. }
  2531. if(idxPeriod > 0)
  2532. {
  2533. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2534. {
  2535. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2536. }
  2537. }
  2538. }
  2539. }
  2540. }
  2541. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2542. {
  2543. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2544. {
  2545. 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?
  2546. 0:
  2547. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2548. }
  2549. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2550. {
  2551. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2552. {
  2553. 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?
  2554. 0:
  2555. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2556. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2557. {
  2558. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2559. }
  2560. if(idxPeriod > 0)
  2561. {
  2562. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2563. {
  2564. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2565. }
  2566. }
  2567. }
  2568. }
  2569. }
  2570. else
  2571. {
  2572. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2573. {
  2574. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2575. {
  2576. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2577. 0:
  2578. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2579. }
  2580. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2581. {
  2582. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2583. {
  2584. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2585. 0:
  2586. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2587. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2588. {
  2589. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2590. }
  2591. if(idxPeriod > 0)
  2592. {
  2593. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2594. {
  2595. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2596. }
  2597. }
  2598. }
  2599. }
  2600. }
  2601. else
  2602. {
  2603. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2604. {
  2605. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2606. 0:
  2607. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2608. }
  2609. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2610. {
  2611. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2612. {
  2613. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2614. 0:
  2615. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2616. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2617. {
  2618. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2619. }
  2620. if(idxPeriod > 0)
  2621. {
  2622. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2623. {
  2624. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2625. }
  2626. }
  2627. }
  2628. }
  2629. }
  2630. }
  2631. /*
  2632. DEBUG_INFO("defaultTxProfile after align.\n");
  2633. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2634. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2635. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2636. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2637. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2638. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2639. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2640. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2641. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2642. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2643. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2644. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2645. {
  2646. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2647. {
  2648. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2649. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2650. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2651. }
  2652. }
  2653. DEBUG_INFO("------------------------------------\n");*/
  2654. }
  2655. if(maxProfile.ChargingProfileId != -1)
  2656. {
  2657. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2658. {
  2659. if(maxProfile.ChargingSchedule.Duration != -1)
  2660. {
  2661. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2662. 0:
  2663. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2664. }
  2665. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2666. {
  2667. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2668. {
  2669. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2670. 0:
  2671. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2672. if(idxPeriod > 0)
  2673. {
  2674. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2675. {
  2676. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2677. }
  2678. }
  2679. }
  2680. }
  2681. }
  2682. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2683. {
  2684. if(maxProfile.ChargingSchedule.Duration != -1)
  2685. {
  2686. 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?
  2687. 0:
  2688. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2689. }
  2690. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2691. {
  2692. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2693. {
  2694. 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?
  2695. 0:
  2696. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2697. if(idxPeriod > 0)
  2698. {
  2699. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2700. {
  2701. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2702. }
  2703. }
  2704. }
  2705. }
  2706. }
  2707. else
  2708. {
  2709. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2710. {
  2711. if(maxProfile.ChargingSchedule.Duration != -1)
  2712. {
  2713. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2714. 0:
  2715. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2716. }
  2717. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2718. {
  2719. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2720. {
  2721. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2722. 0:
  2723. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2724. if(idxPeriod > 0)
  2725. {
  2726. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2727. {
  2728. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2729. }
  2730. }
  2731. }
  2732. }
  2733. }
  2734. else
  2735. {
  2736. if(maxProfile.ChargingSchedule.Duration != -1)
  2737. {
  2738. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2739. 0:
  2740. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2741. }
  2742. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2743. {
  2744. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2745. {
  2746. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2747. 0:
  2748. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2749. if(idxPeriod > 0)
  2750. {
  2751. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2752. {
  2753. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2754. }
  2755. }
  2756. }
  2757. }
  2758. }
  2759. }
  2760. /*
  2761. DEBUG_INFO("MaxProfile after align.\n");
  2762. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2763. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2764. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2765. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2766. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2767. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2768. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2769. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2770. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2771. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2772. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2773. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2774. {
  2775. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2776. {
  2777. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2778. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2779. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2780. }
  2781. }
  2782. DEBUG_INFO("------------------------------------\n");*/
  2783. }
  2784. /*
  2785. * Merge to conposite schedule
  2786. */
  2787. //DEBUG_INFO("====================================\n");
  2788. // Find each profile period quantity
  2789. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2790. {
  2791. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2792. limitMax = idx+1;
  2793. }
  2794. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2795. {
  2796. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2797. limitDef = idx+1;
  2798. }
  2799. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2800. {
  2801. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2802. limitTx = idx+1;
  2803. }
  2804. // TxProfile found, composite schedule based on it
  2805. if(txProfile.ChargingProfileId != -1)
  2806. {
  2807. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2808. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2809. {
  2810. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2811. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2812. (txProfile.ChargingSchedule.Duration > 0))
  2813. {
  2814. if(maxProfile.ChargingProfileId != -1)
  2815. {
  2816. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2817. {
  2818. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2819. {
  2820. if((maxProfile.ChargingSchedule.Duration > 0))
  2821. {
  2822. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2823. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2824. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2825. }
  2826. else
  2827. {
  2828. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2829. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2830. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2831. }
  2832. }
  2833. if(idxMaxPeriod == (limitMax-1))
  2834. {
  2835. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2836. {
  2837. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2838. {
  2839. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2840. compositePeriodIdx++;
  2841. }
  2842. else
  2843. {
  2844. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2845. }
  2846. }
  2847. }
  2848. }
  2849. }
  2850. else
  2851. {
  2852. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2853. {
  2854. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2855. compositePeriodIdx++;
  2856. }
  2857. else
  2858. {
  2859. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2860. }
  2861. }
  2862. }
  2863. if(idxTxPeriod == (limitTx-1))
  2864. {
  2865. if(defaultTxProfile.ChargingProfileId != -1)
  2866. {
  2867. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2868. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2869. {
  2870. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2871. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2872. (defaultTxProfile.ChargingSchedule.Duration>0))
  2873. {
  2874. if(maxProfile.ChargingProfileId != -1)
  2875. {
  2876. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2877. {
  2878. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2879. {
  2880. if((maxProfile.ChargingSchedule.Duration > 0))
  2881. {
  2882. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2883. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2884. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2885. }
  2886. else
  2887. {
  2888. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2889. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2890. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2891. }
  2892. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2893. {
  2894. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2895. {
  2896. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2897. compositePeriodIdx++;
  2898. }
  2899. else
  2900. {
  2901. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2902. }
  2903. }
  2904. // Delete duplicate period
  2905. if(compositePeriodIdx > 1)
  2906. {
  2907. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2908. {
  2909. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2910. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2911. compositePeriodIdx -= 1;
  2912. }
  2913. }
  2914. }
  2915. else
  2916. {
  2917. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2918. {
  2919. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2920. compositePeriodIdx++;
  2921. }
  2922. else
  2923. {
  2924. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2925. }
  2926. break;
  2927. }
  2928. }
  2929. }
  2930. else
  2931. {
  2932. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2933. {
  2934. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2935. compositePeriodIdx++;
  2936. }
  2937. else
  2938. {
  2939. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2940. }
  2941. }
  2942. }
  2943. }
  2944. }
  2945. }
  2946. }
  2947. }
  2948. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2949. else if(defaultTxProfile.ChargingProfileId != -1)
  2950. {
  2951. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2952. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2953. {
  2954. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2955. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2956. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2957. {
  2958. if(maxProfile.ChargingProfileId != -1)
  2959. {
  2960. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2961. {
  2962. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2963. {
  2964. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2965. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2966. if((maxProfile.ChargingSchedule.Duration > 0))
  2967. {
  2968. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2969. }
  2970. else
  2971. {
  2972. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2973. }
  2974. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2975. {
  2976. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2977. {
  2978. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2979. compositePeriodIdx++;
  2980. }
  2981. else
  2982. {
  2983. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2984. }
  2985. }
  2986. // Delete duplicate period
  2987. if(compositePeriodIdx > 1)
  2988. {
  2989. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2990. {
  2991. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2992. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2993. compositePeriodIdx -= 1;
  2994. }
  2995. }
  2996. }
  2997. else
  2998. {
  2999. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3000. {
  3001. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3002. compositePeriodIdx++;
  3003. }
  3004. else
  3005. {
  3006. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3007. }
  3008. break;
  3009. }
  3010. }
  3011. }
  3012. else
  3013. {
  3014. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3015. {
  3016. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3017. compositePeriodIdx++;
  3018. }
  3019. else
  3020. {
  3021. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3022. }
  3023. }
  3024. }
  3025. }
  3026. }
  3027. // Fill other period by MaxProfile
  3028. if(maxProfile.ChargingProfileId != -1)
  3029. {
  3030. if(compositePeriodIdx==0)
  3031. {
  3032. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3033. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3034. {
  3035. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3036. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3037. (maxProfile.ChargingSchedule.Duration > 0))
  3038. {
  3039. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3040. {
  3041. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3042. compositePeriodIdx++;
  3043. }
  3044. else
  3045. {
  3046. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3047. }
  3048. }
  3049. }
  3050. }
  3051. else
  3052. {
  3053. int lastCompositePeriodIdx = compositePeriodIdx;
  3054. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3055. {
  3056. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3057. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3058. (maxProfile.ChargingSchedule.Duration > 0))
  3059. {
  3060. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3061. {
  3062. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3063. {
  3064. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3065. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3066. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3067. }
  3068. else
  3069. {
  3070. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3071. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3072. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3073. }
  3074. }
  3075. if(tmpPeriod.Limit != -1)
  3076. {
  3077. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3078. {
  3079. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3080. {
  3081. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3082. compositePeriodIdx++;
  3083. }
  3084. else
  3085. {
  3086. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3087. }
  3088. }
  3089. // Delete duplicate period
  3090. if(compositePeriodIdx > 1)
  3091. {
  3092. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3093. {
  3094. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3095. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3096. compositePeriodIdx -= 1;
  3097. }
  3098. }
  3099. }
  3100. }
  3101. }
  3102. }
  3103. }
  3104. compositeProfile->ChargingSchedule.Duration = durationReq;
  3105. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3106. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3107. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3108. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3109. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3110. {
  3111. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3112. {
  3113. compositeProfile->ChargingProfileId = 1;
  3114. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3115. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3116. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3117. }
  3118. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3119. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3120. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3121. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3122. }
  3123. if(line)
  3124. free(line);
  3125. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3126. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3127. }
  3128. //==========================================
  3129. // Init all share memory
  3130. //==========================================
  3131. int InitShareMemory()
  3132. {
  3133. int result = PASS;
  3134. int MeterSMId;
  3135. //creat ShmSysConfigAndInfo
  3136. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3137. {
  3138. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3139. result = FAIL;
  3140. }
  3141. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3142. {
  3143. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3144. result = FAIL;
  3145. }
  3146. else
  3147. {}
  3148. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3149. {
  3150. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3151. result = FAIL;
  3152. }
  3153. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3154. {
  3155. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3156. result = FAIL;
  3157. }
  3158. else
  3159. {}
  3160. //creat ShmPsuData
  3161. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3162. {
  3163. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3164. result = FAIL;
  3165. }
  3166. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3167. {
  3168. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3169. result = FAIL;
  3170. }
  3171. else
  3172. {}
  3173. //link ShmOCPP16Data
  3174. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3175. {
  3176. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3177. result = FAIL;
  3178. }
  3179. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3180. {
  3181. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3182. result = FAIL;
  3183. }
  3184. else
  3185. {}
  3186. //creat ShmOCPP16DataPH
  3187. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3188. {
  3189. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3190. result = FAIL;
  3191. }
  3192. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3193. {
  3194. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3195. result = FAIL;
  3196. }
  3197. else
  3198. {}
  3199. /****************************** For Initial Settings************************************************/
  3200. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3201. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3202. // allocate Configuration memory address
  3203. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3204. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3205. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3206. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3207. //offline MeterValue Interval
  3208. TempMeterValueInterval = 0;
  3209. return result;
  3210. }
  3211. int ProcessShareMemory()
  3212. {
  3213. int result = PASS;
  3214. if(InitShareMemory() == FAIL)
  3215. {
  3216. DEBUG_ERROR("InitShareMemory NG\n");
  3217. if(ShmStatusCodeData!=NULL)
  3218. {
  3219. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3220. }
  3221. result = FAIL;
  3222. }
  3223. // Model name parsing
  3224. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3225. {
  3226. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3227. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3228. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3229. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3230. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3231. ) // 'D' means DC
  3232. {
  3233. // DO series
  3234. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3235. {
  3236. SystemInitial += 1;
  3237. gunTotalNumber += 1;
  3238. gunType[gun_index] = GUN_TYPE_DO;
  3239. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3240. {
  3241. case Gun_Type_Chademo:
  3242. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3243. break;
  3244. case Gun_Type_CCS_2:
  3245. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3246. break;
  3247. case Gun_Type_GB:
  3248. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3249. break;
  3250. case Gun_Type_AC:
  3251. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3252. break;
  3253. default:
  3254. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3255. break;
  3256. }
  3257. }
  3258. }
  3259. else
  3260. {
  3261. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3262. {
  3263. SystemInitial += 1;
  3264. gunTotalNumber += 1;
  3265. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3266. {
  3267. case Gun_Type_Chademo:
  3268. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3269. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3270. break;
  3271. case Gun_Type_CCS_2:
  3272. gunType[gun_index] = GUN_TYPE_CCS;
  3273. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3274. break;
  3275. case Gun_Type_GB:
  3276. gunType[gun_index] = GUN_TYPE_GBT;
  3277. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3278. break;
  3279. case Gun_Type_AC:
  3280. gunType[gun_index] = GUN_TYPE_AC;
  3281. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3282. break;
  3283. default:
  3284. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3285. break;
  3286. }
  3287. }
  3288. }
  3289. }
  3290. else
  3291. {
  3292. DEBUG_ERROR("Model name parsing fail.\n");
  3293. result = FAIL;
  3294. }
  3295. if(result != PASS)sleep(5);
  3296. return result;
  3297. }
  3298. void checkRemoteStart(uint8_t connectorIdInt)
  3299. {
  3300. uint8_t tempIndex;
  3301. int result = PASS;
  3302. char cmdBuf[512];
  3303. //check Transaction active
  3304. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3305. {
  3306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3307. {
  3308. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3309. }
  3310. else
  3311. {
  3312. tempIndex = connectorIdInt -1;
  3313. }
  3314. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3315. {
  3316. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3317. {
  3318. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3319. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3320. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3321. {
  3322. //Reserved
  3323. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3324. }
  3325. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3326. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3327. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3328. {
  3329. //Reserved
  3330. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3331. result = FAIL;
  3332. goto end;
  3333. }
  3334. else
  3335. {
  3336. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3337. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3338. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3339. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3340. {
  3341. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3342. result = FAIL;
  3343. goto end;
  3344. }
  3345. }//END FOR ELSE
  3346. }
  3347. }// END FOR CHAdeMO_QUANTITY
  3348. }
  3349. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3350. {
  3351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3352. {
  3353. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3354. }
  3355. else
  3356. {
  3357. tempIndex = connectorIdInt -1;
  3358. }
  3359. for (int index = 0; index < CCS_QUANTITY; index++)
  3360. {
  3361. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3362. {
  3363. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3364. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3365. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3366. {
  3367. //Reserved
  3368. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3369. }
  3370. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3371. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3372. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3373. {
  3374. //Reserved
  3375. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3376. result = FAIL;
  3377. goto end;
  3378. }
  3379. else
  3380. {
  3381. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3382. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3383. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3384. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3385. {
  3386. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3387. result = FAIL;
  3388. goto end;
  3389. }
  3390. }// END FOR ELSE
  3391. }
  3392. }// END FOR CCS_QUANTITY
  3393. }
  3394. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3395. {
  3396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3397. {
  3398. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3399. }
  3400. else
  3401. {
  3402. tempIndex = connectorIdInt -1;
  3403. }
  3404. for (int index = 0; index < GB_QUANTITY; index++)
  3405. {
  3406. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3407. {
  3408. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3409. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3410. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3411. {
  3412. //Reserved
  3413. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3414. }
  3415. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3416. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3417. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3418. {
  3419. //Reserved
  3420. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3421. result = FAIL;
  3422. goto end;
  3423. }
  3424. else
  3425. {
  3426. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3427. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3428. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3429. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3430. {
  3431. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3432. result = FAIL;
  3433. goto end;
  3434. }
  3435. }// END FOR ELSE
  3436. }
  3437. } // END FOR GB_QUANTITY
  3438. }
  3439. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3440. {
  3441. tempIndex = connectorIdInt -1;
  3442. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3443. {
  3444. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3445. {
  3446. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3447. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3448. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3449. {
  3450. //Reserved
  3451. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3452. }
  3453. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3454. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3455. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3456. {
  3457. //Reserved
  3458. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3459. result = FAIL;
  3460. goto end;
  3461. }
  3462. else
  3463. {
  3464. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3465. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3466. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3467. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3468. {
  3469. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3470. result = FAIL;
  3471. goto end;
  3472. }
  3473. }// END FOR ELSE
  3474. }
  3475. } // END FOR GB_QUANTITY
  3476. }
  3477. else
  3478. {
  3479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3480. {
  3481. tempIndex = 2;
  3482. }
  3483. else
  3484. {
  3485. tempIndex = connectorIdInt -1;
  3486. }
  3487. for (int index = 0; index < AC_QUANTITY; index++)
  3488. {
  3489. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3490. {
  3491. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3492. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3493. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3494. {
  3495. //Reserved
  3496. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3497. }
  3498. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3499. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3500. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3501. {
  3502. //Reserved
  3503. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3504. result = FAIL;
  3505. goto end;
  3506. }
  3507. else
  3508. {
  3509. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3510. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3511. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3512. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3513. {
  3514. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3515. result = FAIL;
  3516. goto end;
  3517. }
  3518. }//END FOR ELSE
  3519. }
  3520. }// END FOR AC_QUANTITY
  3521. }
  3522. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3523. {
  3524. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3525. {
  3526. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3527. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3528. {
  3529. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3530. system(cmdBuf);
  3531. }
  3532. }
  3533. else
  3534. {
  3535. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3536. result = FAIL;
  3537. }
  3538. }
  3539. end:
  3540. if(result == PASS)
  3541. {
  3542. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3543. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3544. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3545. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3546. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3547. }
  3548. }
  3549. void CheckSystemValue(void)
  3550. {
  3551. char filenmae[100]={0};
  3552. char str[100]={0};
  3553. int tempIndex = 0;
  3554. //===============================
  3555. // send Heartbeat
  3556. //===============================
  3557. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3558. {
  3559. //parameter for test
  3560. sendHeartbeatRequest(0);
  3561. //==============================================
  3562. // Reset Waiting Time
  3563. //==============================================
  3564. HeartBeatWithNOResponse += 2;
  3565. }
  3566. //===============================
  3567. // Credit deduct report
  3568. //===============================
  3569. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3570. {
  3571. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo, ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice);
  3572. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3573. }
  3574. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3575. {
  3576. OCPP_query_deduct_info();
  3577. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3578. }
  3579. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3580. {
  3581. // ClockAlign MeterValue
  3582. 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))
  3583. {
  3584. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3585. {
  3586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3587. {
  3588. tempIndex = ((gun_index==2) ? 1: 0);
  3589. }
  3590. else
  3591. {
  3592. tempIndex = gun_index;
  3593. }
  3594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3595. {
  3596. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3597. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3598. {
  3599. reqClockAlignMeter[gun_index] = 1;
  3600. }
  3601. }// End for CHAdeMO
  3602. }
  3603. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3604. {
  3605. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3606. {
  3607. tempIndex = ((gun_index==2) ? 1: 0);
  3608. }
  3609. else
  3610. {
  3611. tempIndex = gun_index;
  3612. }
  3613. for (int index = 0; index < CCS_QUANTITY; index++)
  3614. {
  3615. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3616. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3617. {
  3618. reqClockAlignMeter[gun_index] = 1;
  3619. }
  3620. } // End for CCS
  3621. }
  3622. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3623. {
  3624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3625. {
  3626. tempIndex = ((gun_index==2) ? 1: 0);
  3627. }
  3628. else
  3629. {
  3630. tempIndex = gun_index;
  3631. }
  3632. for (int index = 0; index < GB_QUANTITY; index++)
  3633. {
  3634. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3635. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3636. {
  3637. reqClockAlignMeter[gun_index] = 1;
  3638. }
  3639. }// End for GB
  3640. }
  3641. else if(gunType[gun_index] == GUN_TYPE_DO)
  3642. {
  3643. tempIndex = gun_index;
  3644. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3645. {
  3646. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3647. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3648. {
  3649. reqClockAlignMeter[gun_index] = 1;
  3650. }
  3651. }
  3652. }
  3653. else
  3654. {
  3655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3656. {
  3657. tempIndex = 2;
  3658. }
  3659. else
  3660. {
  3661. tempIndex = gun_index;
  3662. }
  3663. for (int index = 0; index < AC_QUANTITY; index++)
  3664. {
  3665. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3666. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3667. {
  3668. reqClockAlignMeter[gun_index] = 1;
  3669. }
  3670. }//End for AC
  3671. }
  3672. }
  3673. }
  3674. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3675. {
  3676. //==========================================
  3677. // Check remote start without connector id
  3678. //==========================================
  3679. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3680. {
  3681. int connectorIdInt = -1;
  3682. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3683. {
  3684. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3685. {
  3686. connectorIdInt = (gun_index+1);
  3687. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3688. checkRemoteStart(connectorIdInt);
  3689. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3690. break;
  3691. }
  3692. }
  3693. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3694. {
  3695. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3696. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3697. }
  3698. }
  3699. //==========================================
  3700. // csu trigger DataTransferReq
  3701. //==========================================
  3702. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3703. {
  3704. sendDataTransferRequest(gun_index);
  3705. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3706. }
  3707. //===============================
  3708. // CSU Trigger Authorize Request
  3709. //===============================
  3710. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3711. {
  3712. sendAuthorizeRequest(0);
  3713. authorizeRetryTimes = authorizeRetryTimes + 1;
  3714. if(authorizeRetryTimes < 3)
  3715. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3716. }
  3717. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3718. {
  3719. authorizeRetryTimes = 0;
  3720. SetOcppConnStatus(FALSE);
  3721. server_sign = FALSE;
  3722. }
  3723. 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))
  3724. {
  3725. sendAuthorizeRequest(0);
  3726. }
  3727. //==============================================
  3728. // Charger start transaction
  3729. //==============================================
  3730. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3731. {
  3732. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3733. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3734. sendStartTransactionRequest(gun_index);
  3735. refreshStartTimer(&clientTime.StartTransaction);
  3736. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3737. //storeTempStopTransaction(gun_index);
  3738. }
  3739. //==============================================
  3740. // Charger stop transaction
  3741. //==============================================
  3742. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3743. {
  3744. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3745. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3746. sendStopTransactionRequest(gun_index);
  3747. refreshStartTimer(&clientTime.StopTransaction);
  3748. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3749. }
  3750. //==============================================
  3751. // Charger status report
  3752. //==============================================
  3753. //--- Check Mode Change ---//
  3754. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3755. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3756. {
  3757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3758. {
  3759. tempIndex = ((gun_index==2) ? 1: 0);
  3760. }
  3761. else
  3762. {
  3763. tempIndex = gun_index;
  3764. }
  3765. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3766. {
  3767. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3768. {
  3769. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3770. {
  3771. // Sent unplug message for California pricing logic
  3772. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3773. {
  3774. uint8_t ts[20];
  3775. getNowDatetime(ts);
  3776. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3777. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3778. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3779. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3780. }
  3781. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3782. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3783. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3784. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3785. {
  3786. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3787. if((access(filenmae,F_OK))!=-1)
  3788. {
  3789. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3790. sprintf(str,"rm -f %s",filenmae);
  3791. system(str);
  3792. }
  3793. }
  3794. }
  3795. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3796. #if 1 // for TempStopTransaction
  3797. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3798. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3799. {
  3800. checkTempStopTransaction(gun_index);
  3801. }
  3802. #endif
  3803. }
  3804. }
  3805. }
  3806. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3807. {
  3808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3809. {
  3810. tempIndex = ((gun_index==2) ? 1: 0);
  3811. }
  3812. else
  3813. {
  3814. tempIndex = gun_index;
  3815. }
  3816. for (int index = 0; index < CCS_QUANTITY; index++)
  3817. {
  3818. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3819. {
  3820. 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]*/ )
  3821. {
  3822. // Sent unplug message for California pricing logic
  3823. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3824. {
  3825. uint8_t ts[20];
  3826. getNowDatetime(ts);
  3827. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3828. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3829. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3830. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3831. }
  3832. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3833. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3834. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3835. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3836. {
  3837. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3838. if((access(filenmae,F_OK))!=-1)
  3839. {
  3840. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3841. sprintf(str,"rm -f %s",filenmae);
  3842. system(str);
  3843. }
  3844. }
  3845. }
  3846. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3847. #if 1 // for TempStopTransaction
  3848. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3849. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3850. {
  3851. checkTempStopTransaction(gun_index);
  3852. }
  3853. #endif
  3854. }
  3855. }
  3856. }
  3857. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3858. {
  3859. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3860. {
  3861. tempIndex = ((gun_index==2) ? 1: 0);
  3862. }
  3863. else
  3864. {
  3865. tempIndex = gun_index;
  3866. }
  3867. for (int index = 0; index < GB_QUANTITY; index++)
  3868. {
  3869. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3870. {
  3871. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3872. {
  3873. // Sent unplug message for California pricing logic
  3874. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3875. {
  3876. uint8_t ts[20];
  3877. getNowDatetime(ts);
  3878. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3879. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3880. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3881. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3882. }
  3883. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3884. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3885. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3886. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3887. {
  3888. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3889. if((access(filenmae,F_OK))!=-1)
  3890. {
  3891. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3892. sprintf(str,"rm -f %s",filenmae);
  3893. system(str);
  3894. }
  3895. }
  3896. }
  3897. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3898. #if 1 // for TempStopTransaction
  3899. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3900. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3901. {
  3902. checkTempStopTransaction(gun_index);
  3903. }
  3904. #endif
  3905. }
  3906. }
  3907. }
  3908. else if(gunType[gun_index] == GUN_TYPE_DO)
  3909. {
  3910. tempIndex = gun_index;
  3911. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3912. {
  3913. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3914. {
  3915. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3916. {
  3917. // Sent unplug message for California pricing logic
  3918. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3919. {
  3920. uint8_t ts[20];
  3921. getNowDatetime(ts);
  3922. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3923. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3924. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3925. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3926. }
  3927. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3928. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3929. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3930. 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
  3931. {
  3932. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3933. if((access(filenmae,F_OK))!=-1)
  3934. {
  3935. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3936. sprintf(str,"rm -f %s",filenmae);
  3937. system(str);
  3938. }
  3939. }
  3940. }
  3941. 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);
  3942. #if 1 // for TempStopTransaction
  3943. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3944. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3945. {
  3946. checkTempStopTransaction(gun_index);
  3947. }
  3948. #endif
  3949. }
  3950. }
  3951. }
  3952. else
  3953. {
  3954. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3955. {
  3956. tempIndex = 2;
  3957. }
  3958. else
  3959. {
  3960. tempIndex = gun_index;
  3961. }
  3962. for (int index = 0; index < AC_QUANTITY; index++)
  3963. {
  3964. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3965. {
  3966. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3967. {
  3968. // Sent unplug message for California pricing logic
  3969. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3970. {
  3971. uint8_t ts[20];
  3972. getNowDatetime(ts);
  3973. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3974. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3975. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3976. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3977. }
  3978. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3979. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3980. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3981. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3982. {
  3983. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3984. if((access(filenmae,F_OK))!=-1)
  3985. {
  3986. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3987. sprintf(str,"rm -f %s",filenmae);
  3988. system(str);
  3989. }
  3990. }
  3991. }
  3992. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3993. #if 1 // for TempStopTransaction
  3994. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3995. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3996. {
  3997. checkTempStopTransaction(gun_index);
  3998. }
  3999. #endif
  4000. }
  4001. }// END
  4002. }
  4003. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4004. (
  4005. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4006. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4007. )
  4008. )
  4009. {
  4010. if(SystemInitial > 0)
  4011. SystemInitial -= 1;
  4012. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4013. sendStatusNotificationRequest(gun_index);
  4014. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4015. }
  4016. //==============================================
  4017. // CSU Trigger Smart Charging Profilw
  4018. //==============================================
  4019. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4020. {
  4021. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4022. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4023. }
  4024. //==============================================
  4025. // Meter report
  4026. //==============================================
  4027. // Trigger MeterValue
  4028. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4029. {
  4030. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4031. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4032. }
  4033. // Clock-aligned Meter value
  4034. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4035. {
  4036. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4037. reqClockAlignMeter[gun_index] = 0;
  4038. }
  4039. // Sample period MeterValue
  4040. 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))))
  4041. {
  4042. //check Transaction active
  4043. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4044. {
  4045. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4046. {
  4047. tempIndex = ((gun_index==2) ? 1: 0);
  4048. }
  4049. else
  4050. {
  4051. tempIndex = gun_index;
  4052. }
  4053. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4054. {
  4055. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4056. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4057. {
  4058. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4059. {
  4060. reqSampleMeter[gun_index] = 1;
  4061. }
  4062. }
  4063. }// End for CHAdeMO
  4064. }
  4065. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4066. {
  4067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4068. {
  4069. tempIndex = ((gun_index==2) ? 1: 0);
  4070. }
  4071. else
  4072. {
  4073. tempIndex = gun_index;
  4074. }
  4075. for (int index = 0; index < CCS_QUANTITY; index++)
  4076. {
  4077. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4078. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4079. {
  4080. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4081. {
  4082. reqSampleMeter[gun_index] = 1;
  4083. }
  4084. }
  4085. } // End for CCS
  4086. }
  4087. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4088. {
  4089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4090. {
  4091. tempIndex = ((gun_index==2) ? 1: 0);
  4092. }
  4093. else
  4094. {
  4095. tempIndex = gun_index;
  4096. }
  4097. for (int index = 0; index < GB_QUANTITY; index++)
  4098. {
  4099. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4100. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4101. {
  4102. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4103. {
  4104. reqSampleMeter[gun_index] = 1;
  4105. }
  4106. }
  4107. }// End for GB
  4108. }
  4109. else if(gunType[gun_index] == GUN_TYPE_DO)
  4110. {
  4111. tempIndex = gun_index;
  4112. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4113. {
  4114. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4115. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4116. {
  4117. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4118. {
  4119. reqSampleMeter[gun_index] = 1;
  4120. }
  4121. }
  4122. }
  4123. }
  4124. else
  4125. {
  4126. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4127. {
  4128. tempIndex = 2;
  4129. }
  4130. else
  4131. {
  4132. tempIndex = gun_index;
  4133. }
  4134. for (int index = 0; index < AC_QUANTITY; index++)
  4135. {
  4136. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4137. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4138. {
  4139. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4140. {
  4141. reqSampleMeter[gun_index] = 1;
  4142. }
  4143. }
  4144. }//End for AC
  4145. }
  4146. if(reqSampleMeter[gun_index] == 1)
  4147. {
  4148. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4149. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4150. //storeTempStopTransaction(gun_index);
  4151. reqSampleMeter[gun_index] = 0;
  4152. }
  4153. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4154. }
  4155. //==============================================
  4156. // Check Connector reserved
  4157. //==============================================
  4158. //===============================
  4159. // Check if Reserve is expired
  4160. //===============================
  4161. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4162. {
  4163. double diff_t;
  4164. struct tm tp;
  4165. // current time
  4166. time_t t = time(NULL);
  4167. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4168. tp.tm_isdst = -1;
  4169. time_t utc = mktime(&tp);
  4170. diff_t = difftime(utc, t);
  4171. if(diff_t <= 0)
  4172. {
  4173. DEBUG_INFO("reserve expired.\n");
  4174. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4175. }
  4176. }//END OF Check if Reserve is expired
  4177. //==========================================
  4178. // csu trigger FirmwareStatusNotificationReq
  4179. //==========================================
  4180. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4181. {
  4182. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4183. }
  4184. //==========================================
  4185. // csu trigger DiagnosticsStatusNotificationReq
  4186. //==========================================
  4187. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4188. {
  4189. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4190. }
  4191. //==========================================
  4192. // csu trigger CancelReservationConf
  4193. //==========================================
  4194. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4195. {
  4196. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4197. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4198. }
  4199. //==========================================
  4200. // csu trigger ChangeAvailabilityConf
  4201. //==========================================
  4202. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4203. {
  4204. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4205. }
  4206. //==========================================
  4207. // csu trigger UnlockConnectorConf
  4208. //==========================================
  4209. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4210. {
  4211. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4212. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4213. }
  4214. //==========================================
  4215. // csu trigger ReserveNowConf
  4216. //==========================================
  4217. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4218. {
  4219. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4220. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4221. }
  4222. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4223. {
  4224. sendSignCertificateRequest();
  4225. }
  4226. }
  4227. }
  4228. //==========================================
  4229. // send request routine
  4230. //==========================================
  4231. int sendAuthorizeRequest(int gun_index)
  4232. {
  4233. mtrace();
  4234. int result = FAIL;
  4235. char message[100]={0};
  4236. char guid[37];
  4237. char tempdata[65]={0};
  4238. DEBUG_INFO("sendAuthorizeRequest...\n");
  4239. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4240. //Local Authorize
  4241. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4242. {
  4243. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4244. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4245. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4246. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4247. result = PASS;
  4248. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4249. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4250. authorizeRetryTimes = 0;
  4251. return result;
  4252. }
  4253. 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))||
  4254. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4255. {
  4256. // Query from cache
  4257. DEBUG_INFO("Authorize from cache.\n");
  4258. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4259. // Query from list
  4260. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4261. {
  4262. DEBUG_INFO("Authorize from list.\n");
  4263. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4264. }
  4265. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4266. {
  4267. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4268. {
  4269. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4270. }
  4271. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4272. {
  4273. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4274. }
  4275. if(!GetOcppConnStatus())
  4276. {
  4277. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4278. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4279. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4280. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4281. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4282. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4283. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4284. authorizeRetryTimes = 0;
  4285. return result;
  4286. }
  4287. }
  4288. else
  4289. {
  4290. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4291. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4292. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4293. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4294. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4295. else
  4296. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4297. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4298. result = PASS;
  4299. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4300. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4301. authorizeRetryTimes = 0;
  4302. return result;
  4303. }
  4304. }
  4305. //initialize struct Authorize
  4306. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4307. //get data from shared memory
  4308. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4309. random_uuid(guid);
  4310. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4311. LWS_Send(message);
  4312. sprintf(tempdata, "Authorize,%d", gun_index);
  4313. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4314. {
  4315. result = PASS;
  4316. DEBUG_INFO("Authorize mapItem pass\n");
  4317. }
  4318. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4319. return result;
  4320. }
  4321. int sendBootNotificationRequest(void)
  4322. {
  4323. mtrace();
  4324. int result = FAIL;
  4325. char message[500]={0}, payload[700]={0};
  4326. char guid[37]={0};
  4327. char tempdata[65]={0};
  4328. // Fill BootNotification fields
  4329. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4330. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4331. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4332. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4333. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4334. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4335. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4336. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4337. ShmOCPP16DataPH->ChargeBoxId
  4338. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4339. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4340. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4341. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4342. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4343. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4344. random_uuid(guid);
  4345. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4346. LWS_Send(message);
  4347. sprintf(tempdata, "BootNotification,0");
  4348. 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*/)
  4349. {
  4350. result = PASS;
  4351. }
  4352. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4353. strcpy(queuedata,message);
  4354. return result;
  4355. }
  4356. int sendDataTransferRequest(int gun_index)
  4357. {
  4358. mtrace();
  4359. char message[1000]={0};
  4360. char guid[37]={0};
  4361. char tempdata[65]={0};
  4362. int result = FAIL;
  4363. random_uuid(guid);
  4364. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4365. MESSAGE_TYPE_CALL,
  4366. guid,
  4367. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4368. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4369. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4370. LWS_Send(message);
  4371. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4372. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4373. {
  4374. result = PASS;
  4375. DEBUG_INFO("DataTransfer mapItem pass\n");
  4376. }
  4377. return result;
  4378. }
  4379. int sendDiagnosticsStatusNotificationRequest(char *status)
  4380. {
  4381. mtrace();
  4382. int result = FAIL;
  4383. char message[110]={0};
  4384. char guid[37]={0};
  4385. char tempdata[65]={0};
  4386. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4387. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4388. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4389. random_uuid(guid);
  4390. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4391. LWS_SendNow(message);
  4392. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4393. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4394. {
  4395. result = PASS;
  4396. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4397. }
  4398. //#ifdef SystemLogMessage
  4399. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4400. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4401. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4402. //#endif
  4403. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4404. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4405. //record status
  4406. if(strcmp(status,"Idle")==0)
  4407. {
  4408. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4409. }
  4410. else if(strcmp(status,"Uploaded")==0)
  4411. {
  4412. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4413. }
  4414. else if(strcmp(status,"UploadFailed")==0)
  4415. {
  4416. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4417. }
  4418. else if(strcmp(status,"Uploading")==0)
  4419. {
  4420. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4421. }
  4422. return result;
  4423. }
  4424. int sendFirmwareStatusNotificationRequest(char *status)
  4425. {
  4426. mtrace();
  4427. int result = FAIL;
  4428. char message[110]={0};
  4429. char guid[37]={0};
  4430. char tempdata[65]={0};
  4431. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4432. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4433. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4434. random_uuid(guid);
  4435. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4436. LWS_SendNow(message);
  4437. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4438. 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*/)
  4439. {
  4440. result = PASS;
  4441. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4442. }
  4443. //#ifdef SystemLogMessage
  4444. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4445. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4446. //#endif
  4447. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4448. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4449. //record status
  4450. if(strcmp(status,"Downloaded")==0)
  4451. {
  4452. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4453. }
  4454. else if(strcmp(status,"DownloadFailed")==0)
  4455. {
  4456. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4457. }
  4458. else if(strcmp(status,"Downloading")==0)
  4459. {
  4460. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4461. }
  4462. else if(strcmp(status,"Idle")==0)
  4463. {
  4464. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4465. }
  4466. else if(strcmp(status,"InstallationFailed")==0)
  4467. {
  4468. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4469. }
  4470. else if(strcmp(status,"Installing")==0)
  4471. {
  4472. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4473. }
  4474. else if(strcmp(status,"Installed")==0)
  4475. {
  4476. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4477. }
  4478. return result;
  4479. }
  4480. int sendHeartbeatRequest(int gun_index)
  4481. {
  4482. mtrace();
  4483. int result = FAIL;
  4484. char message[80]={0};
  4485. char guid[37]={0};
  4486. char tempdata[65]={0};
  4487. random_uuid(guid);
  4488. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4489. , MESSAGE_TYPE_CALL
  4490. , guid );
  4491. LWS_Send(message);
  4492. sprintf(tempdata, "Heartbeat,%d", 0);
  4493. 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*/)
  4494. {
  4495. result = PASS;
  4496. }
  4497. return result;
  4498. }
  4499. int sendStartTransactionRequest(int gun_index)
  4500. {
  4501. mtrace();
  4502. int result = FAIL;
  4503. char message[250]={0};
  4504. char guid[37]={0};
  4505. struct timeval tmnow;
  4506. struct tm *tm;
  4507. char buf[28];//, usec_buf[6];
  4508. char tempdata[65]={0};
  4509. int tempIndex = 0;
  4510. DEBUG_INFO("sendStartTransactionRequest...\n");
  4511. gettimeofday(&tmnow, NULL);
  4512. time_t t;
  4513. t = time(NULL);
  4514. /*UTC time and date*/
  4515. tm = gmtime(&t);
  4516. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4517. #if 0 // remove temporally
  4518. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4519. strcat(buf,".");
  4520. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4521. strcat(buf,usec_buf);
  4522. #endif
  4523. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4524. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4525. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4526. // clear StartTransaction Response
  4527. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4528. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4529. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4530. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4531. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4532. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4533. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4534. {
  4535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4536. {
  4537. tempIndex = ((gun_index==2) ? 1: 0);
  4538. }
  4539. else
  4540. {
  4541. tempIndex = gun_index;
  4542. }
  4543. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4544. {
  4545. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4546. {
  4547. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4548. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4549. }
  4550. }
  4551. }
  4552. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4553. {
  4554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4555. {
  4556. tempIndex = ((gun_index==2) ? 1: 0);
  4557. }
  4558. else
  4559. {
  4560. tempIndex = gun_index;
  4561. }
  4562. for (int index = 0; index < CCS_QUANTITY; index++)
  4563. {
  4564. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4565. {
  4566. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4567. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4568. }
  4569. }
  4570. }
  4571. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4572. {
  4573. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4574. {
  4575. tempIndex = ((gun_index==2) ? 1: 0);
  4576. }
  4577. else
  4578. {
  4579. tempIndex = gun_index;
  4580. }
  4581. for (int index = 0; index < GB_QUANTITY; index++)
  4582. {
  4583. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4584. {
  4585. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4586. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4587. }
  4588. }
  4589. }
  4590. else if(gunType[gun_index] == GUN_TYPE_DO)
  4591. {
  4592. tempIndex = gun_index;
  4593. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4594. {
  4595. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4596. {
  4597. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4598. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4599. }
  4600. }
  4601. }
  4602. else
  4603. {
  4604. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4605. {
  4606. tempIndex = 2;
  4607. }
  4608. else
  4609. {
  4610. tempIndex = gun_index;
  4611. }
  4612. for (int index = 0; index < AC_QUANTITY; index++)
  4613. {
  4614. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4615. {
  4616. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4617. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4618. }
  4619. }
  4620. }
  4621. random_uuid(guid);
  4622. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4623. {
  4624. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4625. , gun_index +1
  4626. , MESSAGE_TYPE_CALL
  4627. , guid
  4628. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4629. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4630. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4631. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4632. }
  4633. else
  4634. {
  4635. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4636. , gun_index +1
  4637. , MESSAGE_TYPE_CALL
  4638. , guid
  4639. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4640. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4641. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4642. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4643. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4644. }
  4645. #if 1
  4646. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4647. 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*/)
  4648. {
  4649. result = PASS;
  4650. }
  4651. #endif
  4652. strcpy(queuedata, message);
  4653. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4654. OCPP_insert_transaction_msg(YES, queuedata);
  4655. return result;
  4656. }
  4657. int sendStatusNotificationRequest(int gun_index)
  4658. {
  4659. mtrace();
  4660. int result = FAIL;
  4661. char message[600]={0};
  4662. char guid[37];
  4663. int currentStatus = 0;
  4664. struct timeval tmnow;
  4665. struct tm *tm;
  4666. char buf[28];//, usec_buf[6];
  4667. char tempdata[65]={0};
  4668. int tempIndex = 0;
  4669. uint8_t isStateChanged = TRUE;
  4670. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4671. gettimeofday(&tmnow, NULL);
  4672. time_t t;
  4673. t = time(NULL);
  4674. /*UTC time and date*/
  4675. tm = gmtime(&t);
  4676. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4677. #if 0 // remove temporally
  4678. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4679. strcat(buf,".");
  4680. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4681. strcat(buf,usec_buf);
  4682. #endif
  4683. //printf("%s",buf);
  4684. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4685. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4686. // it's option
  4687. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4688. /*
  4689. enum _SYSTEM_STATUS
  4690. {
  4691. S_BOOTING = 0,
  4692. S_IDLE, = 1
  4693. S_AUTHORIZING, =2
  4694. S_REASSIGN_CHECK, =3
  4695. S_REASSIGN, =4
  4696. S_PRECHARGE, =5
  4697. S_PREPARING_FOR_EV, =6
  4698. S_PREPARING_FOR_EVSE, =7
  4699. S_CHARGING, =8
  4700. S_TERMINATING, =9
  4701. S_COMPLETE, =10
  4702. S_ALARM, =11
  4703. S_FAULT =12
  4704. }
  4705. */
  4706. //check Transaction active
  4707. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4708. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4709. {
  4710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4711. {
  4712. tempIndex = ((gun_index==2) ? 1: 0);
  4713. }
  4714. else
  4715. {
  4716. tempIndex = gun_index;
  4717. }
  4718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4719. {
  4720. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4721. {
  4722. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4723. {
  4724. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4725. {
  4726. currentStatus = Preparing; //OCPP Status: Preparing
  4727. }
  4728. else
  4729. {
  4730. currentStatus = Available; //OCPP Status: Available
  4731. }
  4732. }
  4733. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4734. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4735. ) //S_PRECHARGE
  4736. {
  4737. currentStatus = Preparing; //OCPP Status: Preparing
  4738. }
  4739. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4740. {
  4741. currentStatus = Charging; //OCPP Status: Charging
  4742. }
  4743. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4744. {
  4745. currentStatus = Finishing; //OCPP Status: Finishing
  4746. }
  4747. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4748. {
  4749. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4750. }
  4751. 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
  4752. {
  4753. currentStatus = Unavailable; //OCPP Status: Unavailable
  4754. }
  4755. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4756. {
  4757. currentStatus = Faulted; //OCPP Status: Faulted
  4758. }
  4759. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4760. {
  4761. currentStatus = Reserved; //OCPP Status: Reserved
  4762. }
  4763. } //end of the same index
  4764. }//end of for CHAdeMO_QUANTITY
  4765. }
  4766. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4767. {
  4768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4769. {
  4770. tempIndex = ((gun_index==2) ? 1: 0);
  4771. }
  4772. else
  4773. {
  4774. tempIndex = gun_index;
  4775. }
  4776. for (int index = 0; index < CCS_QUANTITY; index++)
  4777. {
  4778. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4779. {
  4780. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4781. {
  4782. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4783. {
  4784. currentStatus = Preparing; //OCPP Status: Preparing
  4785. }
  4786. else
  4787. {
  4788. currentStatus = Available; //OCPP Status: Available
  4789. }
  4790. }
  4791. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4792. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4793. ) //S_PRECHARGE
  4794. {
  4795. currentStatus = Preparing; //OCPP Status: Preparing
  4796. }
  4797. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4798. {
  4799. currentStatus = Charging; //OCPP Status: Charging
  4800. }
  4801. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4802. {
  4803. currentStatus = Finishing; //OCPP Status: Finishing
  4804. }
  4805. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4806. {
  4807. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4808. }
  4809. 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
  4810. {
  4811. currentStatus = Unavailable; //OCPP Status : Unavailable
  4812. }
  4813. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4814. {
  4815. currentStatus = Faulted; //OCPP Status: Faulted
  4816. }
  4817. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4818. {
  4819. currentStatus = Reserved; //OCPP Status: Reserved
  4820. }
  4821. } //end of the same index
  4822. } // end of for CCS_QUANTITY
  4823. }
  4824. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4825. {
  4826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4827. {
  4828. tempIndex = ((gun_index==2) ? 1: 0);
  4829. }
  4830. else
  4831. {
  4832. tempIndex = gun_index;
  4833. }
  4834. for (int index = 0; index < GB_QUANTITY; index++)
  4835. {
  4836. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4837. {
  4838. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4839. {
  4840. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4841. {
  4842. currentStatus = Preparing; //OCPP Status: Preparing
  4843. }
  4844. else
  4845. {
  4846. currentStatus = Available; //OCPP Status: Available
  4847. }
  4848. }
  4849. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4850. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4851. ) //S_PRECHARGE
  4852. {
  4853. currentStatus = Preparing; //OCPP Status: Preparing
  4854. }
  4855. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4856. {
  4857. currentStatus = Charging; //OCPP Status: Charging
  4858. }
  4859. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4860. {
  4861. currentStatus = Finishing; //OCPP Status: Finishing
  4862. }
  4863. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4864. {
  4865. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4866. }
  4867. 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
  4868. {
  4869. currentStatus = Unavailable; //OCPP Status: Unavailable
  4870. }
  4871. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4872. {
  4873. currentStatus = Faulted; //OCPP Status: Faulted
  4874. }
  4875. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4876. {
  4877. currentStatus = Reserved; //OCPP Status: Reserved
  4878. }
  4879. } //end of the same index
  4880. } // end of for GB_QUANTITY
  4881. }
  4882. else if(gunType[gun_index] == GUN_TYPE_DO)
  4883. {
  4884. tempIndex = gun_index;
  4885. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4886. {
  4887. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4888. {
  4889. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4890. {
  4891. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4892. {
  4893. currentStatus = Preparing; //OCPP Status: Preparing
  4894. }
  4895. else
  4896. {
  4897. currentStatus = Available; //OCPP Status: Available
  4898. }
  4899. }
  4900. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4901. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4902. ) //S_PRECHARGE
  4903. {
  4904. currentStatus = Preparing; //OCPP Status: Preparing
  4905. }
  4906. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4907. {
  4908. currentStatus = Charging; //OCPP Status: Charging
  4909. }
  4910. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4911. {
  4912. currentStatus = Finishing; //OCPP Status: Finishing
  4913. }
  4914. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4915. {
  4916. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4917. }
  4918. 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
  4919. {
  4920. currentStatus = Unavailable; //OCPP Status: Unavailable
  4921. }
  4922. 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
  4923. {
  4924. currentStatus = Faulted; //OCPP Status: Faulted
  4925. }
  4926. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4927. {
  4928. currentStatus = Reserved; //OCPP Status: Reserved
  4929. }
  4930. } //end of the same index
  4931. }
  4932. }
  4933. else
  4934. {
  4935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4936. {
  4937. tempIndex = 2;
  4938. }
  4939. else
  4940. {
  4941. tempIndex = gun_index;
  4942. }
  4943. for (int index = 0; index < AC_QUANTITY; index++)
  4944. {
  4945. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4946. {
  4947. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4948. {
  4949. 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))
  4950. {
  4951. currentStatus = Preparing; //OCPP Status: Preparing
  4952. }
  4953. else
  4954. {
  4955. currentStatus = Available; //OCPP Status: Available
  4956. }
  4957. }
  4958. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4959. {
  4960. currentStatus = Preparing; //OCPP Status: Preparing
  4961. }
  4962. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4963. {
  4964. currentStatus = Charging; //OCPP Status: Charging
  4965. }
  4966. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4967. {
  4968. currentStatus = Finishing; //OCPP Status: Finishing
  4969. }
  4970. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4971. {
  4972. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4973. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4974. else
  4975. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4976. }
  4977. 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
  4978. {
  4979. currentStatus = Unavailable; //OCPP Status: Unavailable
  4980. }
  4981. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4982. {
  4983. currentStatus = Faulted; //OCPP Status: Faulted
  4984. }
  4985. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4986. {
  4987. currentStatus = Reserved; //OCPP Status: Reserved
  4988. }
  4989. }//end of the same index
  4990. }//end of for AC_QUANTITY
  4991. }
  4992. //it's option
  4993. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4994. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  4995. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  4996. {
  4997. isStateChanged = FALSE;
  4998. }
  4999. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5000. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5001. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5002. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5003. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5004. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5005. random_uuid(guid);
  5006. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5007. , MESSAGE_TYPE_CALL
  5008. , guid
  5009. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5010. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5011. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5012. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5013. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5014. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5015. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5016. if((server_sign == TRUE) && isStateChanged)
  5017. {
  5018. LWS_Send(message);
  5019. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5020. 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*/)
  5021. {
  5022. //DEBUG_ERROR("statusNotification mapitem pass");
  5023. result = PASS;
  5024. }
  5025. }
  5026. else
  5027. {
  5028. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5029. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5030. result = PASS;
  5031. }
  5032. return result;
  5033. }
  5034. int sendStopTransactionRequest(int gun_index)
  5035. {
  5036. mtrace();
  5037. int result = FAIL;
  5038. //char message[1500]={0};
  5039. char guid[37]={0};
  5040. char tempdata[65]={0};
  5041. int tempIndex = 0;
  5042. char TempStopTransaction[256];
  5043. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5044. //int idx_sample=0;
  5045. DEBUG_INFO("sendStopTransactionRequest \n");
  5046. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5047. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5048. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5049. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5050. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5051. {
  5052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5053. {
  5054. tempIndex = ((gun_index==2) ? 1: 0);
  5055. }
  5056. else
  5057. {
  5058. tempIndex = gun_index;
  5059. }
  5060. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5061. {
  5062. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5063. {
  5064. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5065. }
  5066. }// END OF CHAdeMO_QUANTITY
  5067. }
  5068. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5069. {
  5070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5071. {
  5072. tempIndex = ((gun_index==2) ? 1: 0);
  5073. }
  5074. else
  5075. {
  5076. tempIndex = gun_index;
  5077. }
  5078. for (int index = 0; index < CCS_QUANTITY; index++)
  5079. {
  5080. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5081. {
  5082. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5083. }
  5084. }// END OF CCS_QUANTITY
  5085. }
  5086. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5087. {
  5088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5089. {
  5090. tempIndex = ((gun_index==2) ? 1: 0);
  5091. }
  5092. else
  5093. {
  5094. tempIndex = gun_index;
  5095. }
  5096. for (int index = 0; index < GB_QUANTITY; index++)
  5097. {
  5098. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5099. {
  5100. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5101. }
  5102. }// END OF GB_QUANTITY
  5103. }
  5104. else if(gunType[gun_index] == GUN_TYPE_DO)
  5105. {
  5106. tempIndex = gun_index;
  5107. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5108. {
  5109. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5110. {
  5111. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5112. }
  5113. }// END OF GB_QUANTITY
  5114. }
  5115. else
  5116. {
  5117. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5118. {
  5119. tempIndex = 2;
  5120. }
  5121. else
  5122. {
  5123. tempIndex = gun_index;
  5124. }
  5125. for (int index = 0; index < AC_QUANTITY; index++)
  5126. {
  5127. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5128. {
  5129. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5130. }
  5131. }// END OF AC_QUANTITY
  5132. }
  5133. //====================================== Stop Transaction Time =====================================================
  5134. struct timeval tmnow;
  5135. struct tm *tm;
  5136. char buf[28];//, usec_buf[6];
  5137. gettimeofday(&tmnow, NULL);
  5138. time_t t;
  5139. t = time(NULL);
  5140. /*UTC time and date*/
  5141. tm = gmtime(&t);
  5142. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5143. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5144. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5145. random_uuid(guid);
  5146. /***********************************transactionData******************************************************/
  5147. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5148. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5149. //=================================
  5150. // Transaction_Begin
  5151. //=================================
  5152. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5153. {
  5154. //============================================ Energy.Active.Import.Interval ================================
  5155. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5156. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5158. 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*/]);
  5159. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5160. 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))
  5161. {
  5162. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5163. }
  5164. else
  5165. {
  5166. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5167. }
  5168. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5169. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5170. }
  5171. //=================================
  5172. // Transaction_End
  5173. //=================================
  5174. // ================================= Current.Import L1 ===============================================
  5175. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5176. {
  5177. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5178. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5179. {
  5180. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5181. {
  5182. tempIndex = ((gun_index==2) ? 1: 0);
  5183. }
  5184. else
  5185. {
  5186. tempIndex = gun_index;
  5187. }
  5188. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5189. {
  5190. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5191. {
  5192. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5193. }
  5194. }// End of for CHAdeMO_QUANTITY
  5195. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5196. }
  5197. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5198. {
  5199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5200. {
  5201. tempIndex = ((gun_index==2) ? 1: 0);
  5202. }
  5203. else
  5204. {
  5205. tempIndex = gun_index;
  5206. }
  5207. for (int index = 0; index < CCS_QUANTITY; index++)
  5208. {
  5209. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5210. {
  5211. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5212. }
  5213. }// End of for CCS_QUANTITY
  5214. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5215. }
  5216. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5217. {
  5218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5219. {
  5220. tempIndex = ((gun_index==2) ? 1: 0);
  5221. }
  5222. else
  5223. {
  5224. tempIndex = gun_index;
  5225. }
  5226. for (int index = 0; index < GB_QUANTITY; index++)
  5227. {
  5228. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5229. {
  5230. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5231. }
  5232. }// End of for GB_QUANTITY
  5233. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5234. }
  5235. else if(gunType[gun_index] == GUN_TYPE_DO)
  5236. {
  5237. tempIndex = gun_index;
  5238. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5239. {
  5240. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5241. {
  5242. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5243. }
  5244. }
  5245. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5246. }
  5247. else
  5248. {
  5249. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5250. {
  5251. tempIndex = 2;
  5252. }
  5253. else
  5254. {
  5255. tempIndex = gun_index;
  5256. }
  5257. for (int index = 0; index < AC_QUANTITY; index++)
  5258. {
  5259. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5260. {
  5261. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5262. }
  5263. }// End of for AC_QUANTITY
  5264. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5265. }
  5266. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5267. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5268. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5269. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5270. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5271. }
  5272. // ================================= Energy.Active.Import.Interval ==============================================
  5273. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5274. {
  5275. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5276. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5277. {
  5278. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5279. {
  5280. tempIndex = ((gun_index==2) ? 1: 0);
  5281. }
  5282. else
  5283. {
  5284. tempIndex = gun_index;
  5285. }
  5286. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5287. {
  5288. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5289. {
  5290. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5291. }
  5292. }// END OF CHAdeMO_QUANTITY
  5293. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5294. }
  5295. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5296. {
  5297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5298. {
  5299. tempIndex = ((gun_index==2) ? 1: 0);
  5300. }
  5301. else
  5302. {
  5303. tempIndex = gun_index;
  5304. }
  5305. for (int index = 0; index < CCS_QUANTITY; index++)
  5306. {
  5307. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5308. {
  5309. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5310. }
  5311. }// END OF CCS_QUANTITY
  5312. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5313. }
  5314. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5315. {
  5316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5317. {
  5318. tempIndex = ((gun_index==2) ? 1: 0);
  5319. }
  5320. else
  5321. {
  5322. tempIndex = gun_index;
  5323. }
  5324. for (int index = 0; index < GB_QUANTITY; index++)
  5325. {
  5326. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5327. {
  5328. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5329. }
  5330. }// END OF GB_QUANTITY
  5331. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5332. }
  5333. else if(gunType[gun_index] == GUN_TYPE_DO)
  5334. {
  5335. tempIndex = gun_index;
  5336. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5337. {
  5338. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5339. {
  5340. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5341. }
  5342. }
  5343. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5344. }
  5345. else
  5346. {
  5347. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5348. {
  5349. tempIndex = 2;
  5350. }
  5351. else
  5352. {
  5353. tempIndex = gun_index;
  5354. }
  5355. for (int index = 0; index < AC_QUANTITY; index++)
  5356. {
  5357. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5358. {
  5359. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5360. }
  5361. }// END OF AC_QUANTITY
  5362. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5363. }
  5364. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5365. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5366. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5367. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5368. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5369. }
  5370. //=================================== Power.Active.Import ==================================================
  5371. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5372. {
  5373. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5374. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5375. {
  5376. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5377. {
  5378. tempIndex = ((gun_index==2) ? 1: 0);
  5379. }
  5380. else
  5381. {
  5382. tempIndex = gun_index;
  5383. }
  5384. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5385. {
  5386. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5387. {
  5388. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5389. }
  5390. } // End for CHAdeMO_QUANTITY
  5391. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5392. }
  5393. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5394. {
  5395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5396. {
  5397. tempIndex = ((gun_index==2) ? 1: 0);
  5398. }
  5399. else
  5400. {
  5401. tempIndex = gun_index;
  5402. }
  5403. for (int index = 0; index < CCS_QUANTITY; index++)
  5404. {
  5405. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5406. {
  5407. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5408. }
  5409. } // END for CCS_QUANTITY
  5410. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5411. }
  5412. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5413. {
  5414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5415. {
  5416. tempIndex = ((gun_index==2) ? 1: 0);
  5417. }
  5418. else
  5419. {
  5420. tempIndex = gun_index;
  5421. }
  5422. for (int index = 0; index < GB_QUANTITY; index++)
  5423. {
  5424. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5425. {
  5426. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5427. }
  5428. }// END for GB_QUANTITY
  5429. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5430. }
  5431. else if(gunType[gun_index] == GUN_TYPE_DO)
  5432. {
  5433. tempIndex = gun_index;
  5434. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5435. {
  5436. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5437. {
  5438. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5439. }
  5440. }
  5441. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5442. }
  5443. else
  5444. {
  5445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5446. {
  5447. tempIndex = 2;
  5448. }
  5449. else
  5450. {
  5451. tempIndex = gun_index;
  5452. }
  5453. for (int index = 0; index < AC_QUANTITY; index++)
  5454. {
  5455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5456. {
  5457. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5458. }
  5459. } // END for AC_QUANTITY
  5460. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5461. }
  5462. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5463. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5465. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5466. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5467. }
  5468. //============================ Voltage L1 ====================================
  5469. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5470. {
  5471. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5472. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5473. {
  5474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5475. {
  5476. tempIndex = ((gun_index==2) ? 1: 0);
  5477. }
  5478. else
  5479. {
  5480. tempIndex = gun_index;
  5481. }
  5482. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5483. {
  5484. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5485. {
  5486. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5487. }
  5488. } // END OF FOR CHAdeMO_QUANTITY
  5489. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5490. }
  5491. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5492. {
  5493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5494. {
  5495. tempIndex = ((gun_index==2) ? 1: 0);
  5496. }
  5497. else
  5498. {
  5499. tempIndex = gun_index;
  5500. }
  5501. for (int index = 0; index < CCS_QUANTITY; index++)
  5502. {
  5503. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5504. {
  5505. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5506. }
  5507. } // END OF FOR CCS_QUANTITY
  5508. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5509. }
  5510. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5511. {
  5512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5513. {
  5514. tempIndex = ((gun_index==2) ? 1: 0);
  5515. }
  5516. else
  5517. {
  5518. tempIndex = gun_index;
  5519. }
  5520. for (int index = 0; index < GB_QUANTITY; index++)
  5521. {
  5522. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5523. {
  5524. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5525. }
  5526. } // END OF FOR GB_QUANTITY
  5527. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5528. }
  5529. else if(gunType[gun_index] == GUN_TYPE_DO)
  5530. {
  5531. tempIndex = gun_index;
  5532. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5533. {
  5534. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5535. {
  5536. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5537. }
  5538. }
  5539. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5540. }
  5541. else
  5542. {
  5543. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5544. {
  5545. tempIndex = 2;
  5546. }
  5547. else
  5548. {
  5549. tempIndex = gun_index;
  5550. }
  5551. for (int index = 0; index < AC_QUANTITY; index++)
  5552. {
  5553. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5554. {
  5555. 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
  5556. }
  5557. } // END OF FOR AC_QUANTITY
  5558. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5559. }
  5560. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5561. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5562. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5563. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5564. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5565. }
  5566. //====================== End SoC ================================
  5567. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5568. {
  5569. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5570. 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))
  5571. {
  5572. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5573. {
  5574. tempIndex = ((gun_index==2) ? 1: 0);
  5575. }
  5576. else
  5577. {
  5578. tempIndex = gun_index;
  5579. }
  5580. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5581. {
  5582. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5583. {
  5584. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5585. {
  5586. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5587. }
  5588. }
  5589. }
  5590. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5591. {
  5592. for (int index = 0; index < CCS_QUANTITY; index++)
  5593. {
  5594. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5595. {
  5596. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5597. }
  5598. }
  5599. }
  5600. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5601. {
  5602. for (int index = 0; index < GB_QUANTITY; index++)
  5603. {
  5604. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5605. {
  5606. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5607. }
  5608. }
  5609. }
  5610. else if(gunType[gun_index] == GUN_TYPE_DO)
  5611. {
  5612. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5613. {
  5614. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5615. {
  5616. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5617. }
  5618. }
  5619. }
  5620. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5622. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5624. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5625. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5626. } // END FOR DC CASE
  5627. }
  5628. // ================================= Current.Import L2 ===============================================
  5629. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5630. {
  5631. // AC 3 phse L2 current
  5632. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5633. {
  5634. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5635. {
  5636. tempIndex = 2;
  5637. }
  5638. else
  5639. {
  5640. tempIndex = gun_index;
  5641. }
  5642. for (int index = 0; index < AC_QUANTITY; index++)
  5643. {
  5644. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5645. {
  5646. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5647. }
  5648. }// End of for AC_QUANTITY
  5649. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5650. }
  5651. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5656. }
  5657. // ================================= Current.Import L3 ===============================================
  5658. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5659. {
  5660. // AC 3 phse L3 current
  5661. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5662. {
  5663. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5664. {
  5665. tempIndex = 2;
  5666. }
  5667. else
  5668. {
  5669. tempIndex = gun_index;
  5670. }
  5671. for (int index = 0; index < AC_QUANTITY; index++)
  5672. {
  5673. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5674. {
  5675. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5676. }
  5677. }// End of for AC_QUANTITY
  5678. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5679. }
  5680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5682. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5685. }
  5686. //============================ Voltage L2 ====================================
  5687. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5688. {
  5689. // AC 3 phse L2 voltage
  5690. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5691. {
  5692. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5693. {
  5694. tempIndex = 2;
  5695. }
  5696. else
  5697. {
  5698. tempIndex = gun_index;
  5699. }
  5700. for (int index = 0; index < AC_QUANTITY; index++)
  5701. {
  5702. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5703. {
  5704. 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
  5705. }
  5706. } // END OF FOR AC_QUANTITY
  5707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5708. }
  5709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5710. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5711. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5712. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5713. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5714. }
  5715. //============================ Voltage L3 ====================================
  5716. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5717. {
  5718. // AC 3 phse L3 voltage
  5719. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5720. {
  5721. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5722. {
  5723. tempIndex = 2;
  5724. }
  5725. else
  5726. {
  5727. tempIndex = gun_index;
  5728. }
  5729. for (int index = 0; index < AC_QUANTITY; index++)
  5730. {
  5731. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5732. {
  5733. 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
  5734. }
  5735. } // END OF FOR AC_QUANTITY
  5736. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5737. }
  5738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5742. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5743. }
  5744. //====================== Start SoC ================================
  5745. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5746. {
  5747. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5748. 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))
  5749. {
  5750. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5751. {
  5752. tempIndex = ((gun_index==2) ? 1: 0);
  5753. }
  5754. else
  5755. {
  5756. tempIndex = gun_index;
  5757. }
  5758. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5759. {
  5760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5761. {
  5762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5763. {
  5764. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5765. }
  5766. }
  5767. }
  5768. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5769. {
  5770. for (int index = 0; index < CCS_QUANTITY; index++)
  5771. {
  5772. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5773. {
  5774. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5775. }
  5776. }
  5777. }
  5778. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5779. {
  5780. for (int index = 0; index < GB_QUANTITY; index++)
  5781. {
  5782. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5783. {
  5784. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5785. }
  5786. }
  5787. }
  5788. else if(gunType[gun_index] == GUN_TYPE_DO)
  5789. {
  5790. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5791. {
  5792. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5793. {
  5794. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5795. }
  5796. }
  5797. }
  5798. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5800. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5804. } // END FOR DC CASE
  5805. }
  5806. //================================================ Message create ====================================================
  5807. json_object *StopTransaction = json_object_new_object();
  5808. json_object *transactionDatas = json_object_new_array();
  5809. json_object *sampledValues = json_object_new_array();
  5810. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5811. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5812. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5813. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5814. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5815. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5816. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5817. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5818. {
  5819. json_object *transactionData = json_object_new_object();
  5820. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5821. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5822. {
  5823. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5824. {
  5825. json_object *sampledValue = json_object_new_object();
  5826. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5827. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5828. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5829. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5830. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5831. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5832. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5833. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5834. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5835. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5836. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5837. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5838. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5839. json_object_array_add(sampledValues, sampledValue);
  5840. }
  5841. }
  5842. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5843. json_object_array_add(transactionDatas, transactionData);
  5844. }
  5845. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5846. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5847. ,MESSAGE_TYPE_CALL
  5848. ,guid
  5849. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5850. json_object_put(StopTransaction);
  5851. #if 1 // for TempStopTransaction
  5852. //Delete TempStopTransaction
  5853. if((access(TempStopTransaction,F_OK))!=-1)
  5854. {
  5855. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5856. }
  5857. #endif
  5858. #if 1
  5859. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5860. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5861. {
  5862. result = PASS;
  5863. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5864. }
  5865. #endif
  5866. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5867. OCPP_insert_transaction_msg(NO, queuedata);
  5868. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5869. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5870. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5871. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5872. {
  5873. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5874. }
  5875. //for test
  5876. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5877. return result;
  5878. }
  5879. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5880. {
  5881. mtrace();
  5882. int result = FAIL;
  5883. char guid[37]={0};
  5884. char tempdata[65]={0};
  5885. int tempIndex = 0;
  5886. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5887. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5888. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5889. //set value
  5890. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5891. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5892. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5893. -1);
  5894. random_uuid(guid);
  5895. //UTC Date time
  5896. struct timeval tmnow;
  5897. struct tm *tm;
  5898. char buf[28];//, usec_buf[6];
  5899. gettimeofday(&tmnow, NULL);
  5900. time_t t;
  5901. t = time(NULL);
  5902. /*UTC time and date*/
  5903. tm = gmtime(&t);
  5904. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5905. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5906. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5907. //********************************(1)Current.Import L1************************************************/
  5908. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5909. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5910. (dataType == ReadingContext_Trigger))
  5911. {
  5912. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5913. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5914. {
  5915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5916. {
  5917. tempIndex = ((gun_index==2) ? 1: 0);
  5918. }
  5919. else
  5920. {
  5921. tempIndex = gun_index;
  5922. }
  5923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5924. {
  5925. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5926. {
  5927. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5928. }
  5929. }
  5930. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5931. }
  5932. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5933. {
  5934. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5935. {
  5936. tempIndex = ((gun_index==2) ? 1: 0);
  5937. }
  5938. else
  5939. {
  5940. tempIndex = gun_index;
  5941. }
  5942. for (int index = 0; index < CCS_QUANTITY; index++)
  5943. {
  5944. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5945. {
  5946. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5947. }
  5948. }
  5949. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5950. }
  5951. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5952. {
  5953. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5954. {
  5955. tempIndex = ((gun_index==2) ? 1: 0);
  5956. }
  5957. else
  5958. {
  5959. tempIndex = gun_index;
  5960. }
  5961. for (int index = 0; index < GB_QUANTITY; index++)
  5962. {
  5963. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5964. {
  5965. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5966. }
  5967. }
  5968. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5969. }
  5970. else if(gunType[gun_index] == GUN_TYPE_DO)
  5971. {
  5972. tempIndex = gun_index;
  5973. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5974. {
  5975. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5976. {
  5977. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5978. }
  5979. }
  5980. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5981. }
  5982. else
  5983. {
  5984. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5985. {
  5986. tempIndex = 2;
  5987. }
  5988. else
  5989. {
  5990. tempIndex = gun_index;
  5991. }
  5992. for (int index = 0; index < AC_QUANTITY; index++)
  5993. {
  5994. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5995. {
  5996. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5997. }
  5998. }
  5999. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6000. }
  6001. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6002. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6003. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6004. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6005. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6006. }
  6007. //********************************(2)Energy.Active.Import.Register ************************************************/
  6008. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6009. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6010. (dataType == ReadingContext_Trigger))
  6011. {
  6012. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6013. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6014. {
  6015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6016. {
  6017. tempIndex = ((gun_index==2) ? 1: 0);
  6018. }
  6019. else
  6020. {
  6021. tempIndex = gun_index;
  6022. }
  6023. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6024. {
  6025. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6026. {
  6027. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6028. }
  6029. }
  6030. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6031. }
  6032. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6033. {
  6034. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6035. {
  6036. tempIndex = ((gun_index==2) ? 1: 0);
  6037. }
  6038. else
  6039. {
  6040. tempIndex = gun_index;
  6041. }
  6042. for (int index = 0; index < CCS_QUANTITY; index++)
  6043. {
  6044. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6045. {
  6046. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6047. }
  6048. }
  6049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6050. }
  6051. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6052. {
  6053. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6054. {
  6055. tempIndex = ((gun_index==2) ? 1: 0);
  6056. }
  6057. else
  6058. {
  6059. tempIndex = gun_index;
  6060. }
  6061. for (int index = 0; index < GB_QUANTITY; index++)
  6062. {
  6063. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6064. {
  6065. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6066. }
  6067. }
  6068. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6069. }
  6070. else if(gunType[gun_index] == GUN_TYPE_DO)
  6071. {
  6072. tempIndex = gun_index;
  6073. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6074. {
  6075. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6076. {
  6077. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6078. }
  6079. }
  6080. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6081. }
  6082. else
  6083. {
  6084. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6085. {
  6086. tempIndex = 2;
  6087. }
  6088. else
  6089. {
  6090. tempIndex = gun_index;
  6091. }
  6092. for (int index = 0; index < AC_QUANTITY; index++)
  6093. {
  6094. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6095. {
  6096. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6097. }
  6098. }
  6099. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6100. }
  6101. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6102. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6103. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6104. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6105. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6106. }
  6107. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6108. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6109. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6110. (dataType == ReadingContext_Trigger))
  6111. {
  6112. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6113. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6114. {
  6115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6116. {
  6117. tempIndex = ((gun_index==2) ? 1: 0);
  6118. }
  6119. else
  6120. {
  6121. tempIndex = gun_index;
  6122. }
  6123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6124. {
  6125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6126. {
  6127. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6128. }
  6129. } // END OF FOR CHAdeMO_QUANTITY
  6130. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6131. }
  6132. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6133. {
  6134. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6135. {
  6136. tempIndex = ((gun_index==2) ? 1: 0);
  6137. }
  6138. else
  6139. {
  6140. tempIndex = gun_index;
  6141. }
  6142. for (int index = 0; index < CCS_QUANTITY; index++)
  6143. {
  6144. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6145. {
  6146. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6147. }
  6148. } // END OF CCS_QUANTITY
  6149. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6150. }
  6151. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6152. {
  6153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6154. {
  6155. tempIndex = ((gun_index==2) ? 1: 0);
  6156. }
  6157. else
  6158. {
  6159. tempIndex = gun_index;
  6160. }
  6161. for (int index = 0; index < GB_QUANTITY; index++)
  6162. {
  6163. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6164. {
  6165. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6166. }
  6167. } // END OF GB_QUANTITY
  6168. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6169. }
  6170. else if(gunType[gun_index] == GUN_TYPE_DO)
  6171. {
  6172. tempIndex = gun_index;
  6173. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6174. {
  6175. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6176. {
  6177. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6178. }
  6179. }
  6180. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6181. }
  6182. else
  6183. {
  6184. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6185. {
  6186. tempIndex = 2;
  6187. }
  6188. else
  6189. {
  6190. tempIndex = gun_index;
  6191. }
  6192. for (int index = 0; index < AC_QUANTITY; index++)
  6193. {
  6194. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6195. {
  6196. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6197. }
  6198. }
  6199. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6200. }
  6201. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6202. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6203. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6204. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6205. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6206. }
  6207. //********************************(4)Power.Active.Import************************************************/
  6208. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6209. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6210. (dataType == ReadingContext_Trigger))
  6211. {
  6212. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6213. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6214. {
  6215. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6216. {
  6217. tempIndex = ((gun_index==2) ? 1: 0);
  6218. }
  6219. else
  6220. {
  6221. tempIndex = gun_index;
  6222. }
  6223. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6224. {
  6225. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6226. {
  6227. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6228. }
  6229. } // END OF FOR
  6230. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6231. }
  6232. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6233. {
  6234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6235. {
  6236. tempIndex = ((gun_index==2) ? 1: 0);
  6237. }
  6238. else
  6239. {
  6240. tempIndex = gun_index;
  6241. }
  6242. for (int index = 0; index < CCS_QUANTITY; index++)
  6243. {
  6244. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6245. {
  6246. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6247. }
  6248. }
  6249. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6250. }
  6251. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6252. {
  6253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6254. {
  6255. tempIndex = ((gun_index==2) ? 1: 0);
  6256. }
  6257. else
  6258. {
  6259. tempIndex = gun_index;
  6260. }
  6261. for (int index = 0; index < GB_QUANTITY; index++)
  6262. {
  6263. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6264. {
  6265. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6266. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6267. }
  6268. }
  6269. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6270. }
  6271. else if(gunType[gun_index] == GUN_TYPE_DO)
  6272. {
  6273. tempIndex = gun_index;
  6274. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6275. {
  6276. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6277. {
  6278. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6279. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6280. }
  6281. }
  6282. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6283. }
  6284. else
  6285. {
  6286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6287. {
  6288. tempIndex = 2;
  6289. }
  6290. else
  6291. {
  6292. tempIndex = gun_index;
  6293. }
  6294. for (int index = 0; index < AC_QUANTITY; index++)
  6295. {
  6296. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6297. {
  6298. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6299. }
  6300. }
  6301. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6302. }
  6303. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6304. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6305. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6306. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6307. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6308. }
  6309. //***********************************************(5)VOLTAGE L1******************************************************/
  6310. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6311. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6312. (dataType == ReadingContext_Trigger))
  6313. {
  6314. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6315. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6316. {
  6317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6318. {
  6319. tempIndex = ((gun_index==2) ? 1: 0);
  6320. }
  6321. else
  6322. {
  6323. tempIndex = gun_index;
  6324. }
  6325. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6326. {
  6327. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6328. {
  6329. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6330. }
  6331. }
  6332. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6333. }
  6334. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6335. {
  6336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6337. {
  6338. tempIndex = ((gun_index==2) ? 1: 0);
  6339. }
  6340. else
  6341. {
  6342. tempIndex = gun_index;
  6343. }
  6344. for (int index = 0; index < CCS_QUANTITY; index++)
  6345. {
  6346. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6347. {
  6348. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6349. }
  6350. }
  6351. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6352. }
  6353. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6354. {
  6355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6356. {
  6357. tempIndex = ((gun_index==2) ? 1: 0);
  6358. }
  6359. else
  6360. {
  6361. tempIndex = gun_index;
  6362. }
  6363. for (int index = 0; index < GB_QUANTITY; index++)
  6364. {
  6365. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6366. {
  6367. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6368. }
  6369. }
  6370. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6371. }
  6372. else if(gunType[gun_index] == GUN_TYPE_DO)
  6373. {
  6374. tempIndex = gun_index;
  6375. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6376. {
  6377. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6378. {
  6379. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6380. }
  6381. }
  6382. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6383. }
  6384. else
  6385. {
  6386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6387. {
  6388. tempIndex = 2;
  6389. }
  6390. else
  6391. {
  6392. tempIndex = gun_index;
  6393. }
  6394. for (int index = 0; index < AC_QUANTITY; index++)
  6395. {
  6396. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6397. {
  6398. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6399. }
  6400. }
  6401. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6402. }
  6403. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6404. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6405. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6406. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6407. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6408. }
  6409. //***********************************************(6)SOC******************************************************/
  6410. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6411. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6412. (dataType == ReadingContext_Trigger))
  6413. {
  6414. 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))
  6415. {
  6416. //idx_sample=5;
  6417. //sampledValue = NULL;
  6418. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6419. {
  6420. tempIndex = ((gun_index==2) ? 1: 0);
  6421. }
  6422. else
  6423. {
  6424. tempIndex = gun_index;
  6425. }
  6426. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6427. {
  6428. //tempIndex = ((gun_index==2) ? 1: 0);
  6429. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6430. {
  6431. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6432. {
  6433. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6434. }
  6435. }
  6436. }
  6437. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6438. {
  6439. //tempIndex = ((gun_index==2) ? 1: 0);
  6440. for (int index = 0; index < CCS_QUANTITY; index++)
  6441. {
  6442. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6443. {
  6444. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6445. }
  6446. }
  6447. }
  6448. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6449. {
  6450. //tempIndex = ((gun_index==2) ? 1: 0);
  6451. for (int index = 0; index < GB_QUANTITY; index++)
  6452. {
  6453. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6454. {
  6455. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6456. }
  6457. }
  6458. }
  6459. else if(gunType[gun_index] == GUN_TYPE_DO)
  6460. {
  6461. //tempIndex = ((gun_index==2) ? 1: 0);
  6462. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6463. {
  6464. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6465. {
  6466. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6467. }
  6468. }
  6469. }
  6470. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6471. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6472. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6473. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6474. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6475. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6476. }
  6477. }
  6478. //********************************(7)Current.Import L2************************************************/
  6479. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6480. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6481. (dataType == ReadingContext_Trigger))
  6482. {
  6483. // Only for AC 3 phase
  6484. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6485. {
  6486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6487. {
  6488. tempIndex = 2;
  6489. }
  6490. else
  6491. {
  6492. tempIndex = gun_index;
  6493. }
  6494. for (int index = 0; index < AC_QUANTITY; index++)
  6495. {
  6496. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6497. {
  6498. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6499. }
  6500. }
  6501. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6502. }
  6503. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6504. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6505. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6506. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6507. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6508. }
  6509. //********************************(8)Current.Import L3************************************************/
  6510. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6511. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6512. (dataType == ReadingContext_Trigger))
  6513. {
  6514. // Only for AC 3 phase
  6515. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6516. {
  6517. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6518. {
  6519. tempIndex = 2;
  6520. }
  6521. else
  6522. {
  6523. tempIndex = gun_index;
  6524. }
  6525. for (int index = 0; index < AC_QUANTITY; index++)
  6526. {
  6527. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6528. {
  6529. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6530. }
  6531. }
  6532. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6533. }
  6534. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6535. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6536. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6537. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6538. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6539. }
  6540. //***********************************************(9)VOLTAGE L2******************************************************/
  6541. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6542. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6543. (dataType == ReadingContext_Trigger))
  6544. {
  6545. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6546. {
  6547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6548. {
  6549. tempIndex = 2;
  6550. }
  6551. else
  6552. {
  6553. tempIndex = gun_index;
  6554. }
  6555. for (int index = 0; index < AC_QUANTITY; index++)
  6556. {
  6557. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6558. {
  6559. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6560. }
  6561. }
  6562. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6563. }
  6564. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6565. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6566. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6567. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6568. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6569. }
  6570. //***********************************************(10)VOLTAGE L3******************************************************/
  6571. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6572. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6573. (dataType == ReadingContext_Trigger))
  6574. {
  6575. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6576. {
  6577. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6578. {
  6579. tempIndex = 2;
  6580. }
  6581. else
  6582. {
  6583. tempIndex = gun_index;
  6584. }
  6585. for (int index = 0; index < AC_QUANTITY; index++)
  6586. {
  6587. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6588. {
  6589. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6590. }
  6591. }
  6592. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6593. }
  6594. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6595. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6596. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6597. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6598. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6599. }
  6600. //***********************************************(11)Current.Offered******************************************************/
  6601. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6602. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6603. (dataType == ReadingContext_Trigger))
  6604. {
  6605. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6606. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6607. {
  6608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6609. {
  6610. tempIndex = ((gun_index==2) ? 1: 0);
  6611. }
  6612. else
  6613. {
  6614. tempIndex = gun_index;
  6615. }
  6616. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6617. {
  6618. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6619. {
  6620. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6621. }
  6622. } // END OF FOR CHAdeMO_QUANTITY
  6623. }
  6624. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6625. {
  6626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6627. {
  6628. tempIndex = ((gun_index==2) ? 1: 0);
  6629. }
  6630. else
  6631. {
  6632. tempIndex = gun_index;
  6633. }
  6634. for (int index = 0; index < CCS_QUANTITY; index++)
  6635. {
  6636. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6637. {
  6638. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6639. }
  6640. } // END OF CCS_QUANTITY
  6641. }
  6642. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6643. {
  6644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6645. {
  6646. tempIndex = ((gun_index==2) ? 1: 0);
  6647. }
  6648. else
  6649. {
  6650. tempIndex = gun_index;
  6651. }
  6652. for (int index = 0; index < GB_QUANTITY; index++)
  6653. {
  6654. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6655. {
  6656. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6657. }
  6658. } // END OF GB_QUANTITY
  6659. }
  6660. else if(gunType[gun_index] == GUN_TYPE_DO)
  6661. {
  6662. tempIndex = gun_index;
  6663. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6664. {
  6665. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6666. {
  6667. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6668. }
  6669. }
  6670. }
  6671. else
  6672. {
  6673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6674. {
  6675. tempIndex = 2;
  6676. }
  6677. else
  6678. {
  6679. tempIndex = gun_index;
  6680. }
  6681. for (int index = 0; index < AC_QUANTITY; index++)
  6682. {
  6683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6684. {
  6685. uint16_t currentOffer;
  6686. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6687. {
  6688. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6689. }
  6690. else
  6691. {
  6692. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6693. }
  6694. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6695. }
  6696. }
  6697. }
  6698. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6699. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6700. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6701. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6702. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6703. }
  6704. //***********************************************(12)Power.Offered******************************************************/
  6705. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6706. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6707. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6708. {
  6709. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6710. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6711. {
  6712. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6713. {
  6714. tempIndex = ((gun_index==2) ? 1: 0);
  6715. }
  6716. else
  6717. {
  6718. tempIndex = gun_index;
  6719. }
  6720. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6721. {
  6722. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6723. {
  6724. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6725. }
  6726. } // END OF FOR CHAdeMO_QUANTITY
  6727. }
  6728. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6729. {
  6730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6731. {
  6732. tempIndex = ((gun_index==2) ? 1: 0);
  6733. }
  6734. else
  6735. {
  6736. tempIndex = gun_index;
  6737. }
  6738. for (int index = 0; index < CCS_QUANTITY; index++)
  6739. {
  6740. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6741. {
  6742. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6743. }
  6744. } // END OF CCS_QUANTITY
  6745. }
  6746. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6747. {
  6748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6749. {
  6750. tempIndex = ((gun_index==2) ? 1: 0);
  6751. }
  6752. else
  6753. {
  6754. tempIndex = gun_index;
  6755. }
  6756. for (int index = 0; index < GB_QUANTITY; index++)
  6757. {
  6758. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6759. {
  6760. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6761. }
  6762. } // END OF GB_QUANTITY
  6763. }
  6764. else if(gunType[gun_index] == GUN_TYPE_DO)
  6765. {
  6766. tempIndex = gun_index;
  6767. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6768. {
  6769. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6770. {
  6771. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6772. }
  6773. }
  6774. }
  6775. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6776. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6777. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6778. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6779. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6780. }
  6781. // Message create ====================================================================================================
  6782. if(TRUE)
  6783. {
  6784. json_object *MeterValueReq = json_object_new_object();
  6785. json_object *MeterValues = json_object_new_array();
  6786. json_object *sampledValues = json_object_new_array();
  6787. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6788. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6789. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6790. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6791. {
  6792. json_object *MeterValue = json_object_new_object();
  6793. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6794. {
  6795. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6796. {
  6797. json_object *sampledValue = json_object_new_object();
  6798. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6799. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6800. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6801. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6802. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6803. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6804. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6805. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6806. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6807. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6808. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6809. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6810. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6811. json_object_array_add(sampledValues, sampledValue);
  6812. }
  6813. }
  6814. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6815. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6816. json_object_array_add(MeterValues, MeterValue);
  6817. }
  6818. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6819. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6820. ,gun_index + 1
  6821. ,MESSAGE_TYPE_CALL
  6822. ,guid
  6823. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6824. json_object_put(MeterValueReq);
  6825. }
  6826. // Put request guid to hash map
  6827. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6828. 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*/)
  6829. {
  6830. result = PASS;
  6831. //DEBUG_INFO("MeterValues mapitem pass\n");
  6832. }
  6833. if((dataType != ReadingContext_Trigger) &&
  6834. (dataType != ReadingContext_Sample_Clock) &&
  6835. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6836. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6837. else
  6838. {
  6839. if(FirstHeartBeat)
  6840. LWS_Send(queuedata +2);
  6841. }
  6842. return result;
  6843. }
  6844. int sendLogStatusNotificationRequest(char *status)
  6845. {
  6846. mtrace();
  6847. int result = PASS;
  6848. char message[4096]={0};
  6849. char guid[37]={0};
  6850. char tempdata[128]={0};
  6851. json_object *LogStatusNotification = json_object_new_object();
  6852. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6853. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6854. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6855. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6856. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6857. random_uuid(guid);
  6858. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6859. json_object_put(LogStatusNotification);
  6860. LWS_Send(message);
  6861. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6862. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6863. {
  6864. result = PASS;
  6865. }
  6866. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6867. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6868. return result;
  6869. }
  6870. int sendSecurityEventNotificationRequest()
  6871. {
  6872. mtrace();
  6873. int result = PASS;
  6874. char message[4096]={0};
  6875. char guid[37]={0};
  6876. char tempdata[128]={0};
  6877. json_object *SecurityEventNotification = json_object_new_object();
  6878. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6879. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6880. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6881. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6882. random_uuid(guid);
  6883. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6884. json_object_put(SecurityEventNotification);
  6885. LWS_Send(message);
  6886. sprintf(tempdata, "SecurityEventNotification,0");
  6887. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6888. {
  6889. result = PASS;
  6890. }
  6891. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6892. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6893. return result;
  6894. }
  6895. int sendSignCertificateRequest()
  6896. {
  6897. mtrace();
  6898. int result = PASS;
  6899. char message[4096]={0};
  6900. char guid[37]={0};
  6901. char tempdata[128]={0};
  6902. json_object *SignCertificate = json_object_new_object();
  6903. DEBUG_INFO("sendSignCertificateRequest...\n");
  6904. // Read csr file content
  6905. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6906. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6907. char *line = NULL;
  6908. size_t len = 0;
  6909. while(getline(&line, &len, fp) != -1)
  6910. {
  6911. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6912. {
  6913. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6914. }
  6915. }
  6916. fclose(fp);
  6917. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6918. random_uuid(guid);
  6919. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6920. json_object_put(SignCertificate);
  6921. LWS_Send(message);
  6922. sprintf(tempdata, "SignCertificate,0");
  6923. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6924. {
  6925. result = PASS;
  6926. }
  6927. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6928. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6929. return result;
  6930. }
  6931. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6932. {
  6933. mtrace();
  6934. int result = PASS;
  6935. char message[110]={0};
  6936. char guid[37]={0};
  6937. char tempdata[65]={0};
  6938. json_object *FirmwareStatusNotification = json_object_new_object();
  6939. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6940. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6941. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6942. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6943. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6944. random_uuid(guid);
  6945. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6946. json_object_put(FirmwareStatusNotification);
  6947. LWS_Send(message);
  6948. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6949. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6950. {
  6951. result = PASS;
  6952. }
  6953. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6954. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6955. return result;
  6956. }
  6957. //==========================================
  6958. // send confirm routine
  6959. //==========================================
  6960. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6961. {
  6962. mtrace();
  6963. int result = FAIL;
  6964. char message[100]={0};
  6965. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6966. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6967. LWS_Send(message);
  6968. result = TRUE;
  6969. return result;
  6970. }
  6971. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6972. {
  6973. mtrace();
  6974. int result = FAIL;
  6975. char message[100]={0};
  6976. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6977. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6978. LWS_Send(message);
  6979. result = TRUE;
  6980. return result;
  6981. }
  6982. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6983. {
  6984. mtrace();
  6985. int result = FAIL;
  6986. char message[100]={0};
  6987. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6988. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6989. LWS_Send(message);
  6990. result = TRUE;
  6991. return result;
  6992. }
  6993. int sendClearCacheConfirmation(char *uuid,char *payload)
  6994. {
  6995. mtrace();
  6996. int result = FAIL;
  6997. char message[500]={0};
  6998. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6999. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7000. LWS_Send(message);
  7001. return result;
  7002. }
  7003. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7004. {
  7005. mtrace();
  7006. int result = FAIL;
  7007. char message[500]={0};
  7008. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7009. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7010. LWS_Send(message);
  7011. return result;
  7012. }
  7013. int sendDataTransferConfirmation(char *uuid,char *payload)
  7014. {
  7015. mtrace();
  7016. char statusStr[20]={0};
  7017. char dataStr[10]={0};
  7018. char sstr[20]={0};
  7019. int c = 0;
  7020. char *loc;
  7021. int result = FAIL;
  7022. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7023. /**********************status**************************/
  7024. loc = strstr(payload, "status");
  7025. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7026. c = 0;
  7027. while (loc[3+strlen("status")+c] != '\"')
  7028. {
  7029. sstr[c] = loc[3+strlen("status")+c];
  7030. c++;
  7031. }
  7032. sstr[c] = '\0';
  7033. strcpy(statusStr, sstr);
  7034. /**********************data**************************/
  7035. loc = strstr(payload, "data");
  7036. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7037. c = 0;
  7038. while (loc[3+strlen("data")+c] != '\"')
  7039. {
  7040. sstr[c] = loc[3+strlen("data")+c];
  7041. c++;
  7042. }
  7043. sstr[c] = '\0';
  7044. strcpy(dataStr, sstr);
  7045. return result;
  7046. }
  7047. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7048. {
  7049. mtrace();
  7050. int result = FAIL;
  7051. char message[1000]={0};
  7052. int CompositeScheduleIndex = 0;
  7053. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7054. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7055. if(nPeriod == 0)
  7056. {
  7057. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7058. {
  7059. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7060. ,MESSAGE_TYPE_CALLRESULT
  7061. ,uuid
  7062. ,payload
  7063. ,connectorIdInt);
  7064. }
  7065. else
  7066. {
  7067. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7068. ,MESSAGE_TYPE_CALLRESULT
  7069. ,uuid
  7070. ,payload
  7071. ,connectorIdInt
  7072. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7073. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7074. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7075. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7076. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7077. }
  7078. }
  7079. else
  7080. {
  7081. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7082. ,MESSAGE_TYPE_CALLRESULT
  7083. ,uuid
  7084. ,payload
  7085. ,connectorIdInt
  7086. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7087. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7088. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7089. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7090. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7091. {
  7092. if (idx_sample == 0)
  7093. {
  7094. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7095. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7096. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7097. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7098. }
  7099. else
  7100. {
  7101. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7102. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7103. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7104. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7105. }
  7106. }
  7107. sprintf(message + strlen(message), "]}}]");
  7108. }
  7109. LWS_Send(message);
  7110. result = TRUE;
  7111. return result;
  7112. }
  7113. int sendGetConfigurationConfirmation(char *uuid)
  7114. {
  7115. mtrace();
  7116. int result = FAIL;
  7117. int MaxKeySupported = 0;
  7118. int sentConfigurationNumber= 0;
  7119. int sentunConfigurationNumber= 0;
  7120. char message[1024*10]={0};
  7121. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7122. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7123. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7124. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7125. ,MESSAGE_TYPE_CALLRESULT
  7126. ,uuid );
  7127. //configuration key
  7128. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7129. {
  7130. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7131. {
  7132. if (sentConfigurationNumber == 0)
  7133. {
  7134. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7135. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7136. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7137. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7138. }
  7139. else
  7140. {
  7141. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7142. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7143. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7144. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7145. }
  7146. sentConfigurationNumber = sentConfigurationNumber + 1;
  7147. }
  7148. }
  7149. sprintf(message + strlen(message), "]");
  7150. if(UnknownKeynum != 0)
  7151. {
  7152. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7153. //unkown key
  7154. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7155. {
  7156. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7157. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7158. if(sentunConfigurationNumber == 0)
  7159. {
  7160. sprintf(message + strlen(message), "\"%s\""
  7161. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7162. }
  7163. else
  7164. {
  7165. sprintf(message + strlen(message), ",\"%s\""
  7166. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7167. }
  7168. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7169. }
  7170. sprintf(message + strlen(message), "]");
  7171. }
  7172. sprintf(message + strlen(message), "}]");
  7173. LWS_Send(message);
  7174. return result;
  7175. }
  7176. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7177. {
  7178. mtrace();
  7179. int result = FAIL;
  7180. char message[400]={0};
  7181. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7182. if(strcmp(payload,"")==0)
  7183. {
  7184. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7185. }
  7186. else
  7187. {
  7188. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7189. }
  7190. LWS_Send(message);
  7191. result = TRUE;
  7192. return result;
  7193. }
  7194. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7195. {
  7196. mtrace();
  7197. int result = FAIL;
  7198. char message[80]={0};
  7199. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7200. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7201. LWS_Send(message);
  7202. result = TRUE;
  7203. return result;
  7204. }
  7205. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7206. {
  7207. mtrace();
  7208. int result = FAIL;
  7209. char message[80]={0};
  7210. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7211. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7212. LWS_Send(message);
  7213. result = TRUE;
  7214. return result;
  7215. }
  7216. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7217. {
  7218. mtrace();
  7219. int result = FAIL;
  7220. char message[80]={0};
  7221. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7222. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7223. LWS_Send(message);
  7224. result = TRUE;
  7225. return result;
  7226. }
  7227. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7228. {
  7229. mtrace();
  7230. int result = FAIL;
  7231. char message[80]={0};
  7232. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7233. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7234. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7235. LWS_Send(message);
  7236. result = TRUE;
  7237. return result;
  7238. }
  7239. int sendResetConfirmation(char *uuid,char *payload)
  7240. {
  7241. mtrace();
  7242. int result = FAIL;
  7243. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7244. char message[80]={0};
  7245. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7246. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7247. LWS_Send(message);
  7248. result = TRUE;
  7249. return result;
  7250. }
  7251. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7252. {
  7253. mtrace();
  7254. int result = FAIL;
  7255. char message[500]={0};
  7256. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7257. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7258. LWS_Send(message);
  7259. result = TRUE;
  7260. return result;
  7261. }
  7262. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7263. {
  7264. mtrace();
  7265. int result = FAIL;
  7266. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7267. char message[80]={0};
  7268. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7269. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7270. LWS_Send(message);
  7271. result = TRUE;
  7272. return result;
  7273. }
  7274. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7275. {
  7276. mtrace();
  7277. int result = FAIL;
  7278. char message[80]={0};
  7279. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7280. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7281. LWS_Send(message);
  7282. result = TRUE;
  7283. return result;
  7284. }
  7285. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7286. {
  7287. mtrace();
  7288. int result = FAIL;
  7289. char message[80]={0};
  7290. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7291. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7292. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7293. LWS_Send(message);
  7294. result = TRUE;
  7295. return result;
  7296. }
  7297. int sendUpdateFirmwareConfirmation(char *uuid)
  7298. {
  7299. mtrace();
  7300. int result = FAIL;
  7301. char message[60]={0};
  7302. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7303. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7304. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7305. LWS_Send(message);
  7306. result = TRUE;
  7307. return result;
  7308. }
  7309. int sendCertificateSignedConfirmation(char *uuid)
  7310. {
  7311. mtrace();
  7312. int result = PASS;
  7313. char message[4096]={0};
  7314. json_object *CertificateSigned = json_object_new_object();
  7315. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7316. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7317. sprintf(message,"[%d,\"%s\",%s]"
  7318. ,MESSAGE_TYPE_CALLRESULT
  7319. ,uuid
  7320. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7321. json_object_put(CertificateSigned);
  7322. LWS_Send(message);
  7323. return result;
  7324. }
  7325. int sendDeleteCertificateConfirmation(char *uuid)
  7326. {
  7327. mtrace();
  7328. int result = PASS;
  7329. char message[4096]={0};
  7330. json_object *DeleteCertificate = json_object_new_object();
  7331. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7332. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7333. sprintf(message,"[%d,\"%s\",%s]"
  7334. ,MESSAGE_TYPE_CALLRESULT
  7335. ,uuid
  7336. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7337. json_object_put(DeleteCertificate);
  7338. LWS_Send(message);
  7339. return result;
  7340. }
  7341. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7342. {
  7343. mtrace();
  7344. int result = PASS;
  7345. char message[4096]={0};
  7346. json_object *ExtendedTriggerMessage = json_object_new_object();
  7347. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7348. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7349. sprintf(message,"[%d,\"%s\",%s]"
  7350. ,MESSAGE_TYPE_CALLRESULT
  7351. ,uuid
  7352. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7353. json_object_put(ExtendedTriggerMessage);
  7354. LWS_Send(message);
  7355. return result;
  7356. }
  7357. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7358. {
  7359. mtrace();
  7360. int result = PASS;
  7361. char message[4096]={0};
  7362. json_object *GetInstalledCertificateIds = json_object_new_object();
  7363. json_object *certificateHashDataDatas = json_object_new_array();
  7364. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7365. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7366. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7367. {
  7368. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7369. {
  7370. json_object *certificateHashData = json_object_new_object();
  7371. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7372. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7373. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7374. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7375. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7376. }
  7377. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7378. }
  7379. else
  7380. {
  7381. json_object_put(certificateHashDataDatas);
  7382. }
  7383. sprintf(message,"[%d,\"%s\",%s]"
  7384. ,MESSAGE_TYPE_CALLRESULT
  7385. ,uuid
  7386. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7387. json_object_put(GetInstalledCertificateIds);
  7388. LWS_Send(message);
  7389. return result;
  7390. }
  7391. int sendGetLogConfirmation(char *uuid)
  7392. {
  7393. mtrace();
  7394. int result = PASS;
  7395. char message[4096]={0};
  7396. json_object *GetLog = json_object_new_object();
  7397. DEBUG_INFO("sendGetLogConfirmation...\n");
  7398. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7399. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7400. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7401. sprintf(message,"[%d,\"%s\",%s]"
  7402. ,MESSAGE_TYPE_CALLRESULT
  7403. ,uuid
  7404. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7405. json_object_put(GetLog);
  7406. LWS_Send(message);
  7407. return result;
  7408. }
  7409. int sendInstallCertificateConfirmation(char *uuid)
  7410. {
  7411. mtrace();
  7412. int result = PASS;
  7413. char message[4096]={0};
  7414. json_object *InstallCertificate = json_object_new_object();
  7415. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7416. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7417. sprintf(message,"[%d,\"%s\",%s]"
  7418. ,MESSAGE_TYPE_CALLRESULT
  7419. ,uuid
  7420. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7421. json_object_put(InstallCertificate);
  7422. LWS_Send(message);
  7423. return result;
  7424. }
  7425. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7426. {
  7427. mtrace();
  7428. int result = PASS;
  7429. char message[4096]={0};
  7430. json_object *SignedUpdateFirmware = json_object_new_object();
  7431. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7432. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7433. sprintf(message,"[%d,\"%s\",%s]"
  7434. ,MESSAGE_TYPE_CALLRESULT
  7435. ,uuid
  7436. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7437. json_object_put(SignedUpdateFirmware);
  7438. LWS_Send(message);
  7439. return result;
  7440. }
  7441. int sendUnknownConfirmation(char *uuid)
  7442. {
  7443. mtrace();
  7444. int result = PASS;
  7445. char message[256]={0};
  7446. DEBUG_INFO("sendUnknownConfirmation...\n");
  7447. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7448. LWS_Send(message);
  7449. return result;
  7450. }
  7451. //==========================================
  7452. // Handle server request routine Start
  7453. //==========================================
  7454. int handleCancelReservationRequest(char *uuid, char *payload)
  7455. {
  7456. mtrace();
  7457. int result = FAIL;
  7458. int gunNO = 0;
  7459. int reservationIdInt = -1;
  7460. char comfirmstr[20];
  7461. DEBUG_INFO("handleCancelReservationRequest...\n");
  7462. json_object *CancelReservation;
  7463. CancelReservation = json_tokener_parse(payload);
  7464. if(!is_error(CancelReservation))
  7465. {
  7466. // Required data
  7467. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7468. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7469. }
  7470. json_object_put(CancelReservation);
  7471. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7472. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7473. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7474. if(reservationIdInt != -1)
  7475. {
  7476. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7477. //check Transaction active
  7478. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7480. {
  7481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7482. {
  7483. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7484. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7485. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7486. {
  7487. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7488. }
  7489. else
  7490. {
  7491. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7492. }
  7493. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7494. goto end;
  7495. }
  7496. }
  7497. for (int index = 0; index < CCS_QUANTITY; index++)
  7498. {
  7499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7500. {
  7501. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7502. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7503. if(gunType[2] == GUN_TYPE_CCS)
  7504. {
  7505. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7506. }
  7507. else
  7508. {
  7509. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7510. }
  7511. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7512. goto end;
  7513. }
  7514. }
  7515. for (int index = 0; index < GB_QUANTITY; index++)
  7516. {
  7517. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7518. {
  7519. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7520. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7521. if(gunType[2] == GUN_TYPE_GBT)
  7522. {
  7523. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7524. }
  7525. else
  7526. {
  7527. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7528. }
  7529. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7530. goto end;
  7531. }
  7532. }
  7533. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7534. {
  7535. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7536. {
  7537. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7538. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7539. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7540. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7541. goto end;
  7542. }
  7543. }
  7544. for (int index = 0; index < AC_QUANTITY; index++)
  7545. {
  7546. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7547. {
  7548. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7549. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7550. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7551. {
  7552. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7553. }
  7554. else
  7555. {
  7556. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7557. }
  7558. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7559. goto end;
  7560. }
  7561. }
  7562. }
  7563. //The reservationId does NOT match the reservationId
  7564. sendCancelReservationConfirmation(uuid, comfirmstr);
  7565. end:
  7566. // Fill in ocpp packet uuid
  7567. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7568. return result;
  7569. }
  7570. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7571. {
  7572. mtrace();
  7573. int result = FAIL;
  7574. int gunIndex = -1;
  7575. char typeStr[16]={0};
  7576. char comfirmstr[20];
  7577. int specificId = FALSE;
  7578. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7579. json_object *ChangeAvailability;
  7580. ChangeAvailability = json_tokener_parse(payload);
  7581. if(!is_error(ChangeAvailability))
  7582. {
  7583. // Required data
  7584. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7585. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7586. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7587. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7588. }
  7589. json_object_put(ChangeAvailability);
  7590. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7591. {
  7592. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7593. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7594. }
  7595. else if(gunIndex == 0)
  7596. {
  7597. for(int i=0; i < gunTotalNumber; i++)
  7598. {
  7599. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7600. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7601. }
  7602. }
  7603. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7605. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7606. {
  7607. specificId = TRUE;
  7608. }
  7609. if(specificId == FALSE)
  7610. goto end;
  7611. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7612. {
  7613. //----------------------gunIndex is 0 ------------------------------------------------//
  7614. if(gunIndex == 0)
  7615. {
  7616. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7617. {
  7618. for(int i=0; i < gunTotalNumber; i++)
  7619. {
  7620. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7621. {
  7622. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7623. {
  7624. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7625. {
  7626. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7627. goto end;
  7628. }
  7629. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7630. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7631. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7632. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7633. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7634. {
  7635. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7636. goto end;
  7637. }
  7638. }
  7639. }//END FOR CHAdeMO_QUANTITY
  7640. for (int index = 0; index < CCS_QUANTITY; index++)
  7641. {
  7642. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7643. {
  7644. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7645. {
  7646. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7647. goto end;
  7648. }
  7649. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7650. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7651. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7652. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7653. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7654. {
  7655. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7656. goto end;
  7657. }
  7658. }
  7659. }//END FOR CCS_QUANTITY
  7660. for (int index = 0; index < GB_QUANTITY; index++)
  7661. {
  7662. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7663. {
  7664. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7665. {
  7666. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7667. goto end;
  7668. }
  7669. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7670. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7671. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7672. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7673. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7674. {
  7675. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7676. goto end;
  7677. }
  7678. }
  7679. }// END FOR GB_QUANTITY
  7680. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7681. {
  7682. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7683. {
  7684. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7685. {
  7686. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7687. goto end;
  7688. }
  7689. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7690. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7691. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7692. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7693. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7694. {
  7695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7696. goto end;
  7697. }
  7698. }
  7699. }// END FOR GENERAL_GUN_QUANTITY
  7700. for (int index = 0; index < AC_QUANTITY; index++)
  7701. {
  7702. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7703. {
  7704. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7705. {
  7706. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7707. goto end;
  7708. }
  7709. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7710. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7711. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7712. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7713. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7714. {
  7715. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7716. goto end;
  7717. }
  7718. }
  7719. }//END FOR AC_QUANTITY
  7720. }// END FOR gunTotalNumber
  7721. }
  7722. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7723. {
  7724. for(int i=0; i < gunTotalNumber; i++)
  7725. {
  7726. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7727. {
  7728. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7729. goto end;
  7730. }
  7731. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7732. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7733. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7734. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7735. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7736. {
  7737. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7738. goto end;
  7739. }
  7740. }
  7741. }
  7742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7743. goto end;
  7744. }
  7745. //----------------------gunIndex is not 0 ------------------------------------------------//
  7746. //check Transaction active
  7747. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7748. {
  7749. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7750. {
  7751. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7752. {
  7753. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7754. goto end;
  7755. }
  7756. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7757. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7758. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7759. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7760. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7761. {
  7762. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7763. goto end;
  7764. }
  7765. else
  7766. {
  7767. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7768. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7769. goto end;
  7770. }
  7771. }
  7772. }//END FOR CHAdeMO_QUANTITY
  7773. for (int index = 0; index < CCS_QUANTITY; index++)
  7774. {
  7775. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7776. {
  7777. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7778. {
  7779. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7780. goto end;
  7781. }
  7782. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7783. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7784. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7785. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7786. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7787. {
  7788. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7789. goto end;
  7790. }
  7791. else
  7792. {
  7793. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7794. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7795. goto end;
  7796. }
  7797. }
  7798. }//END FOR CCS_QUANTITY
  7799. for (int index = 0; index < GB_QUANTITY; index++)
  7800. {
  7801. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7802. {
  7803. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7804. {
  7805. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7806. goto end;
  7807. }
  7808. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7809. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7810. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7811. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7812. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7813. {
  7814. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7815. goto end;
  7816. }
  7817. else
  7818. {
  7819. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7820. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7821. goto end;
  7822. }
  7823. }
  7824. }// END FOR GB_QUANTITY
  7825. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7826. {
  7827. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7828. {
  7829. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7830. {
  7831. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7832. goto end;
  7833. }
  7834. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7835. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7836. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7837. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7838. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7839. {
  7840. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7841. goto end;
  7842. }
  7843. else
  7844. {
  7845. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7846. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7847. goto end;
  7848. }
  7849. }
  7850. }// END FOR GENERAL_GUN_QUANTITY
  7851. for (int index = 0; index < AC_QUANTITY; index++)
  7852. {
  7853. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7854. {
  7855. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7856. {
  7857. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7858. goto end;
  7859. }
  7860. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7861. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7862. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7863. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7864. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7865. {
  7866. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7867. goto end;
  7868. }
  7869. else
  7870. {
  7871. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7872. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7873. goto end;
  7874. }
  7875. }
  7876. }//END FOR AC_QUANTITY
  7877. }//END FOR AvailabilityTypeStr[Inoperative]
  7878. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7879. {
  7880. //----------------------gunIndex is 0 ------------------------------------------------//
  7881. if(gunIndex == 0)
  7882. {
  7883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7884. {
  7885. for(int i=0; i < gunTotalNumber; i++)
  7886. {
  7887. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7888. {
  7889. 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
  7890. {
  7891. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7892. goto end;
  7893. }
  7894. }//END FOR CHAdeMO_QUANTITY
  7895. for (int index = 0; index < CCS_QUANTITY; index++)
  7896. {
  7897. 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
  7898. {
  7899. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7900. goto end;
  7901. }
  7902. }//END FOR CCS_QUANTITY
  7903. for (int index = 0; index < GB_QUANTITY; index++)
  7904. {
  7905. 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
  7906. {
  7907. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7908. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7909. goto end;
  7910. }
  7911. }// END FOR GB_QUANTITY
  7912. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7913. {
  7914. 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
  7915. {
  7916. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7917. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7918. goto end;
  7919. }
  7920. }// END FOR GENERAL_GUN_QUANTITY
  7921. for (int index = 0; index < AC_QUANTITY; index++)
  7922. {
  7923. 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
  7924. {
  7925. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7926. goto end;
  7927. }
  7928. }//END FOR CHAdeMO_QUANTITY
  7929. }// END FOR gunTotalNumber
  7930. }
  7931. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7932. {
  7933. for(int i=0; i < gunTotalNumber; i++)
  7934. {
  7935. for (int index = 0; index < AC_QUANTITY; index++)
  7936. {
  7937. 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
  7938. {
  7939. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7940. goto end;
  7941. }
  7942. }//END FOR CHAdeMO_QUANTITY
  7943. } // END FOR gunTotalNumber
  7944. }
  7945. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7946. goto end;
  7947. }
  7948. //----------------------gunIndex is not 0 ------------------------------------------------//
  7949. //check Transaction active
  7950. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7951. {
  7952. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7953. {
  7954. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7955. goto end;
  7956. }
  7957. }//END FOR CHAdeMO_QUANTITY
  7958. for (int index = 0; index < CCS_QUANTITY; index++)
  7959. {
  7960. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7961. {
  7962. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7963. goto end;
  7964. }
  7965. }//END FOR CCS_QUANTITY
  7966. for (int index = 0; index < GB_QUANTITY; index++)
  7967. {
  7968. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7969. {
  7970. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7971. goto end;
  7972. }
  7973. }// END FOR GB_QUANTITY
  7974. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7975. {
  7976. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7977. {
  7978. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7979. goto end;
  7980. }
  7981. }// END FOR GENERAL_GUN_QUANTITY
  7982. for (int index = 0; index < AC_QUANTITY; index++)
  7983. {
  7984. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7985. {
  7986. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7987. goto end;
  7988. }
  7989. }//END FOR AC_QUANTITY
  7990. }//END FOR AvailabilityTypeStr[Operative]
  7991. end:
  7992. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7993. {
  7994. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7995. }
  7996. else
  7997. {
  7998. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7999. }
  8000. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8001. {
  8002. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8003. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8004. }
  8005. else if(gunIndex == 0)
  8006. {
  8007. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8008. {
  8009. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8010. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8011. }
  8012. }
  8013. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8014. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8015. return result;
  8016. }
  8017. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8018. {
  8019. mtrace();
  8020. int valueInvalid = NO;
  8021. int result = FAIL;
  8022. char keystr[40]={0};
  8023. char valuestr[501]={0}; //value should be limited in 500 bytes
  8024. char comfirmstr[20]={0};
  8025. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8026. json_object *ChangeConfiguration;
  8027. ChangeConfiguration = json_tokener_parse(payload);
  8028. if(!is_error(ChangeConfiguration))
  8029. {
  8030. // Required data
  8031. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8032. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8033. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8034. {
  8035. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8036. }
  8037. else
  8038. {
  8039. valueInvalid = YES;
  8040. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8041. }
  8042. }
  8043. json_object_put(ChangeConfiguration);
  8044. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8045. {
  8046. DEBUG_ERROR("Payload is null or not accepted.\n");
  8047. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8048. }
  8049. else
  8050. {
  8051. int status = setKeyValue(keystr, valuestr);
  8052. switch(status)
  8053. {
  8054. case ConfigurationStatus_Accepted:
  8055. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8056. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8057. StoreConfigurationTable();
  8058. break;
  8059. case RebootRequired:
  8060. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8061. StoreConfigurationTable();
  8062. break;
  8063. case NotSupported:
  8064. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8065. break;
  8066. case ConfigurationStatus_Rejected:
  8067. default:
  8068. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8069. break;
  8070. }
  8071. }
  8072. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8073. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8074. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8075. {
  8076. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8077. SetOcppConnStatus(FALSE);
  8078. }
  8079. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8080. {
  8081. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8082. }
  8083. return result;
  8084. }
  8085. int handleClearCacheRequest(char *uuid, char *payload)
  8086. {
  8087. mtrace();
  8088. int result = FAIL;
  8089. char comfirmstr[20];
  8090. char rmFileCmd[100]={0};
  8091. struct stat stats;
  8092. DEBUG_INFO("handleClearCacheRequest...\n");
  8093. stat("/Storage/OCPP_PH", &stats);
  8094. // Check for directory existence
  8095. if (S_ISDIR(stats.st_mode) == 1)
  8096. {}
  8097. else
  8098. {
  8099. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8100. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8101. system(rmFileCmd);
  8102. }
  8103. if(OCPP_cleanLocalCache())
  8104. {
  8105. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8106. }
  8107. else
  8108. {
  8109. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8110. }
  8111. sendClearCacheConfirmation(uuid, comfirmstr);
  8112. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8113. return result;
  8114. }
  8115. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8116. {
  8117. mtrace();
  8118. int result = FAIL;
  8119. int resultRename;
  8120. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8121. char chargingProfilePurposeStr[26]={0};
  8122. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8123. char tempchargingProfilePurposeStr[26]={0};
  8124. char str[100]={0};
  8125. char fname[200]={0};
  8126. char comfirmstr[20]={0};
  8127. char word[1600]={0};
  8128. int clearflag = FALSE;
  8129. int chargingProfileIdIsNULL = FALSE;
  8130. int connectorIsNULL = FALSE;
  8131. int chargingProfilePurposeIsNULL = FALSE;
  8132. int stackLevelIsNULL = FALSE;
  8133. //int GotoEnd = FALSE;
  8134. FILE *fptr1, *fptr2;
  8135. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8136. int n_chargingProfile=0;
  8137. int isEmptyFile = FALSE;
  8138. char sLineWord[1600]={0};
  8139. char chargingProfiles[10][100]={0};
  8140. int ChargeProfileCount = 0;
  8141. int ch;
  8142. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8143. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8144. json_object *ClearChargingProfile;
  8145. ClearChargingProfile = json_tokener_parse(payload);
  8146. if(!is_error(ClearChargingProfile))
  8147. {
  8148. // Optional data
  8149. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8150. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8151. else
  8152. chargingProfileIdIsNULL = TRUE;
  8153. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8154. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8155. else
  8156. connectorIsNULL = TRUE;
  8157. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8158. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8159. else
  8160. chargingProfilePurposeIsNULL = TRUE;
  8161. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8162. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8163. else
  8164. stackLevelIsNULL = TRUE;
  8165. }
  8166. json_object_put(ClearChargingProfile);
  8167. if(connectorIsNULL == FALSE)
  8168. {
  8169. switch(connectorIdInt)
  8170. {
  8171. case 0:
  8172. if(chargingProfilePurposeIsNULL == TRUE)
  8173. {
  8174. int l = 0;
  8175. strcpy(fname, ChargePointMaxProfile_JSON);
  8176. if((access(fname,F_OK))!=-1)
  8177. {
  8178. strcpy(chargingProfiles[l], fname);
  8179. l = l + 1;
  8180. }
  8181. strcpy(fname, TxDefaultProfile_0_JSON);
  8182. if((access(fname,F_OK))!=-1)
  8183. {
  8184. strcpy(chargingProfiles[l], fname);
  8185. l = l + 1;
  8186. }
  8187. ChargeProfileCount = l;
  8188. }
  8189. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8190. {
  8191. strcpy(fname, ChargePointMaxProfile_JSON);
  8192. if((access(fname,F_OK))!=-1)
  8193. {
  8194. strcpy(chargingProfiles[0], fname);
  8195. ChargeProfileCount = 1;
  8196. }
  8197. }
  8198. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8199. {
  8200. strcpy(fname, TxDefaultProfile_0_JSON);
  8201. if((access(fname,F_OK))!=-1)
  8202. {
  8203. strcpy(chargingProfiles[0], fname);
  8204. ChargeProfileCount = 1;
  8205. }
  8206. }
  8207. break;
  8208. default:
  8209. if(chargingProfilePurposeIsNULL == TRUE)
  8210. {
  8211. int m = 0;
  8212. memset(fname, 0, ARRAY_SIZE(fname));
  8213. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8214. if((access(fname,F_OK))!=-1)
  8215. {
  8216. strcpy(chargingProfiles[m], fname);
  8217. m = m + 1;
  8218. }
  8219. memset(fname, 0, ARRAY_SIZE(fname));
  8220. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8221. if((access(fname,F_OK))!=-1)
  8222. {
  8223. strcpy(chargingProfiles[m], fname);
  8224. m = m + 1;
  8225. }
  8226. ChargeProfileCount = m;
  8227. }
  8228. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8229. {
  8230. //strcpy(fname, TxDefaultProfile_1_JSON);
  8231. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8232. if((access(fname,F_OK))!=-1)
  8233. {
  8234. strcpy(chargingProfiles[0], fname);
  8235. ChargeProfileCount = 1;
  8236. }
  8237. }
  8238. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8239. {
  8240. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8241. if((access(fname,F_OK))!=-1)
  8242. {
  8243. strcpy(chargingProfiles[0], fname);
  8244. ChargeProfileCount = 1;
  8245. }
  8246. //strcpy(fname, TxProfile_1_JSON);
  8247. }
  8248. //strcpy(fname, ChargePointMaxProfile_JSON );
  8249. break;
  8250. }
  8251. }
  8252. else // Check all Charging Profiles
  8253. {
  8254. int i = 0;
  8255. char fnametemp[200]={0};
  8256. ChargeProfileCount = 0;
  8257. //Check ChargePointMaxProfile.json exit
  8258. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8259. {
  8260. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8261. i = i + 1;
  8262. }
  8263. //Check TxDefaultProfile_0.json exit
  8264. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8265. {
  8266. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8267. i = i + 1;
  8268. }
  8269. //Check TxDefaultProfile_%d.json
  8270. for(int j=1; j <= gunTotalNumber; j++)
  8271. {
  8272. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8273. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8274. if((access(fnametemp,F_OK))!=-1)
  8275. {
  8276. strcpy(chargingProfiles[i], fnametemp);
  8277. i = i + 1;
  8278. }
  8279. }
  8280. //Check TxProfile_%d.json
  8281. for(int j=1; j <= gunTotalNumber; j++)
  8282. {
  8283. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8284. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8285. if((access(fnametemp,F_OK))!=-1)
  8286. {
  8287. strcpy(chargingProfiles[i], fnametemp);
  8288. i = i + 1;
  8289. }
  8290. }
  8291. ChargeProfileCount = i;
  8292. }// End connectorIsNULL is TRUE
  8293. if(ChargeProfileCount == 0)
  8294. {
  8295. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8296. goto end;
  8297. }
  8298. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8299. {
  8300. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8301. goto end;
  8302. }
  8303. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8304. {
  8305. memset(str, 0, ARRAY_SIZE(str));
  8306. // clear temp file
  8307. sprintf(str,"rm -f %s",temp);
  8308. system(str);
  8309. for(int k=0; k < ChargeProfileCount; k++)
  8310. {
  8311. memset(str, 0, ARRAY_SIZE(str));
  8312. //clear file in C
  8313. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8314. system(str);
  8315. }
  8316. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8317. goto end;
  8318. }
  8319. else if(connectorIsNULL == TRUE)
  8320. {
  8321. for(int k=0; k < ChargeProfileCount; k++)
  8322. {
  8323. fptr1 = fopen(chargingProfiles[k], "r");
  8324. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8325. //Check Charging Profile Count
  8326. while(fscanf(fptr1, "%s", word) != EOF)
  8327. {
  8328. //DEBUG_INFO("word=%s\n",word);
  8329. if(strstr(word, "chargingProfileId")!= NULL)
  8330. {
  8331. //DEBUG_INFO("test chargingProfileId \n");
  8332. n_chargingProfile = n_chargingProfile + 1;
  8333. //DEBUG_INFO("chargingProfileId Found\n");
  8334. }
  8335. }
  8336. rewind(fptr1);
  8337. //search Charging Profile Element
  8338. //int i= 0;
  8339. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8340. {
  8341. json_object *tmpProfilee;
  8342. tmpProfilee = json_tokener_parse(sLineWord);
  8343. if(!is_error(tmpProfilee))
  8344. {
  8345. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8346. {
  8347. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8348. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8349. }
  8350. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8351. {
  8352. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8353. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8354. }
  8355. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8356. {
  8357. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8358. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8359. }
  8360. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8361. {
  8362. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8363. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8364. }
  8365. }
  8366. json_object_put(tmpProfilee);
  8367. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8368. {
  8369. //------- not write to fptr2-------//
  8370. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8371. //clearflag = TRUE;
  8372. }
  8373. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8374. {
  8375. //------- not write to fptr2-------//
  8376. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8377. }
  8378. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8379. {
  8380. //------- not write to fptr2-------//
  8381. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8382. }
  8383. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8384. {
  8385. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8386. }
  8387. else
  8388. {
  8389. fprintf(fptr2, sLineWord);//writing data into file
  8390. }
  8391. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8392. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8393. if(clearflag == TRUE)
  8394. {
  8395. fclose(fptr1);
  8396. fclose(fptr2);
  8397. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8398. system(str);
  8399. // clear temp file
  8400. sprintf(str,"rm -f %s",temp);
  8401. system(str);
  8402. }
  8403. else
  8404. {
  8405. fclose(fptr1);
  8406. fclose(fptr2);
  8407. memset(str, 0, ARRAY_SIZE(str));
  8408. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8409. system(str);
  8410. resultRename = rename(temp, chargingProfiles[k]);
  8411. if(resultRename == 0)
  8412. {
  8413. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8414. }
  8415. else
  8416. {
  8417. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8418. }
  8419. if(comfirmstr[0]== 0)
  8420. {
  8421. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8422. }
  8423. //Check chargingProfile is empty file
  8424. /*------ Read the file ----------------*/
  8425. fptr1=fopen(chargingProfiles[k],"r");
  8426. ch=fgetc(fptr1);
  8427. rewind(fptr1);
  8428. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8429. if(ch!=EOF)
  8430. {
  8431. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8432. {
  8433. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8434. if(sLineWord[0]=='\0')
  8435. {
  8436. isEmptyFile = TRUE;
  8437. break;
  8438. }
  8439. else
  8440. {
  8441. isEmptyFile = FALSE;
  8442. break;
  8443. }
  8444. }
  8445. }
  8446. else
  8447. isEmptyFile = TRUE;
  8448. fclose(fptr1);
  8449. if(isEmptyFile == TRUE)
  8450. {
  8451. memset(str, 0, ARRAY_SIZE(str));
  8452. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8453. system(str);
  8454. }
  8455. }
  8456. }// End of while(int k=0; k < ChargePointCount; k++)
  8457. }
  8458. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8459. {
  8460. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8461. for(int k=0; k < ChargeProfileCount; k++)
  8462. {
  8463. fptr1 = fopen(chargingProfiles[k], "r");
  8464. fptr2 = fopen(temp, "w+");
  8465. //Check Charging Profile Count
  8466. while(fscanf(fptr1, "%s", word) != EOF)
  8467. {
  8468. //DEBUG_INFO("word=%s\n",word);
  8469. if(strstr(word, "chargingProfileId")!= NULL)
  8470. {
  8471. n_chargingProfile = n_chargingProfile + 1;
  8472. }
  8473. }
  8474. rewind(fptr1);
  8475. //search Charging Profile Element
  8476. //int i= 0;
  8477. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8478. {
  8479. json_object *tmpProfilee;
  8480. tmpProfilee = json_tokener_parse(sLineWord);
  8481. if(!is_error(tmpProfilee))
  8482. {
  8483. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8484. {
  8485. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8486. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8487. }
  8488. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8489. {
  8490. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8491. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8492. }
  8493. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8494. {
  8495. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8496. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8497. }
  8498. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8499. {
  8500. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8501. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8502. }
  8503. }
  8504. json_object_put(tmpProfilee);
  8505. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8506. {
  8507. //------- not write to fptr2-------//
  8508. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8509. //clearflag = TRUE;
  8510. }
  8511. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8512. {
  8513. //------- not write to fptr2-------//
  8514. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8515. }
  8516. else if(stackLevelIsNULL == TRUE)
  8517. {
  8518. //Clear Whole File
  8519. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8520. clearflag = TRUE;
  8521. break;
  8522. }
  8523. else
  8524. {
  8525. fprintf(fptr2, sLineWord);//writing data into file
  8526. }
  8527. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8528. }
  8529. if(clearflag == TRUE)
  8530. {
  8531. fclose(fptr1);
  8532. fclose(fptr2);
  8533. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8534. system(str);
  8535. // clear temp file
  8536. sprintf(str,"rm -f %s",temp);
  8537. system(str);
  8538. }
  8539. else
  8540. {
  8541. fclose(fptr1);
  8542. fclose(fptr2);
  8543. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8544. system(str);
  8545. resultRename = rename(temp, chargingProfiles[k]);
  8546. if(resultRename == 0)
  8547. {
  8548. DEBUG_INFO("File ChargingProfile renamed successfully");
  8549. }
  8550. else
  8551. {
  8552. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8553. }
  8554. if(comfirmstr[0]== 0)
  8555. {
  8556. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8557. }
  8558. //Check chargingProfile is empty file
  8559. /*------ Read the file ----------------*/
  8560. fptr1=fopen(chargingProfiles[k],"r");
  8561. ch=fgetc(fptr1);
  8562. rewind(fptr1);
  8563. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8564. if(ch!=EOF)
  8565. {
  8566. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8567. {
  8568. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8569. if(sLineWord[0]=='\0')
  8570. {
  8571. isEmptyFile = TRUE;
  8572. break;
  8573. }
  8574. else
  8575. {
  8576. isEmptyFile = FALSE;
  8577. break;
  8578. }
  8579. }
  8580. }
  8581. else
  8582. isEmptyFile = TRUE;
  8583. fclose(fptr1);
  8584. if(isEmptyFile == TRUE)
  8585. {
  8586. memset(str, 0, ARRAY_SIZE(str));
  8587. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8588. system(str);
  8589. }
  8590. /*------- End of reading ---------------*/
  8591. }
  8592. } // while(int k=0; k < ChargeProfileCount; k++)
  8593. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8594. end:
  8595. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8596. {
  8597. if(connectorIdInt == 0)
  8598. {
  8599. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8600. {
  8601. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8602. }
  8603. }
  8604. else
  8605. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8606. }
  8607. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8608. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8609. return result;
  8610. }
  8611. void createFirmwareVersionByDataTransfer(void)
  8612. {
  8613. json_object *FirmwareDataTransfer = json_object_new_object();
  8614. // AC & DC model
  8615. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8616. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8617. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8618. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8619. // DC model
  8620. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8621. {
  8622. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8623. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8624. (gunType[3] != GUN_TYPE_UNKNOWN))
  8625. {
  8626. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8627. }
  8628. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8629. {
  8630. // DS DM DW
  8631. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8632. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8633. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8634. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8635. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8636. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8637. }
  8638. else
  8639. {
  8640. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8641. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8642. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8643. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8644. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8645. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8646. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8647. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8648. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8649. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8650. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8651. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8652. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8653. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8654. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8655. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8656. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8657. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8658. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8659. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8660. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8661. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8662. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8663. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8664. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8665. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8666. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8667. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8668. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8669. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8670. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8671. }
  8672. }
  8673. // 4G model
  8674. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8675. {
  8676. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8677. }
  8678. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8679. json_object_put(FirmwareDataTransfer);
  8680. }
  8681. int handleDataTransferRequest(char *uuid, char *payload)
  8682. {
  8683. mtrace();
  8684. json_object *response = json_object_new_object();
  8685. int result = FAIL;
  8686. char tempvendorId[255]={0};
  8687. char tempmessageId[50]={0};
  8688. char tempdata[512]={0};
  8689. char message[2048]={0};
  8690. DEBUG_INFO("handleDataTransferRequest...\n");
  8691. if((uuid != NULL) && (payload != NULL))
  8692. {
  8693. json_object *DataTransfer;
  8694. DataTransfer = json_tokener_parse(payload);
  8695. if(!is_error(DataTransfer))
  8696. {
  8697. // Required data
  8698. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8699. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8700. // Optional data
  8701. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8702. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8703. if(json_object_object_get(DataTransfer, "data") != NULL)
  8704. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8705. result = PASS;
  8706. }
  8707. json_object_put(DataTransfer);
  8708. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8709. {
  8710. // Send all moudle firmware version on EVSE
  8711. createFirmwareVersionByDataTransfer();
  8712. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8713. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8714. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8715. json_object_put(response);
  8716. }
  8717. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8718. {
  8719. system("/usr/bin/run_tmate_restart.sh &");
  8720. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8721. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8722. json_object_put(response);
  8723. }
  8724. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8725. {
  8726. json_object *data;
  8727. data = json_tokener_parse(tempdata);
  8728. if(!is_error(data))
  8729. {
  8730. 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))
  8731. {
  8732. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8733. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8734. if(json_object_object_get(data, "SOC") != NULL)
  8735. {
  8736. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8737. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8738. }
  8739. if(json_object_object_get(data, "Energy") != NULL)
  8740. {
  8741. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8742. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8743. }
  8744. if(json_object_object_get(data, "Duration") != NULL)
  8745. {
  8746. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8747. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8748. }
  8749. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8750. }
  8751. else
  8752. {
  8753. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8754. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8755. }
  8756. }
  8757. else
  8758. {
  8759. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8760. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8761. }
  8762. json_object_put(data);
  8763. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8764. json_object_put(response);
  8765. }
  8766. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8767. {
  8768. json_object *data;
  8769. data = json_tokener_parse(tempdata);
  8770. if(!is_error(data))
  8771. {
  8772. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8773. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8774. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8775. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8776. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8777. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8778. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8779. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8780. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8781. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8782. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8783. }
  8784. else
  8785. {
  8786. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8787. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8788. }
  8789. json_object_put(data);
  8790. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8791. json_object_put(response);
  8792. }
  8793. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8794. {
  8795. json_object *data;
  8796. data = json_tokener_parse(tempdata);
  8797. if(!is_error(data))
  8798. {
  8799. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8800. if(json_object_object_get(data, "idToken") != NULL)
  8801. {
  8802. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8803. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8804. }
  8805. if(json_object_object_get(data, "price") != NULL)
  8806. {
  8807. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8808. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8809. }
  8810. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8811. }
  8812. else
  8813. {
  8814. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8815. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8816. }
  8817. json_object_put(data);
  8818. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8819. json_object_put(response);
  8820. }
  8821. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8822. {
  8823. json_object *data;
  8824. data = json_tokener_parse(tempdata);
  8825. if(!is_error(data))
  8826. {
  8827. if(json_object_object_get(data, "txId") != NULL)
  8828. {
  8829. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8830. for(int idx = 0;idx<gunTotalNumber;idx++)
  8831. {
  8832. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8833. {
  8834. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8835. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8836. if(json_object_object_get(data, "description") != NULL)
  8837. {
  8838. // California pricing V1.0
  8839. DEBUG_INFO("California pricing V1.0\n");
  8840. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8841. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8842. }
  8843. else
  8844. {
  8845. // California pricing V1.1
  8846. DEBUG_INFO("California pricing V1.1\n");
  8847. if(json_object_object_get(data, "timestamp") != NULL)
  8848. {
  8849. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8850. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8851. }
  8852. if(json_object_object_get(data, "meterValue") != NULL)
  8853. {
  8854. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8855. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8856. }
  8857. if(json_object_object_get(data, "cost") != NULL)
  8858. {
  8859. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8860. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8861. }
  8862. if(json_object_object_get(data, "state") != NULL)
  8863. {
  8864. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8865. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8866. }
  8867. if(json_object_object_get(data, "chargingPrice") != NULL)
  8868. {
  8869. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8870. {
  8871. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8872. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8873. }
  8874. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8875. {
  8876. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8877. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8878. }
  8879. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8880. {
  8881. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8882. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8883. }
  8884. }
  8885. if(json_object_object_get(data, "idlePrice") != NULL)
  8886. {
  8887. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8888. {
  8889. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8890. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8891. }
  8892. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8893. {
  8894. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8895. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8896. }
  8897. }
  8898. if(json_object_object_get(data, "nextPeriod") != NULL)
  8899. {
  8900. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8901. {
  8902. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8903. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8904. }
  8905. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8906. {
  8907. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8908. {
  8909. 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")));
  8910. 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"));
  8911. }
  8912. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8913. {
  8914. 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")));
  8915. 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"));
  8916. }
  8917. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8918. {
  8919. 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")));
  8920. 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"));
  8921. }
  8922. }
  8923. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8924. {
  8925. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8926. {
  8927. 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")));
  8928. 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"));
  8929. }
  8930. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8931. {
  8932. 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")));
  8933. 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"));
  8934. }
  8935. }
  8936. }
  8937. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8938. {
  8939. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8940. {
  8941. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8942. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8943. }
  8944. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8945. {
  8946. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8947. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8948. }
  8949. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8950. {
  8951. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8952. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8953. }
  8954. }
  8955. }
  8956. }
  8957. }
  8958. }
  8959. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8960. }
  8961. else
  8962. {
  8963. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8964. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8965. }
  8966. json_object_put(data);
  8967. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8968. json_object_put(response);
  8969. }
  8970. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8971. {
  8972. json_object *data;
  8973. data = json_tokener_parse(tempdata);
  8974. if(!is_error(data))
  8975. {
  8976. if(json_object_object_get(data, "txId") != NULL)
  8977. {
  8978. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8979. for(int idx = 0;idx<gunTotalNumber;idx++)
  8980. {
  8981. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8982. {
  8983. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8984. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8985. if(json_object_object_get(data, "description") != NULL)
  8986. {
  8987. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8988. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8989. }
  8990. }
  8991. }
  8992. }
  8993. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8994. }
  8995. else
  8996. {
  8997. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8998. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8999. }
  9000. json_object_put(data);
  9001. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9002. json_object_put(response);
  9003. }
  9004. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9005. {
  9006. json_object *data;
  9007. data = json_tokener_parse(tempdata);
  9008. if(!is_error(data))
  9009. {
  9010. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9011. if(json_object_object_get(data, "Content_Type") != NULL)
  9012. {
  9013. 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))
  9014. {
  9015. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9016. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9017. {
  9018. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9019. }
  9020. }
  9021. else
  9022. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9023. }
  9024. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9025. }
  9026. else
  9027. {
  9028. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9029. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9030. }
  9031. json_object_put(data);
  9032. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9033. json_object_put(response);
  9034. }
  9035. else if(strstr(tempmessageId, "ID_DisplayLcdPage") != NULL)
  9036. {
  9037. json_object *data;
  9038. data = json_tokener_parse(tempdata);
  9039. if(!is_error(data))
  9040. {
  9041. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9042. if(json_object_object_get(data, "ConnectorId") != NULL)
  9043. {
  9044. ShmSysConfigAndInfo->SysConfig.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9045. }
  9046. if(json_object_object_get(data, "Page_Index") != NULL)
  9047. {
  9048. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9049. }
  9050. if(json_object_object_get(data, "Duration") != NULL)
  9051. {
  9052. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9053. }
  9054. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9055. }
  9056. else
  9057. {
  9058. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9059. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9060. }
  9061. json_object_put(data);
  9062. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9063. json_object_put(response);
  9064. }
  9065. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9066. {
  9067. json_object *data;
  9068. data = json_tokener_parse(tempdata);
  9069. if(!is_error(data))
  9070. {
  9071. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9072. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9073. {
  9074. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9075. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9076. else
  9077. {
  9078. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9079. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9080. }
  9081. }
  9082. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9083. {
  9084. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9085. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9086. else
  9087. {
  9088. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9089. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9090. }
  9091. }
  9092. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9093. {
  9094. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9095. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9096. else
  9097. {
  9098. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9099. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9100. }
  9101. }
  9102. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9103. {
  9104. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9105. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9106. else
  9107. {
  9108. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9109. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9110. }
  9111. }
  9112. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9113. {
  9114. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9115. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9116. else
  9117. {
  9118. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9119. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9120. }
  9121. }
  9122. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9123. {
  9124. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9125. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9126. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9127. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9128. else
  9129. {
  9130. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9131. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9132. }
  9133. }
  9134. if(json_object_object_get(data, "isAuthentication") != NULL)
  9135. {
  9136. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9137. {
  9138. case 0:
  9139. case 1:
  9140. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9141. break;
  9142. default:
  9143. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9144. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9145. break;
  9146. }
  9147. }
  9148. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9149. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9150. }
  9151. else
  9152. {
  9153. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9154. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9155. }
  9156. json_object_put(data);
  9157. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9158. json_object_put(response);
  9159. }
  9160. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9161. {
  9162. json_object *data;
  9163. data = json_tokener_parse(tempdata);
  9164. if(!is_error(data))
  9165. {
  9166. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9167. if(json_object_object_get(data, "stationName") != NULL)
  9168. {
  9169. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9170. }
  9171. else
  9172. {
  9173. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9174. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9175. }
  9176. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9177. {
  9178. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9179. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9180. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9181. }
  9182. }
  9183. else
  9184. {
  9185. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9186. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9187. }
  9188. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9189. json_object_put(response);
  9190. }
  9191. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9192. {
  9193. json_object *data;
  9194. data = json_tokener_parse(tempdata);
  9195. if(!is_error(data))
  9196. {
  9197. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9198. if(json_object_object_get(data, "weatherId") != NULL)
  9199. {
  9200. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9201. }
  9202. else
  9203. {
  9204. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9205. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9206. }
  9207. if(json_object_object_get(data, "Temperature") != NULL)
  9208. {
  9209. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  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("temperature data can not get."));
  9215. }
  9216. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9217. {
  9218. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9219. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9220. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9221. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9222. }
  9223. }
  9224. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9225. {
  9226. json_object *data;
  9227. data = json_tokener_parse(tempdata);
  9228. if(!is_error(data))
  9229. {
  9230. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9231. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9232. {
  9233. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9234. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9235. }
  9236. else
  9237. {
  9238. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9239. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9240. }
  9241. }
  9242. else
  9243. {
  9244. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9245. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9246. }
  9247. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9248. json_object_put(response);
  9249. }
  9250. else
  9251. {
  9252. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9253. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9254. }
  9255. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9256. json_object_put(response);
  9257. }
  9258. else
  9259. {
  9260. // Can not find valid message id
  9261. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9262. }
  9263. }
  9264. else
  9265. {
  9266. // Payload is null
  9267. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9268. }
  9269. LWS_Send(message);
  9270. return result;
  9271. }
  9272. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9273. {
  9274. mtrace();
  9275. int result = FAIL;
  9276. int connectorIdInt, durationInt;
  9277. char chargingRateUnitStr[4]={0};
  9278. char comfirmstr[20];
  9279. int confirmPeriods = 0;
  9280. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9281. json_object *GetCompositeSchedule;
  9282. GetCompositeSchedule = json_tokener_parse(payload);
  9283. if(!is_error(GetCompositeSchedule))
  9284. {
  9285. // Required data
  9286. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9287. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9288. else
  9289. connectorIdInt = -1;
  9290. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9291. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9292. else
  9293. durationInt = 86400;
  9294. // Optional data
  9295. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9296. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9297. }
  9298. json_object_put(GetCompositeSchedule);
  9299. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9300. if((connectorIdInt == 0) ||
  9301. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9302. {
  9303. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9304. struct StructChargingProfile tmpProfile[1];
  9305. if(strstr(chargingRateUnitStr, "W") != NULL)
  9306. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9307. else
  9308. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9309. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9310. {
  9311. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9312. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9313. }
  9314. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9315. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9316. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9317. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9318. {
  9319. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9320. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9321. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9322. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9323. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9324. {
  9325. confirmPeriods = idx;
  9326. break;
  9327. }
  9328. }
  9329. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9330. {
  9331. confirmPeriods += 1;
  9332. }
  9333. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9334. }
  9335. else
  9336. {
  9337. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9338. }
  9339. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9340. return result;
  9341. }
  9342. int handleGetConfigurationRequest(char *uuid, char *payload)
  9343. {
  9344. mtrace();
  9345. int result = FAIL;
  9346. int MaxKeySupported = 0;
  9347. int n_keys = 0;
  9348. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9349. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9350. json_object *GetConfiguration;
  9351. GetConfiguration = json_tokener_parse(payload);
  9352. if(!is_error(GetConfiguration))
  9353. {
  9354. // Optional data
  9355. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9356. {
  9357. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9358. {
  9359. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9360. n_keys = idx + 1;
  9361. }
  9362. }
  9363. }
  9364. json_object_put(GetConfiguration);
  9365. UnknownKeynum = 0;
  9366. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9367. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9368. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9369. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9370. if(n_keys != 0)
  9371. {
  9372. for(int i=0;i<n_keys;i++)
  9373. {
  9374. getKeyValue(requestKey[i]);
  9375. }
  9376. }
  9377. else
  9378. {
  9379. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9380. getKeyValue("");
  9381. }
  9382. processUnkownKey();
  9383. sendGetConfigurationConfirmation(uuid);
  9384. return result;
  9385. }
  9386. static char fnamePlusPath[100]={0};
  9387. static char fnamePWithNoPath[60]={0};
  9388. void checkUploadLog(void)
  9389. {
  9390. FILE *fp;
  9391. /* Open the command for reading. */
  9392. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9393. if (fp == NULL) {
  9394. DEBUG_WARN("Failed to run command\n" );
  9395. exit(1);
  9396. }
  9397. int ftppathlen = 0;
  9398. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9399. int i = 0;
  9400. /* Read the output a line at a time - output it. */
  9401. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9402. if(i==0)
  9403. {
  9404. ftppathlen = strlen(fnamePlusPath);
  9405. DEBUG_INFO("%s\n", fnamePlusPath);
  9406. fnamePlusPath[ftppathlen]='\0';
  9407. break;
  9408. }
  9409. i= i+1;
  9410. }
  9411. /* close */
  9412. pclose(fp);
  9413. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9414. {
  9415. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9416. {
  9417. fnamePlusPath[k]='\0';
  9418. }
  9419. }
  9420. i=1;
  9421. //char fname[60]={0};
  9422. while(i < ftppathlen)
  9423. {
  9424. int len=ftppathlen-i;
  9425. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9426. {
  9427. DEBUG_INFO("compare '/' all right\n");
  9428. break;
  9429. }
  9430. i=i+1;
  9431. }
  9432. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9433. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9434. fnamePWithNoPath[i+1] = '\0';
  9435. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9436. {
  9437. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9438. {
  9439. fnamePWithNoPath[j]='\0';
  9440. }
  9441. }
  9442. FILE* fp1 = fopen(fnamePlusPath, "r");
  9443. if (fp1)
  9444. {
  9445. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9446. // file exists
  9447. fclose(fp1);
  9448. }
  9449. else
  9450. {
  9451. // file doesn't exist
  9452. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9453. }
  9454. }
  9455. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9456. {
  9457. mtrace();
  9458. int result = FAIL;
  9459. time_t CurrentTime;
  9460. struct tm *tm;
  9461. pthread_t th_Status;
  9462. CurrentTime = time(NULL);
  9463. tm = localtime(&CurrentTime);
  9464. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9465. 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);
  9466. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9467. if(!interLock.isGetDiagnosticGoing)
  9468. {
  9469. interLock.isGetDiagnosticGoing = 1;
  9470. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9471. sleep(1);
  9472. }
  9473. else
  9474. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9475. return result;
  9476. }
  9477. void* GetDiagnosticsProcess(void* data)
  9478. {
  9479. pthread_detach(pthread_self());
  9480. mtrace();
  9481. int retriesInt=0, retryIntervalInt=0;
  9482. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9483. 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};
  9484. int port=0;
  9485. int isSuccess = FALSE;
  9486. char ftpbuf[200]={0};
  9487. char cmdBuf[2048];
  9488. struct tm *tmNow;
  9489. time_t CurrentTime;
  9490. struct tm tmStart;
  9491. struct tm tmStop;
  9492. CurrentTime = time(NULL);
  9493. tmNow=localtime(&CurrentTime);
  9494. uint16_t targetYear, targetMonth;
  9495. json_object *GetDiagnostics;
  9496. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9497. GetDiagnostics = json_tokener_parse(data);
  9498. if(!is_error(GetDiagnostics))
  9499. {
  9500. // Required data
  9501. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9502. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9503. // Optional data
  9504. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9505. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9506. else
  9507. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9508. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9509. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9510. else
  9511. retryIntervalInt = 30;
  9512. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9513. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9514. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9515. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9516. }
  9517. json_object_put(GetDiagnostics);
  9518. // Pack log to compress file
  9519. 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) &&
  9520. (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))
  9521. {
  9522. // Pack system log
  9523. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9524. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9525. targetYear = tmStart.tm_year;
  9526. targetMonth = tmStart.tm_mon;
  9527. do
  9528. {
  9529. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9530. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9531. if(targetMonth+1>=13)
  9532. {
  9533. targetYear += 1;
  9534. targetMonth = 1;
  9535. }
  9536. else
  9537. {
  9538. targetMonth += 1;
  9539. }
  9540. }while((targetYear < (tmNow->tm_year+1900)) ||
  9541. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9542. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9543. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9544. system(cmdBuf);
  9545. // Pack charging & event log
  9546. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9547. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9548. targetYear = tmStart.tm_year;
  9549. targetMonth = tmStart.tm_mon;
  9550. do
  9551. {
  9552. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9553. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9554. if(targetMonth+1>=13)
  9555. {
  9556. targetYear += 1;
  9557. targetMonth = 1;
  9558. }
  9559. else
  9560. {
  9561. targetMonth += 1;
  9562. }
  9563. }while((targetYear < (tmNow->tm_year+1900)) ||
  9564. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9565. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9566. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9567. system(cmdBuf);
  9568. // Combine log file
  9569. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9570. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9571. }
  9572. else
  9573. {
  9574. system("exec /root/logPackTools 'log' 6");
  9575. }
  9576. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9577. system(cmdBuf);
  9578. checkUploadLog();
  9579. //****************location*******************/
  9580. if(strcmp(locationstr,"")==0)
  9581. {
  9582. DEBUG_INFO("location is <Empty>!\n");
  9583. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9584. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9585. goto end;
  9586. }
  9587. memset(protocol, 0, ARRAY_SIZE(protocol));
  9588. memset(user, 0, ARRAY_SIZE(user) );
  9589. memset(password, 0, ARRAY_SIZE(password));
  9590. memset(host, 0, ARRAY_SIZE(host));
  9591. memset(path, 0, ARRAY_SIZE(path));
  9592. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9593. memset(host1, 0, ARRAY_SIZE(host1));
  9594. memset(path1, 0, ARRAY_SIZE(path1));
  9595. /*location: ftp://user:password@host:port/path*/
  9596. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9597. if((access(fnamePlusPath,F_OK))!=-1)
  9598. {
  9599. DEBUG_INFO("fnamePlusPath exist.\n");
  9600. }
  9601. else
  9602. {
  9603. DEBUG_INFO("fnamePlusPath not exist!\n");
  9604. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9605. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9606. goto end;
  9607. }
  9608. if(strchr(locationstr,'@')==NULL)
  9609. {
  9610. sscanf(locationstr,
  9611. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9612. protocol, host, &port, path);
  9613. strcpy(user,"anonymous");
  9614. strcpy(password,"");
  9615. }
  9616. else
  9617. {
  9618. //DEBUG_INFO("pch=%s\n", pch);
  9619. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9620. protocol, user, password, host, &port, path);
  9621. }
  9622. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9623. {
  9624. DEBUG_INFO("protocol is not ftp/http ! \n");
  9625. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9626. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9627. goto end;
  9628. }
  9629. if(strncmp(locationstr,"http", 4) == 0)
  9630. {
  9631. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9632. sprintf(ftppath,"/%s", path);
  9633. do
  9634. {
  9635. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9636. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9637. sleep(3);
  9638. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9639. if(!isSuccess)
  9640. {
  9641. DEBUG_INFO("Diagnostics fail.\n");
  9642. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9643. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9644. sleep(retryIntervalInt);
  9645. }
  9646. else
  9647. {
  9648. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9649. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9650. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9651. }
  9652. retriesInt--;
  9653. }while((isSuccess == 0)&&(retriesInt >= 0));
  9654. }
  9655. else
  9656. {
  9657. sscanf(host,"%[^/]%s",host1, path1);
  9658. if(strlen(path) > 0)
  9659. sprintf(ftppath,"/%s", path);
  9660. else
  9661. sprintf(ftppath,"/%s", path1);
  9662. int ftppathlen=strlen(ftppath);
  9663. int i=1;
  9664. char filenametemp[50];
  9665. while(i < ftppathlen)
  9666. {
  9667. int len=ftppathlen-i;
  9668. if(ftppath[len]== 47) // '/' ascll code: 47
  9669. {
  9670. DEBUG_INFO("find '/' all right\n");
  9671. break;
  9672. }
  9673. i=i+1;
  9674. }
  9675. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9676. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9677. filenametemp[i+1] = 0;
  9678. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9679. if(port == 0)
  9680. port = 21;
  9681. do
  9682. {
  9683. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9684. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9685. sleep(3);
  9686. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9687. if(!isSuccess)
  9688. {
  9689. DEBUG_INFO("Diagnostics fail.\n");
  9690. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9691. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9692. sleep(retryIntervalInt);
  9693. }
  9694. else
  9695. {
  9696. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9697. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9698. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9699. }
  9700. retriesInt--;
  9701. }while((!isSuccess)&&(retriesInt >= 0));
  9702. }
  9703. end:
  9704. system("rm -f /mnt/*");
  9705. sleep(5);
  9706. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9707. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9708. interLock.isGetDiagnosticGoing = 0;
  9709. pthread_exit(NULL);
  9710. }
  9711. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9712. {
  9713. mtrace();
  9714. int result = FAIL;
  9715. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9716. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9717. {
  9718. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9719. locallistVersion = -1;
  9720. }
  9721. else
  9722. {
  9723. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9724. OCPP_getListVerion();
  9725. }
  9726. //from db.OCPP_getListVerion
  9727. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9728. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9729. sendGetLocalListVersionConfirmation(uuid,"");
  9730. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9731. return result;
  9732. }
  9733. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9734. {
  9735. mtrace();
  9736. int result = FAIL;
  9737. int connectorIdInt=-1;
  9738. int tempIndex = 0;
  9739. int connectorIdIsNULL, chargingProfileIsNULL;
  9740. char comfirmstr[20]={0};
  9741. char cmdBuf[512];
  9742. json_object *RemoteStartTransaction;
  9743. FILE *fp;
  9744. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9745. if(server_pending == TRUE)
  9746. {
  9747. return 0;
  9748. }
  9749. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9750. RemoteStartTransaction = json_tokener_parse(payload);
  9751. if(!is_error(RemoteStartTransaction))
  9752. {
  9753. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9754. {
  9755. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9756. }
  9757. else
  9758. {
  9759. connectorIdIsNULL = TRUE;
  9760. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9761. {
  9762. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9763. {
  9764. connectorIdIsNULL = FALSE;
  9765. connectorIdInt = (gun_index+1);
  9766. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9767. break;
  9768. }
  9769. }
  9770. }
  9771. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9772. {
  9773. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9774. // Required data
  9775. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9776. // Optional data
  9777. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9778. {
  9779. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9780. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9781. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9782. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9783. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9784. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9785. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9786. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9787. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9788. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9789. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9790. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9791. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9792. {
  9793. 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")));
  9794. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9795. 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"));
  9796. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9797. 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"));
  9798. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9799. 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")));
  9800. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9801. {
  9802. 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++)
  9803. {
  9804. 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"));
  9805. 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"));
  9806. 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)
  9807. 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"));
  9808. }
  9809. }
  9810. }
  9811. }
  9812. else
  9813. {
  9814. chargingProfileIsNULL = TRUE;
  9815. }
  9816. }
  9817. }
  9818. else
  9819. {
  9820. connectorIdIsNULL = TRUE;
  9821. }
  9822. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9823. {
  9824. DEBUG_WARN("Connector id is NULL\n.");
  9825. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9826. goto end;
  9827. }
  9828. /*
  9829. enum _SYSTEM_STATUS
  9830. {
  9831. S_BOOTING = 0,
  9832. S_IDLE, = 1
  9833. S_AUTHORIZING, = 2
  9834. S_REASSIGN_CHECK, = 3
  9835. S_REASSIGN, = 4
  9836. S_PRECHARGE, = 5
  9837. S_PREPARING_FOR_EV, = 6
  9838. S_PREPARING_FOR_EVSE, = 7
  9839. S_CHARGING, = 8
  9840. S_TERMINATING, = 9
  9841. S_COMPLETE, = 10
  9842. S_ALARM, = 11
  9843. S_FAULT = 12
  9844. }
  9845. */
  9846. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9847. {
  9848. //check Transaction active
  9849. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9850. {
  9851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9852. {
  9853. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9854. }
  9855. else
  9856. {
  9857. tempIndex = connectorIdInt -1;
  9858. }
  9859. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9860. {
  9861. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9862. {
  9863. 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))
  9864. {
  9865. //Reserved
  9866. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9867. }
  9868. 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))
  9869. {
  9870. //Reserved
  9871. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9872. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9873. goto end;
  9874. }
  9875. else
  9876. {
  9877. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9878. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9879. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9880. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9881. {
  9882. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9883. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9884. goto end;
  9885. }
  9886. }//END FOR ELSE
  9887. }
  9888. }// END FOR CHAdeMO_QUANTITY
  9889. }
  9890. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9891. {
  9892. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9893. {
  9894. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9895. }
  9896. else
  9897. {
  9898. tempIndex = connectorIdInt -1;
  9899. }
  9900. for (int index = 0; index < CCS_QUANTITY; index++)
  9901. {
  9902. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9903. {
  9904. 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))
  9905. {
  9906. //Reserved
  9907. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9908. }
  9909. 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))
  9910. {
  9911. //Reserved
  9912. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9913. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9914. goto end;
  9915. }
  9916. else
  9917. {
  9918. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9919. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9920. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9921. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9922. {
  9923. DEBUG_WARN("CCS connector not allow start\n.");
  9924. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9925. goto end;
  9926. }
  9927. }// END FOR ELSE
  9928. }
  9929. }// END FOR CCS_QUANTITY
  9930. }
  9931. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9932. {
  9933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9934. {
  9935. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9936. }
  9937. else
  9938. {
  9939. tempIndex = connectorIdInt -1;
  9940. }
  9941. for (int index = 0; index < GB_QUANTITY; index++)
  9942. {
  9943. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9944. {
  9945. 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))
  9946. {
  9947. //Reserved
  9948. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9949. }
  9950. 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))
  9951. {
  9952. //Reserved
  9953. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9954. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9955. goto end;
  9956. }
  9957. else
  9958. {
  9959. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9960. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9961. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9962. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9963. {
  9964. DEBUG_WARN("GB connector not allow start\n.");
  9965. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9966. goto end;
  9967. }
  9968. }// END FOR ELSE
  9969. }
  9970. } // END FOR GB_QUANTITY
  9971. }
  9972. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9973. {
  9974. tempIndex = connectorIdInt -1;
  9975. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9976. {
  9977. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9978. {
  9979. 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))
  9980. {
  9981. //Reserved
  9982. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9983. }
  9984. 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))
  9985. {
  9986. //Reserved
  9987. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9988. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9989. goto end;
  9990. }
  9991. else
  9992. {
  9993. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9994. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9995. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9996. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9997. {
  9998. DEBUG_WARN("GB connector not allow start\n.");
  9999. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10000. goto end;
  10001. }
  10002. }// END FOR ELSE
  10003. }
  10004. } // END FOR GB_QUANTITY
  10005. }
  10006. else
  10007. {
  10008. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10009. {
  10010. tempIndex = 2;
  10011. }
  10012. else
  10013. {
  10014. tempIndex = connectorIdInt -1;
  10015. }
  10016. for (int index = 0; index < AC_QUANTITY; index++)
  10017. {
  10018. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10019. {
  10020. 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))
  10021. {
  10022. //Reserved
  10023. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10024. }
  10025. 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))
  10026. {
  10027. //Reserved
  10028. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10029. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10030. goto end;
  10031. }
  10032. else
  10033. {
  10034. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10035. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10036. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10037. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10038. {
  10039. DEBUG_WARN("AC connector not allow start\n.");
  10040. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10041. goto end;
  10042. }
  10043. }//END FOR ELSE
  10044. }
  10045. }// END FOR AC_QUANTITY
  10046. }
  10047. if(chargingProfileIsNULL == FALSE)
  10048. {
  10049. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10050. {
  10051. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10052. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10053. //memset idTag
  10054. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10055. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10056. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10058. // Save profile to file
  10059. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10060. system(cmdBuf);
  10061. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10062. fp = fopen(cmdBuf, "w");
  10063. 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));
  10064. fclose(fp);
  10065. }
  10066. else
  10067. {
  10068. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10069. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10070. }
  10071. }
  10072. else
  10073. {
  10074. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10075. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10076. //memset idTag
  10077. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10078. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10079. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10080. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10081. }
  10082. }
  10083. else
  10084. {
  10085. DEBUG_WARN("Connector id over\n.");
  10086. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10087. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10088. }
  10089. end:
  10090. json_object_put(RemoteStartTransaction);
  10091. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10092. {
  10093. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10094. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10095. }
  10096. //OCPP send RemoteStartConfirmation by first.
  10097. sendRemoteStartConfirmation(uuid, comfirmstr);
  10098. return result;
  10099. }
  10100. int handleRemoteStartRequest(char *uuid, char *payload)
  10101. {
  10102. mtrace();
  10103. int result = PASS;
  10104. int connectorIdInt=-1;
  10105. int tempIndex = 0;
  10106. char comfirmstr[20]={0};
  10107. char cmdBuf[512];
  10108. json_object *RemoteStartTransaction;
  10109. FILE *fp;
  10110. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10111. if(server_pending == TRUE)
  10112. {
  10113. result = FAIL;
  10114. }
  10115. RemoteStartTransaction = json_tokener_parse(payload);
  10116. if(!is_error(RemoteStartTransaction))
  10117. {
  10118. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10119. {
  10120. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10121. }
  10122. else
  10123. {
  10124. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10125. {
  10126. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10127. {
  10128. connectorIdInt = (gun_index+1);
  10129. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10130. break;
  10131. }
  10132. }
  10133. }
  10134. if(connectorIdInt == 0)
  10135. {
  10136. DEBUG_WARN("Connector id shall not equal 0.\n");
  10137. result = FAIL;
  10138. }
  10139. else if(connectorIdInt == -1)
  10140. {
  10141. DEBUG_INFO("Connector id does not specific.\n");
  10142. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10143. {
  10144. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10145. // Required data
  10146. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10147. // Optional data
  10148. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10149. {
  10150. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10151. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10152. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10153. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10154. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10155. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10156. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10157. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10158. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10159. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10160. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10161. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10162. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10163. {
  10164. 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")));
  10165. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10166. 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"));
  10167. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10168. 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"));
  10169. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10170. 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")));
  10171. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10172. {
  10173. 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++)
  10174. {
  10175. 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"));
  10176. 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"));
  10177. 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)
  10178. 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"));
  10179. }
  10180. }
  10181. }
  10182. }
  10183. else
  10184. {
  10185. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10186. }
  10187. }
  10188. }
  10189. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10190. {
  10191. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10192. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10193. // Required data
  10194. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10195. // Optional data
  10196. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10197. {
  10198. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10199. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10200. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10201. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10202. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10203. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10204. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10205. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10206. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10207. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10208. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10209. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10210. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10211. {
  10212. 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")));
  10213. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10214. 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"));
  10215. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10216. 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"));
  10217. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10218. 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")));
  10219. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10220. {
  10221. 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++)
  10222. {
  10223. 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"));
  10224. 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"));
  10225. 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)
  10226. 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"));
  10227. }
  10228. }
  10229. }
  10230. }
  10231. else
  10232. {
  10233. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10234. }
  10235. }
  10236. else
  10237. {
  10238. DEBUG_WARN("Connector id is over maximun value.\n");
  10239. result = FAIL;
  10240. }
  10241. }
  10242. if(result == PASS)
  10243. {
  10244. if(connectorIdInt > 0)
  10245. {
  10246. //check Transaction active
  10247. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10248. {
  10249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10250. {
  10251. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10252. }
  10253. else
  10254. {
  10255. tempIndex = connectorIdInt -1;
  10256. }
  10257. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10258. {
  10259. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10260. {
  10261. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10262. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10263. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10264. {
  10265. //Reserved
  10266. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10267. }
  10268. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10269. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10270. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10271. {
  10272. //Reserved
  10273. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10274. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10275. goto end;
  10276. }
  10277. else
  10278. {
  10279. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10280. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10281. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10282. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10283. {
  10284. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10285. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10286. goto end;
  10287. }
  10288. }//END FOR ELSE
  10289. }
  10290. }// END FOR CHAdeMO_QUANTITY
  10291. }
  10292. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10293. {
  10294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10295. {
  10296. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10297. }
  10298. else
  10299. {
  10300. tempIndex = connectorIdInt -1;
  10301. }
  10302. for (int index = 0; index < CCS_QUANTITY; index++)
  10303. {
  10304. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10305. {
  10306. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10307. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10308. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10309. {
  10310. //Reserved
  10311. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10312. }
  10313. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10314. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10315. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10316. {
  10317. //Reserved
  10318. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10319. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10320. goto end;
  10321. }
  10322. else
  10323. {
  10324. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10325. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10326. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10327. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10328. {
  10329. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10330. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10331. goto end;
  10332. }
  10333. }// END FOR ELSE
  10334. }
  10335. }// END FOR CCS_QUANTITY
  10336. }
  10337. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10338. {
  10339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10340. {
  10341. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10342. }
  10343. else
  10344. {
  10345. tempIndex = connectorIdInt -1;
  10346. }
  10347. for (int index = 0; index < GB_QUANTITY; index++)
  10348. {
  10349. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10350. {
  10351. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10352. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10353. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10354. {
  10355. //Reserved
  10356. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10357. }
  10358. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10359. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10360. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10361. {
  10362. //Reserved
  10363. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10364. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10365. goto end;
  10366. }
  10367. else
  10368. {
  10369. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10370. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10371. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10372. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10373. {
  10374. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10375. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10376. goto end;
  10377. }
  10378. }// END FOR ELSE
  10379. }
  10380. } // END FOR GB_QUANTITY
  10381. }
  10382. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10383. {
  10384. tempIndex = connectorIdInt -1;
  10385. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10386. {
  10387. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10388. {
  10389. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10390. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10391. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10392. {
  10393. //Reserved
  10394. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10395. }
  10396. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10397. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10398. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10399. {
  10400. //Reserved
  10401. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10402. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10403. goto end;
  10404. }
  10405. else
  10406. {
  10407. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10408. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10409. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10410. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10411. {
  10412. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10413. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10414. goto end;
  10415. }
  10416. }// END FOR ELSE
  10417. }
  10418. } // END FOR GB_QUANTITY
  10419. }
  10420. else
  10421. {
  10422. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10423. {
  10424. tempIndex = 2;
  10425. }
  10426. else
  10427. {
  10428. tempIndex = connectorIdInt -1;
  10429. }
  10430. for (int index = 0; index < AC_QUANTITY; index++)
  10431. {
  10432. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10433. {
  10434. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10435. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10436. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10437. {
  10438. //Reserved
  10439. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10440. }
  10441. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10442. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10443. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10444. {
  10445. //Reserved
  10446. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10447. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10448. goto end;
  10449. }
  10450. else
  10451. {
  10452. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10453. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10454. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10455. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10456. {
  10457. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10458. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10459. goto end;
  10460. }
  10461. }//END FOR ELSE
  10462. }
  10463. }// END FOR AC_QUANTITY
  10464. }
  10465. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10466. {
  10467. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10468. {
  10469. // Save profile to file
  10470. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10471. system(cmdBuf);
  10472. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10473. fp = fopen(cmdBuf, "w");
  10474. 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));
  10475. fclose(fp);
  10476. }
  10477. else
  10478. {
  10479. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10480. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10481. goto end;
  10482. }
  10483. }
  10484. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10485. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10486. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10487. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10488. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10489. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10490. }
  10491. else
  10492. {
  10493. uint8_t isHasIdleConnector = FALSE;
  10494. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10495. {
  10496. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10497. {
  10498. isHasIdleConnector = TRUE;
  10499. break;
  10500. }
  10501. }
  10502. if(isHasIdleConnector == TRUE)
  10503. {
  10504. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10505. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10506. {
  10507. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10508. {
  10509. // Save profile to file
  10510. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10511. system(cmdBuf);
  10512. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10513. fp = fopen(cmdBuf, "w");
  10514. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10515. fclose(fp);
  10516. refreshStartTimer(&clientTime.RemoteStartWait);
  10517. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10518. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10519. }
  10520. else
  10521. {
  10522. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10523. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10524. }
  10525. }
  10526. else
  10527. {
  10528. refreshStartTimer(&clientTime.RemoteStartWait);
  10529. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10530. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10531. }
  10532. }
  10533. else
  10534. {
  10535. DEBUG_INFO("There is not any connector is idle.\n");
  10536. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10537. }
  10538. }
  10539. }
  10540. else
  10541. {
  10542. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10543. }
  10544. end:
  10545. json_object_put(RemoteStartTransaction);
  10546. sendRemoteStartConfirmation(uuid, comfirmstr);
  10547. return result;
  10548. }
  10549. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10550. {
  10551. mtrace();
  10552. int result = FAIL;
  10553. int match = FALSE;
  10554. int GunNO = 0;
  10555. int tempIndex = 0;
  10556. int transactionIdInt=0;
  10557. int transactionIdIsNULL= TRUE;
  10558. char comfirmstr[20];
  10559. json_object *RemoteStopTransaction;
  10560. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10561. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10562. if(server_pending == TRUE)
  10563. {
  10564. return 0;
  10565. }
  10566. RemoteStopTransaction = json_tokener_parse(payload);
  10567. if(!is_error(RemoteStopTransaction))
  10568. {
  10569. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10570. {
  10571. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10572. transactionIdIsNULL = FALSE;
  10573. }
  10574. }
  10575. json_object_put(RemoteStopTransaction);
  10576. if(transactionIdIsNULL == FALSE)
  10577. {
  10578. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10579. {
  10580. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10581. {
  10582. //check Transaction active
  10583. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10584. {
  10585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10586. {
  10587. tempIndex = ((gun_index==2) ? 1: 0);
  10588. }
  10589. else
  10590. {
  10591. tempIndex = gun_index;
  10592. }
  10593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10594. {
  10595. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10596. {
  10597. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10598. {
  10599. match = TRUE;
  10600. GunNO = gun_index;
  10601. }
  10602. }
  10603. }// END FOR CHAdeMO_QUANTITY
  10604. }
  10605. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10606. {
  10607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10608. {
  10609. tempIndex = ((gun_index==2) ? 1: 0);
  10610. }
  10611. else
  10612. {
  10613. tempIndex = gun_index;
  10614. }
  10615. for (int index = 0; index < CCS_QUANTITY; index++)
  10616. {
  10617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10618. {
  10619. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10620. {
  10621. match = TRUE;
  10622. GunNO = gun_index;
  10623. }
  10624. }
  10625. }// END FOR CCS_QUANTITY
  10626. }
  10627. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10628. {
  10629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10630. {
  10631. tempIndex = ((gun_index==2) ? 1: 0);
  10632. }
  10633. else
  10634. {
  10635. tempIndex = gun_index;
  10636. }
  10637. for (int index = 0; index < GB_QUANTITY; index++)
  10638. {
  10639. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10640. {
  10641. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10642. {
  10643. match = TRUE;
  10644. GunNO = gun_index;
  10645. }
  10646. }
  10647. }// END FOR GB_QUANTITY
  10648. }
  10649. else if(gunType[gun_index] == GUN_TYPE_DO)
  10650. {
  10651. tempIndex = gun_index;
  10652. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10653. {
  10654. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10655. {
  10656. 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
  10657. {
  10658. match = TRUE;
  10659. GunNO = gun_index;
  10660. }
  10661. }
  10662. }// END FOR GB_QUANTITY
  10663. }
  10664. else
  10665. {
  10666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10667. {
  10668. tempIndex = 2;
  10669. }
  10670. else
  10671. {
  10672. tempIndex = gun_index;
  10673. }
  10674. for (int index = 0; index < AC_QUANTITY; index++)
  10675. {
  10676. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10677. {
  10678. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10679. {
  10680. match = TRUE;
  10681. GunNO = gun_index;
  10682. }
  10683. }
  10684. }// END FOR CHAdeMO_QUANTITY
  10685. } // END FOR AC ELSE
  10686. }// CHECK IF ResponseTransactionId == transactionIdInt
  10687. }//END FOR
  10688. if( match == TRUE)
  10689. {
  10690. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10691. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10692. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10693. }
  10694. else
  10695. {
  10696. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10697. }
  10698. }
  10699. else
  10700. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10701. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10702. return result;
  10703. }
  10704. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10705. {
  10706. mtrace();
  10707. int result = FAIL;
  10708. int connectorIdInt=0, reservationIdInt=0;
  10709. int tempIndex = 0;
  10710. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10711. char comfirmstr[20]={0};
  10712. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10713. int c = 0;
  10714. char *loc;
  10715. //char *ptr;
  10716. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10717. strcpy(sstrtemp, stringtrimspace(payload));
  10718. //***(1)connectorId ****/
  10719. c=0;
  10720. loc = strstr(sstrtemp, "connectorId");
  10721. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10722. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10723. {
  10724. sstr[c] = loc[strlen("connectorId")+2+c];
  10725. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10726. c++;
  10727. }
  10728. sstr[c] = '\0';
  10729. connectorIdInt = atoi(sstr);
  10730. //***(2)expiryDate ****/
  10731. loc = strstr(sstrtemp, "expiryDate");
  10732. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10733. c = 0;
  10734. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10735. {
  10736. sstr[c] = loc[3+strlen("expiryDate")+c];
  10737. c++;
  10738. }
  10739. sstr[c] = '\0';
  10740. strcpy(expiryDatestr, sstr);
  10741. //***(3)idTag ****/
  10742. loc = strstr(sstrtemp, "idTag");
  10743. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10744. c = 0;
  10745. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10746. {
  10747. sstr[c] = loc[3+strlen("idTag")+c];
  10748. c++;
  10749. }
  10750. sstr[c] = '\0';
  10751. strcpy(idTagstr, sstr);
  10752. //***(4)parentIdTag ****/
  10753. loc = strstr(sstrtemp, "parentIdTag");
  10754. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10755. c = 0;
  10756. if(loc == NULL)
  10757. {
  10758. strcpy(parentIdTagstr, "");
  10759. }
  10760. else
  10761. {
  10762. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10763. {
  10764. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10765. c++;
  10766. }
  10767. sstr[c] = '\0';
  10768. strcpy(parentIdTagstr, sstr);
  10769. }
  10770. //***(5)reservationId ****/
  10771. c=0;
  10772. loc = strstr(sstrtemp, "reservationId");
  10773. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10774. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10775. {
  10776. sstr[c] = loc[strlen("reservationId")+2+c];
  10777. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10778. c++;
  10779. }
  10780. sstr[c] = '\0';
  10781. reservationIdInt = atoi(sstr);
  10782. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10783. /*
  10784. enum SYSTEM_STATUS
  10785. {
  10786. SYS_MODE_BOOTING = 0,
  10787. SYS_MODE_IDLE = 1,
  10788. SYS_MODE_AUTHORIZING = 2,
  10789. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10790. SYS_MODE_REASSIGN = 4,
  10791. SYS_MODE_PREPARING = 5,
  10792. SYS_MODE_PREPARE_FOR_EV = 6,
  10793. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10794. SYS_MODE_CHARGING = 8,
  10795. SYS_MODE_TERMINATING = 9,
  10796. SYS_MODE_COMPLETE = 10,
  10797. SYS_MODE_ALARM = 11,
  10798. SYS_MODE_FAULT = 12,
  10799. SYS_MODE_RESERVATION = 13,
  10800. SYS_MODE_BOOKING = 14,
  10801. SYS_MODE_MAINTAIN = 15,
  10802. SYS_MODE_DEBUG = 16,
  10803. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10804. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10805. SYS_MODE_UPDATE = 19
  10806. };
  10807. */
  10808. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10809. {
  10810. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10811. goto end;
  10812. }
  10813. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10814. {
  10815. //check Transaction active
  10816. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10817. {
  10818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10819. {
  10820. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10821. }
  10822. else
  10823. {
  10824. tempIndex = connectorIdInt -1;
  10825. }
  10826. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10827. {
  10828. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10829. {
  10830. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10831. {
  10832. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10833. {
  10834. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10835. {
  10836. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10838. }
  10839. 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'))
  10840. {
  10841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10842. }
  10843. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10844. {
  10845. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10846. }
  10847. else
  10848. {
  10849. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10850. }
  10851. }
  10852. 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
  10853. {
  10854. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10855. }
  10856. }
  10857. else
  10858. {
  10859. //replace reservation
  10860. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10861. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10862. }
  10863. }
  10864. } // END FOR CHAdeMO_QUANTITY
  10865. }
  10866. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10867. {
  10868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10869. {
  10870. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10871. }
  10872. else
  10873. {
  10874. tempIndex = connectorIdInt -1;
  10875. }
  10876. for (int index = 0; index < CCS_QUANTITY; index++)
  10877. {
  10878. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10879. {
  10880. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10881. {
  10882. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10883. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10884. {
  10885. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10886. {
  10887. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10889. }
  10890. 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'))
  10891. {
  10892. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10893. }
  10894. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10895. {
  10896. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10897. }
  10898. else
  10899. {
  10900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10901. }
  10902. }
  10903. 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
  10904. {
  10905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10906. }
  10907. }
  10908. else
  10909. {
  10910. //replace reservation
  10911. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10912. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10913. }
  10914. }
  10915. } // END FOR CCS_QUANTITY
  10916. }
  10917. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10918. {
  10919. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10920. {
  10921. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10922. }
  10923. else
  10924. {
  10925. tempIndex = connectorIdInt -1;
  10926. }
  10927. for (int index = 0; index < GB_QUANTITY; index++)
  10928. {
  10929. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10930. {
  10931. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10932. {
  10933. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10934. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10935. {
  10936. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10937. {
  10938. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10940. }
  10941. 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'))
  10942. {
  10943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10944. }
  10945. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10946. {
  10947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10948. }
  10949. else
  10950. {
  10951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10952. }
  10953. }
  10954. 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
  10955. {
  10956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10957. }
  10958. }
  10959. else
  10960. {
  10961. //replace reservation
  10962. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10963. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10964. }
  10965. }
  10966. }// END FOR GB_QUANTITY
  10967. }
  10968. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10969. {
  10970. tempIndex = connectorIdInt -1;
  10971. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10972. {
  10973. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10974. {
  10975. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10976. {
  10977. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10978. 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
  10979. {
  10980. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10981. {
  10982. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10984. }
  10985. 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'))
  10986. {
  10987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10988. }
  10989. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10990. {
  10991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10992. }
  10993. else
  10994. {
  10995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10996. }
  10997. }
  10998. 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
  10999. {
  11000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11001. }
  11002. }
  11003. else
  11004. {
  11005. //replace reservation
  11006. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11008. }
  11009. }
  11010. }// END FOR GB_QUANTITY
  11011. }
  11012. else
  11013. {
  11014. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11015. {
  11016. tempIndex = 2;
  11017. }
  11018. else
  11019. {
  11020. tempIndex = (connectorIdInt -1);
  11021. }
  11022. for (int index = 0; index < AC_QUANTITY; index++)
  11023. {
  11024. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11025. {
  11026. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11027. {
  11028. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11029. {
  11030. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11031. {
  11032. 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))
  11033. {
  11034. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11035. }
  11036. else
  11037. {
  11038. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11040. }
  11041. }
  11042. 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'))
  11043. {
  11044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11045. }
  11046. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11047. {
  11048. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11049. }
  11050. else
  11051. {
  11052. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11053. }
  11054. }
  11055. 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
  11056. {
  11057. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11058. }
  11059. }
  11060. else
  11061. {
  11062. //replace reservation
  11063. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11065. }
  11066. }
  11067. } // END FOR AC_QUANTITY
  11068. }
  11069. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11070. }
  11071. else if(connectorIdInt == 0)
  11072. {
  11073. //check Transaction active
  11074. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11075. {
  11076. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11077. {
  11078. 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'))
  11079. {
  11080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11081. goto end;
  11082. }
  11083. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11084. {
  11085. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11086. goto end;
  11087. }
  11088. 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
  11089. {
  11090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11091. goto end;
  11092. }
  11093. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11094. {
  11095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11096. goto end;
  11097. }
  11098. }
  11099. }// END FOR CHAdeMO_QUANTITY
  11100. for (int index = 0; index < CCS_QUANTITY; index++)
  11101. {
  11102. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11103. {
  11104. 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'))
  11105. {
  11106. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11107. goto end;
  11108. }
  11109. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11110. {
  11111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11112. goto end;
  11113. }
  11114. 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
  11115. {
  11116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11117. goto end;
  11118. }
  11119. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11120. {
  11121. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11122. goto end;
  11123. }
  11124. }
  11125. } // END FOR CCS_QUANTITY
  11126. for (int index = 0; index < GB_QUANTITY; index++)
  11127. {
  11128. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11129. {
  11130. 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'))
  11131. {
  11132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11133. goto end;
  11134. }
  11135. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11136. {
  11137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11138. goto end;
  11139. }
  11140. 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
  11141. {
  11142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11143. goto end;
  11144. }
  11145. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11146. {
  11147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11148. goto end;
  11149. }
  11150. }
  11151. } // END FOR GB_QUANTITY
  11152. for (int index = 0; index < AC_QUANTITY; index++)
  11153. {
  11154. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11155. {
  11156. 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'))
  11157. {
  11158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11159. goto end;
  11160. }
  11161. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11162. {
  11163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11164. goto end;
  11165. }
  11166. 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
  11167. {
  11168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11169. goto end;
  11170. }
  11171. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11172. {
  11173. 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))
  11174. {
  11175. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11176. goto end;
  11177. }
  11178. }
  11179. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11180. {
  11181. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11182. goto end;
  11183. }
  11184. }
  11185. }// END FOR AC_QUANTITY
  11186. //The connectorId is 0
  11187. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11188. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11189. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11190. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11191. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11192. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11193. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11194. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11195. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11196. result = TRUE;
  11197. return result;
  11198. }
  11199. else
  11200. {
  11201. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11202. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11203. }
  11204. if(strcmp(comfirmstr,"Accepted") == 0)
  11205. {
  11206. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11207. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11208. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11209. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11210. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11211. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11212. result = TRUE;
  11213. return result;
  11214. }
  11215. end:
  11216. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11217. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11218. return result;
  11219. }
  11220. int handleResetRequest(char *uuid, char *payload)
  11221. {
  11222. mtrace();
  11223. int result = FAIL;
  11224. char sstr[10]={0},sstrtemp[30]={ 0 };
  11225. char typestr[10]={0};
  11226. char comfirmstr[20]={0};
  11227. int c = 0;
  11228. char *loc;
  11229. DEBUG_INFO("handleResetRequest...\n");
  11230. strcpy(sstrtemp, stringtrimspace(payload));
  11231. loc = strstr(sstrtemp, "type");
  11232. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11233. c = 0;
  11234. while (loc[3+strlen("type")+c] != '\"')
  11235. {
  11236. sstr[c] = loc[3+strlen("type")+c];
  11237. c++;
  11238. }
  11239. sstr[c] = '\0';
  11240. strcpy(typestr,sstr);
  11241. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11242. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11243. {
  11244. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11245. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11246. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11247. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11248. }
  11249. else
  11250. {
  11251. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11252. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11253. result = PASS;
  11254. }
  11255. sendResetConfirmation(uuid, comfirmstr);
  11256. return result;
  11257. }
  11258. int handleSendLocalListRequest(char *uuid, char *payload)
  11259. {
  11260. mtrace();
  11261. int result = FAIL;
  11262. char comfirmstr[20];
  11263. int checkState_Faulted = FALSE;
  11264. json_object *SendLocalList;
  11265. DEBUG_INFO("handleSendLocalListRequest...\n");
  11266. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11267. {
  11268. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11269. goto end;
  11270. }
  11271. //check Charge Point state
  11272. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11273. {
  11274. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11275. {
  11276. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11277. }
  11278. }
  11279. for (int index = 0; index < CCS_QUANTITY; index++)
  11280. {
  11281. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11282. {
  11283. checkState_Faulted = TRUE; //OCPP Status
  11284. }
  11285. }
  11286. for (int index = 0; index < GB_QUANTITY; index++)
  11287. {
  11288. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11289. {
  11290. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11291. }
  11292. }
  11293. //check Charge Point state
  11294. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11295. {
  11296. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11297. {
  11298. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11299. }
  11300. }
  11301. //check Charge Point state
  11302. for (int index = 0; index < AC_QUANTITY; index++)
  11303. {
  11304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11305. {
  11306. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11307. }
  11308. }
  11309. if(checkState_Faulted == TRUE)
  11310. {
  11311. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11312. goto end;
  11313. }
  11314. // Parsing payload
  11315. SendLocalList = json_tokener_parse(payload);
  11316. if(!is_error(SendLocalList))
  11317. {
  11318. // Required data
  11319. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11320. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11321. // Optional data
  11322. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11323. {
  11324. //Check UpdateType
  11325. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11326. {
  11327. //Local list full update
  11328. DEBUG_INFO("Local list full update.\n");
  11329. OCPP_getListVerion();
  11330. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11331. {
  11332. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11333. goto end;
  11334. }
  11335. OCPP_cleanLocalList();
  11336. }
  11337. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11338. {
  11339. //Local list different update
  11340. DEBUG_INFO("Local list different update.\n");
  11341. OCPP_getListVerion();
  11342. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11343. {
  11344. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11345. goto end;
  11346. }
  11347. }
  11348. else
  11349. {
  11350. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11351. goto end;
  11352. }
  11353. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11354. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11355. {
  11356. 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")));
  11357. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11358. {
  11359. 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")));
  11360. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11361. 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")));
  11362. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11363. 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")));
  11364. }
  11365. // Add to db
  11366. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11367. {
  11368. //Local list full update
  11369. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11370. idx,
  11371. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11372. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11373. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11374. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11375. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11376. // update list
  11377. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11378. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11379. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11380. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11381. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11382. }
  11383. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11384. {
  11385. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11386. idx,
  11387. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11388. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11389. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11390. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11391. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11392. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11393. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11394. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11395. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11396. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11397. }
  11398. }
  11399. }
  11400. else
  11401. {
  11402. //Check UpdateType
  11403. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11404. {
  11405. //Local list full update
  11406. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11407. OCPP_cleanLocalList();
  11408. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11409. goto end;
  11410. }
  11411. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11412. {
  11413. //Local list different update
  11414. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11415. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11416. goto end;
  11417. }
  11418. }
  11419. result = PASS;
  11420. }
  11421. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11422. end:
  11423. json_object_put(SendLocalList);
  11424. sendSendLocalListConfirmation(uuid, comfirmstr);
  11425. return result;
  11426. }
  11427. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11428. {
  11429. mtrace();
  11430. int result = FAIL;
  11431. struct StructSetChargingProfile SetProfileReq = {0};
  11432. int tempchargingProfileIdInt;
  11433. int chargingSchedulePeriodCount = 0;
  11434. char comfirmstr[20]={0};
  11435. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11436. char rmFileCmd[128]={0};
  11437. int profileQuantity = 0;
  11438. json_object *SetChargingProfile;
  11439. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11440. SetChargingProfile = json_tokener_parse(payload);
  11441. if(!is_error(SetChargingProfile))
  11442. {
  11443. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11444. {
  11445. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11446. }
  11447. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11448. {
  11449. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11450. {
  11451. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11452. }
  11453. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11454. {
  11455. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11456. }
  11457. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11458. {
  11459. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11460. }
  11461. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11462. {
  11463. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11464. }
  11465. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11466. {
  11467. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11468. }
  11469. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11470. {
  11471. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11472. }
  11473. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11474. {
  11475. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11476. }
  11477. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11478. {
  11479. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11480. }
  11481. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11482. {
  11483. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11484. {
  11485. 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")));
  11486. }
  11487. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11488. {
  11489. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11490. }
  11491. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11492. {
  11493. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11494. }
  11495. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11496. {
  11497. 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")));
  11498. }
  11499. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11500. {
  11501. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11502. if(chargingSchedulePeriodCount <= 10)
  11503. {
  11504. 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++)
  11505. {
  11506. 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)
  11507. {
  11508. 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"));
  11509. }
  11510. 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)
  11511. {
  11512. 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"));
  11513. }
  11514. 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)
  11515. {
  11516. 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"));
  11517. }
  11518. }
  11519. }
  11520. }
  11521. }
  11522. }
  11523. }
  11524. // Profile periods quantity check
  11525. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11526. {
  11527. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11528. goto end;
  11529. }
  11530. // Check invalid limit
  11531. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11532. {
  11533. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11534. {
  11535. 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)))) ||
  11536. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11537. {
  11538. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11539. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11540. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11541. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11542. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11543. goto end;
  11544. }
  11545. }
  11546. }
  11547. else
  11548. {
  11549. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11550. {
  11551. 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))
  11552. {
  11553. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11554. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11555. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11556. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11557. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11558. goto end;
  11559. }
  11560. }
  11561. }
  11562. // Profile purpose info check
  11563. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11564. {
  11565. FILE *fp;
  11566. char dataLine[4096]={0};
  11567. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11568. if(SetProfileReq.ConnectorId != 0)
  11569. {
  11570. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11571. goto end;
  11572. }
  11573. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11574. if (!fp)
  11575. {
  11576. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11577. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11578. }
  11579. else
  11580. {
  11581. while(fscanf(fp, "%s", dataLine) != EOF)
  11582. {
  11583. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11584. {
  11585. profileQuantity += 1;
  11586. }
  11587. }
  11588. }
  11589. fclose(fp);
  11590. }
  11591. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11592. {
  11593. FILE *fp;
  11594. char dataLine[4096]={0};
  11595. char filename[128]={0};
  11596. int tmpProfileQuantity;
  11597. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11598. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11599. {
  11600. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11601. goto end;
  11602. }
  11603. if(SetProfileReq.ConnectorId == 0)
  11604. {
  11605. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11606. {
  11607. tmpProfileQuantity = 0;
  11608. memset(filename, 0, ARRAY_SIZE(filename));
  11609. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11610. fp = fopen(filename, "r");
  11611. if (!fp)
  11612. {
  11613. DEBUG_INFO("%s does not create.\n", filename);
  11614. fp = fopen(filename, "w+");
  11615. }
  11616. else
  11617. {
  11618. while(fscanf(fp, "%s", dataLine) != EOF)
  11619. {
  11620. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11621. {
  11622. tmpProfileQuantity += 1;
  11623. }
  11624. }
  11625. }
  11626. fclose(fp);
  11627. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11628. }
  11629. }
  11630. else
  11631. {
  11632. memset(filename, 0, ARRAY_SIZE(filename));
  11633. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11634. fp = fopen(filename, "r");
  11635. if (!fp)
  11636. {
  11637. DEBUG_INFO("%s does not create.\n", filename);
  11638. fp = fopen(filename, "w+");
  11639. }
  11640. else
  11641. {
  11642. while(fscanf(fp, "%s", dataLine) != EOF)
  11643. {
  11644. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11645. {
  11646. profileQuantity += 1;
  11647. }
  11648. }
  11649. }
  11650. fclose(fp);
  11651. }
  11652. }
  11653. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11654. {
  11655. int isMatchTransactiodId= FALSE;
  11656. FILE *fp;
  11657. char dataLine[4096]={0};
  11658. char filename[128]={0};
  11659. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11660. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11661. if(SetProfileReq.ConnectorId == 0)
  11662. {
  11663. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11664. goto end;
  11665. }
  11666. int tempIndex = 0;
  11667. //check Transaction active
  11668. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11669. {
  11670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11671. {
  11672. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11673. }
  11674. else
  11675. {
  11676. tempIndex = SetProfileReq.ConnectorId -1;
  11677. }
  11678. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11679. {
  11680. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11681. {
  11682. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11683. {
  11684. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11685. {
  11686. isMatchTransactiodId = TRUE;
  11687. break;
  11688. }
  11689. }
  11690. }
  11691. }
  11692. }
  11693. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11694. {
  11695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11696. {
  11697. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11698. }
  11699. else
  11700. {
  11701. tempIndex = SetProfileReq.ConnectorId -1;
  11702. }
  11703. for (int index = 0; index < CCS_QUANTITY; index++)
  11704. {
  11705. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11706. {
  11707. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11708. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11709. {
  11710. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11711. {
  11712. isMatchTransactiodId = TRUE;
  11713. break;
  11714. }
  11715. }
  11716. }
  11717. }
  11718. }
  11719. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11720. {
  11721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11722. {
  11723. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11724. }
  11725. else
  11726. {
  11727. tempIndex = SetProfileReq.ConnectorId -1;
  11728. }
  11729. for (int index = 0; index < GB_QUANTITY; index++)
  11730. {
  11731. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11732. {
  11733. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11734. {
  11735. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11736. {
  11737. isMatchTransactiodId = TRUE;
  11738. break;
  11739. }
  11740. }
  11741. }
  11742. }
  11743. }
  11744. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11745. {
  11746. tempIndex = SetProfileReq.ConnectorId -1;
  11747. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11748. {
  11749. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11750. {
  11751. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11752. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11753. {
  11754. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11755. {
  11756. isMatchTransactiodId = TRUE;
  11757. break;
  11758. }
  11759. }
  11760. }
  11761. }
  11762. }
  11763. else
  11764. {
  11765. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11766. {
  11767. tempIndex = 2;
  11768. }
  11769. else
  11770. {
  11771. tempIndex = (SetProfileReq.ConnectorId -1);
  11772. }
  11773. for (int index = 0; index < AC_QUANTITY; index++)
  11774. {
  11775. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11776. {
  11777. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11778. {
  11779. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11780. {
  11781. isMatchTransactiodId = TRUE;
  11782. break;
  11783. }
  11784. }
  11785. }
  11786. }
  11787. }
  11788. //check Transaction active
  11789. if(isMatchTransactiodId == FALSE)
  11790. {
  11791. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11792. goto end;
  11793. }
  11794. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11795. {
  11796. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11797. goto end;
  11798. }
  11799. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11800. fp = fopen(filename, "r");
  11801. if (!fp)
  11802. {
  11803. DEBUG_INFO("%s does not create.\n", filename);
  11804. fp = fopen(filename, "w+");
  11805. }
  11806. else
  11807. {
  11808. //Check Charging Profile Count
  11809. while(fscanf(fp, "%s", dataLine) != EOF)
  11810. {
  11811. //DEBUG_INFO("word=%s\n",word);
  11812. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11813. {
  11814. profileQuantity += 1;
  11815. }
  11816. }
  11817. }
  11818. fclose(fp);
  11819. }
  11820. // Check ChargeProfileMaxStackLevel
  11821. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11822. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11823. {
  11824. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11825. goto end;
  11826. }
  11827. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11828. {
  11829. FILE *fp;
  11830. char dataLine[4096]={0};
  11831. char fnametemp[128]={0};
  11832. int tmpProfileQuantity;
  11833. //Check ChargePointMaxProfile.json exit
  11834. profileQuantity = 0;
  11835. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11836. {
  11837. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11838. //Check Charging Profile Count
  11839. tmpProfileQuantity = 0;
  11840. while(fscanf(fp, "%s", dataLine) != EOF)
  11841. {
  11842. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11843. {
  11844. profileQuantity += 1;
  11845. tmpProfileQuantity += 1;
  11846. }
  11847. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11848. }
  11849. fclose(fp);
  11850. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11851. }
  11852. //Check TxDefaultProfile_%d.json
  11853. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11854. {
  11855. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11856. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11857. if((access(fnametemp,F_OK))!=-1)
  11858. {
  11859. fp = fopen(fnametemp, "r");
  11860. //Check Charging Profile Count
  11861. tmpProfileQuantity = 0;
  11862. while(fscanf(fp, "%s", dataLine) != EOF)
  11863. {
  11864. //DEBUG_INFO("word=%s\n",word);
  11865. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11866. {
  11867. profileQuantity += 1;
  11868. tmpProfileQuantity += 1;
  11869. }
  11870. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11871. }
  11872. fclose(fp);
  11873. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11874. }
  11875. }
  11876. //Check TxProfile_%d.json
  11877. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11878. {
  11879. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11880. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11881. if((access(fnametemp,F_OK))!=-1)
  11882. {
  11883. fp = fopen(fnametemp, "r");
  11884. //Check Charging Profile Count
  11885. tmpProfileQuantity = 0;
  11886. while(fscanf(fp, "%s", dataLine) != EOF)
  11887. {
  11888. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11889. {
  11890. profileQuantity += 1;
  11891. tmpProfileQuantity += 1;
  11892. }
  11893. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11894. }
  11895. fclose(fp);
  11896. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11897. }
  11898. }
  11899. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11900. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11901. {
  11902. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11903. goto end;
  11904. }
  11905. }
  11906. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11907. //**********************************Write to File********************************************************/
  11908. {
  11909. FILE *infile;
  11910. FILE *outfile;
  11911. char dataLine[4096]={0};
  11912. char filename[128]={0};
  11913. int chkChar=0;
  11914. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11915. {
  11916. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11917. {
  11918. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11919. }
  11920. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11921. {
  11922. if(SetProfileReq.ConnectorId==0)
  11923. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11924. else
  11925. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11926. }
  11927. else
  11928. {
  11929. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11930. }
  11931. infile = fopen (filename, "r");
  11932. outfile = fopen (tempfile, "w");
  11933. chkChar = fgetc(infile);
  11934. rewind(infile);
  11935. if(chkChar == EOF)
  11936. {
  11937. // Profile is empty
  11938. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11939. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11940. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11941. fclose(infile);
  11942. fclose(outfile);
  11943. sprintf(rmFileCmd,"rm -f %s",filename);
  11944. system(rmFileCmd);
  11945. rename(tempfile, filename);
  11946. }
  11947. else
  11948. {
  11949. // Profile is not empty
  11950. int ChargingProfileAdded = FALSE;
  11951. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11952. {
  11953. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11954. json_object *tmpChargingProfile;
  11955. tmpChargingProfile = json_tokener_parse(dataLine);
  11956. if(!is_error(SetChargingProfile))
  11957. {
  11958. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11959. {
  11960. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11961. {
  11962. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11963. }
  11964. }
  11965. }
  11966. json_object_put(tmpChargingProfile);
  11967. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11968. {
  11969. if(ChargingProfileAdded == FALSE)
  11970. {
  11971. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11972. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11973. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11974. ChargingProfileAdded = TRUE;
  11975. }
  11976. }
  11977. else
  11978. {
  11979. fprintf(outfile,"%s\n",dataLine);
  11980. if(ChargingProfileAdded == FALSE)
  11981. {
  11982. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11983. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11984. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11985. ChargingProfileAdded = TRUE;
  11986. }
  11987. }
  11988. } // end of while loop
  11989. fclose(infile);
  11990. fclose(outfile);
  11991. sprintf(rmFileCmd,"rm -f %s",filename);
  11992. system(rmFileCmd);
  11993. rename(tempfile, filename);
  11994. }
  11995. }
  11996. sleep(1);
  11997. result = TRUE;
  11998. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11999. }
  12000. end:
  12001. json_object_put(SetChargingProfile);
  12002. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12003. {
  12004. if(SetProfileReq.ConnectorId == 0)
  12005. {
  12006. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12007. {
  12008. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12009. }
  12010. }
  12011. else
  12012. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12013. }
  12014. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12015. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12016. return result;
  12017. }
  12018. int handleTriggerMessageRequest(char *uuid, char *payload)
  12019. {
  12020. mtrace();
  12021. int result = FAIL;
  12022. int connectorIdIsNULL = FALSE;
  12023. int connectorIdInt =0;
  12024. char sstr[40]={0},sstrtemp[100]={ 0 };
  12025. char requestedMessagestr[40]={0};
  12026. char comfirmstr[20]={0};
  12027. int c = 0;
  12028. char *loc;
  12029. DEBUG_INFO("handleTriggerMessageRequest\n");
  12030. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12031. strcpy(sstrtemp, stringtrimspace(payload));
  12032. c = 0;
  12033. loc = strstr(sstrtemp, "requestedMessage");
  12034. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12035. {
  12036. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12037. c++;
  12038. }
  12039. sstr[c] = '\0';
  12040. strcpy(requestedMessagestr, sstr);
  12041. c = 0;
  12042. loc = strstr(sstrtemp, "connectorId");
  12043. if(loc == NULL)
  12044. {
  12045. connectorIdIsNULL = TRUE;
  12046. }
  12047. else
  12048. {
  12049. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12050. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12051. {
  12052. sstr[c] = loc[strlen("connectorId")+2+c];
  12053. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12054. c++;
  12055. }
  12056. sstr[c] = '\0';
  12057. connectorIdInt = atoi(sstr);
  12058. }
  12059. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12060. {
  12061. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12062. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12063. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12064. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12065. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12066. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12067. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12068. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12069. {
  12070. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12071. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12072. return TRUE;
  12073. }
  12074. else
  12075. {
  12076. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12077. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12078. }
  12079. }
  12080. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12081. {
  12082. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12083. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12084. return TRUE;
  12085. }
  12086. //==========================
  12087. // Trigger message
  12088. //==========================
  12089. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12090. {
  12091. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12092. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12093. {
  12094. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12095. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12096. }
  12097. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12098. }
  12099. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12100. {
  12101. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12102. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12103. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12104. }
  12105. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12106. {
  12107. //sendBootNotificationRequest();
  12108. server_sign = FALSE;
  12109. }
  12110. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12111. {
  12112. refreshStartTimer(&clientTime.Heartbeat);
  12113. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12114. }
  12115. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12116. {
  12117. if(connectorIdIsNULL == FALSE)
  12118. {
  12119. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12120. {
  12121. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12122. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12123. }
  12124. }
  12125. else
  12126. {
  12127. for(int idx=0;idx< gunTotalNumber;idx++)
  12128. {
  12129. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12130. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12131. }
  12132. }
  12133. }
  12134. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12135. {
  12136. if(connectorIdIsNULL == FALSE)
  12137. {
  12138. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12139. {
  12140. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12141. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12142. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12143. }
  12144. }
  12145. else
  12146. {
  12147. for(int idx=0;idx< gunTotalNumber;idx++)
  12148. {
  12149. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12150. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12151. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12152. }
  12153. }
  12154. }
  12155. return result;
  12156. }
  12157. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12158. {
  12159. mtrace();
  12160. int result = FAIL;
  12161. int connectorIdInt =0;
  12162. char comfirmstr[20]={0};
  12163. int tempIndex = 0;
  12164. json_object *UnlockConnector;
  12165. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12166. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12167. UnlockConnector = json_tokener_parse(payload);
  12168. if(!is_error(UnlockConnector))
  12169. {
  12170. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12171. {
  12172. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12173. }
  12174. }
  12175. json_object_put(UnlockConnector);
  12176. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12177. if(gunTotalNumber == 0)
  12178. {
  12179. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12180. goto end;
  12181. }
  12182. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12183. {
  12184. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12185. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12186. goto end;
  12187. }
  12188. else
  12189. {
  12190. //check Transaction active
  12191. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12192. {
  12193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12194. {
  12195. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12196. }
  12197. else
  12198. {
  12199. tempIndex = connectorIdInt -1;
  12200. }
  12201. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12202. {
  12203. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12204. {
  12205. //stop Transaction
  12206. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12207. }
  12208. }
  12209. }
  12210. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12211. {
  12212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12213. {
  12214. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12215. }
  12216. else
  12217. {
  12218. tempIndex = connectorIdInt -1;
  12219. }
  12220. for (int index = 0; index < CCS_QUANTITY; index++)
  12221. {
  12222. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12223. {
  12224. //stop Transaction
  12225. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12226. }
  12227. }
  12228. }
  12229. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12230. {
  12231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12232. {
  12233. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12234. }
  12235. else
  12236. {
  12237. tempIndex = connectorIdInt -1;
  12238. }
  12239. for (int index = 0; index < GB_QUANTITY; index++)
  12240. {
  12241. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12242. {
  12243. //stop Transaction
  12244. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12245. }
  12246. }
  12247. }
  12248. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12249. {
  12250. tempIndex = connectorIdInt -1;
  12251. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12252. {
  12253. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12254. {
  12255. //stop Transaction
  12256. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12257. }
  12258. }
  12259. }
  12260. else
  12261. {
  12262. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12263. {
  12264. tempIndex = 2;
  12265. }
  12266. else
  12267. {
  12268. tempIndex = connectorIdInt-1;
  12269. }
  12270. for (int index = 0; index < AC_QUANTITY; index++)
  12271. {
  12272. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12273. {
  12274. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12275. }
  12276. }
  12277. }
  12278. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12279. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12280. result = TRUE;
  12281. return result;
  12282. }
  12283. end:
  12284. //json_object_put(obj); --- remove temporally
  12285. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12286. return result;
  12287. }
  12288. static char UpdateFirmwarepayloadData[300]={0};
  12289. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12290. {
  12291. mtrace();
  12292. int result = FAIL;
  12293. pthread_t t;
  12294. sendUpdateFirmwareConfirmation(uuid);
  12295. memset(UpdateFirmwarepayloadData, 0, 300);
  12296. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12297. if(!interLock.isUpdateFirmwareGoing)
  12298. {
  12299. interLock.isUpdateFirmwareGoing = 1;
  12300. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12301. sleep(1);
  12302. }
  12303. else
  12304. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12305. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12306. return result;
  12307. }
  12308. void *UpdateFirmwareProcess(void *data)
  12309. {
  12310. pthread_detach(pthread_self());
  12311. mtrace();
  12312. int retriesInt =0, retryIntervalInt=0;
  12313. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12314. int port=0;
  12315. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12316. int isSuccess = 0;
  12317. char ftpbuf[512];
  12318. char temp[100];
  12319. char * pch;
  12320. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12321. json_object *UpdateFirmware;
  12322. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12323. if(!is_error(UpdateFirmware))
  12324. {
  12325. // Required data
  12326. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12327. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12328. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12329. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12330. // Optional data
  12331. if(json_object_object_get(UpdateFirmware, "retries"))
  12332. {
  12333. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12334. }
  12335. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12336. {
  12337. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12338. }
  12339. }
  12340. json_object_put(UpdateFirmware);
  12341. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12342. memset(path, 0, ARRAY_SIZE(path));
  12343. // Wait retrieveData
  12344. if(strlen(retrieveDatestr) > 10)
  12345. {
  12346. do
  12347. {
  12348. sleep(1);
  12349. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12350. }
  12351. // Ready to download
  12352. system("rm -f /mnt/*");
  12353. if(strncmp(locationstr,"http", 4) == 0)
  12354. {
  12355. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12356. sprintf(ftppath,"/%s", path);
  12357. DEBUG_INFO("locationstr: %s\n", locationstr);
  12358. DEBUG_INFO("protocol: %s\n",protocol);
  12359. DEBUG_INFO("host: %s\n",host);
  12360. DEBUG_INFO("path: %s\n",path);
  12361. DEBUG_INFO("ftppath: %s\n",ftppath);
  12362. int ftppathlen=strlen(ftppath);
  12363. int i=1;
  12364. char filenametemp[50];
  12365. while(i < ftppathlen)
  12366. {
  12367. int len=ftppathlen-i;
  12368. if(ftppath[len]== 47) // '/' ascll code: 47
  12369. {
  12370. DEBUG_INFO("compare '/' all right\n");
  12371. break;
  12372. }
  12373. i=i+1;
  12374. }
  12375. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12376. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12377. filenametemp[i+1] = 0;
  12378. do
  12379. {
  12380. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12381. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12382. sleep(1);
  12383. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12384. if(!isSuccess)
  12385. {
  12386. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12387. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12388. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12389. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12390. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12391. }
  12392. else
  12393. {
  12394. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12395. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12396. }
  12397. retriesInt--;
  12398. }while((isSuccess == 0)&&(retriesInt >= 0));
  12399. }
  12400. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12401. {
  12402. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12403. memset(temp, 0, ARRAY_SIZE(temp));
  12404. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12405. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12406. int ftppathlen=strlen(ftpbuf);
  12407. int i=1;
  12408. char filenametemp[50];
  12409. while(i < ftppathlen)
  12410. {
  12411. int len=ftppathlen-i;
  12412. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12413. {
  12414. DEBUG_INFO(" compare '/' all right\n");
  12415. break;
  12416. }
  12417. i=i+1;
  12418. }
  12419. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12420. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12421. filenametemp[i+1] = 0;
  12422. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12423. pch=strchr(temp,'@');
  12424. if(pch==NULL)
  12425. {
  12426. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12427. protocol, host, &port, path);
  12428. strcpy(user,"anonymous");
  12429. strcpy(password,"");
  12430. }
  12431. else
  12432. {
  12433. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12434. protocol, user, password, host, &port, path);
  12435. }
  12436. sscanf(host,"%[^/]%s",host1, path1);
  12437. sprintf(ftppath,"%s", path1);
  12438. //DEBUG_INFO("protocol =%s\n",protocol);
  12439. //DEBUG_INFO("user =%s\n",user);
  12440. //DEBUG_INFO("password =%s\n",password);
  12441. //DEBUG_INFO("host1 =%s\n",host1);
  12442. //DEBUG_INFO("port =%d\n",port);
  12443. //DEBUG_INFO("path1 =%s\n",path1);
  12444. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12445. //ftpFile(host, user, password, port, ftppath, fname);
  12446. //download firmware pthred
  12447. if(port == 0)
  12448. {
  12449. port = 21;
  12450. }
  12451. do
  12452. {
  12453. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12454. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12455. sleep(1);
  12456. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12457. if(!isSuccess)
  12458. {
  12459. //BulldogUtil.sleepMs(interval*1000);
  12460. DEBUG_INFO("Update firmware request and download file fail.\n");
  12461. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12462. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12463. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12464. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12465. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12466. }
  12467. else
  12468. {
  12469. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12470. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12471. }
  12472. retriesInt--;
  12473. }while((!isSuccess)&&(retriesInt >= 0));
  12474. }
  12475. else
  12476. {
  12477. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12478. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12479. sleep(1);
  12480. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12481. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12482. }
  12483. // OCPPPH only, must announce CSU upgrade firmware
  12484. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12485. interLock.isUpdateFirmwareGoing = 0;
  12486. pthread_exit(NULL);
  12487. }
  12488. int handleCertificateSignedRequest(char *uuid, char *payload)
  12489. {
  12490. mtrace();
  12491. int result = PASS;
  12492. json_object *CertificateSigned;
  12493. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12494. CertificateSigned = json_tokener_parse(payload);
  12495. if(!is_error(CertificateSigned))
  12496. {
  12497. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12498. }
  12499. json_object_put(CertificateSigned);
  12500. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12501. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12502. fclose(fp);
  12503. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12504. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12505. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12506. sendCertificateSignedConfirmation(uuid);
  12507. return result;
  12508. }
  12509. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12510. {
  12511. mtrace();
  12512. int result = PASS;
  12513. json_object *DeleteCertificate;
  12514. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12515. DeleteCertificate = json_tokener_parse(payload);
  12516. if(!is_error(DeleteCertificate))
  12517. {
  12518. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12519. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12520. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12521. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12522. }
  12523. json_object_put(DeleteCertificate);
  12524. /*
  12525. * TODO: Delete certificateSigned process
  12526. */
  12527. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12528. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12529. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12530. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12531. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12532. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12533. sendDeleteCertificateConfirmation(uuid);
  12534. return result;
  12535. }
  12536. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12537. {
  12538. mtrace();
  12539. int result = PASS;
  12540. json_object *ExtendedTriggerMessage;
  12541. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12542. ExtendedTriggerMessage = json_tokener_parse(payload);
  12543. if(!is_error(ExtendedTriggerMessage))
  12544. {
  12545. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12546. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12547. {
  12548. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12549. }
  12550. else
  12551. {
  12552. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12553. }
  12554. }
  12555. json_object_put(ExtendedTriggerMessage);
  12556. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12557. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12558. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12559. {
  12560. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12561. }
  12562. else
  12563. {
  12564. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12565. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12566. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12567. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12568. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12569. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12570. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12571. {
  12572. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12573. }
  12574. else
  12575. {
  12576. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12577. }
  12578. }
  12579. sendExtendedTriggerMessageConfirmation(uuid);
  12580. //==========================
  12581. // Trigger message
  12582. //==========================
  12583. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12584. {
  12585. //sendBootNotificationRequest();
  12586. server_sign = FALSE;
  12587. }
  12588. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12589. {
  12590. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12591. }
  12592. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12593. {
  12594. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12595. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12596. {
  12597. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12598. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12599. }
  12600. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12601. }
  12602. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12603. {
  12604. refreshStartTimer(&clientTime.Heartbeat);
  12605. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12606. }
  12607. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12608. {
  12609. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12610. {
  12611. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12612. }
  12613. else
  12614. {
  12615. for(int idx=0;idx< gunTotalNumber;idx++)
  12616. {
  12617. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12618. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12619. }
  12620. }
  12621. }
  12622. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12623. {
  12624. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12625. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12626. {
  12627. 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\" &");
  12628. }
  12629. }
  12630. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12631. {
  12632. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12633. {
  12634. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12635. }
  12636. else
  12637. {
  12638. for(int idx=0;idx< gunTotalNumber;idx++)
  12639. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12640. }
  12641. }
  12642. return result;
  12643. }
  12644. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12645. {
  12646. mtrace();
  12647. int result = PASS;
  12648. json_object *GetInstalledCertificateIds;
  12649. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12650. GetInstalledCertificateIds = json_tokener_parse(payload);
  12651. if(!is_error(GetInstalledCertificateIds))
  12652. {
  12653. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12654. }
  12655. json_object_put(GetInstalledCertificateIds);
  12656. /*
  12657. * TODO: Return installed certificate process
  12658. */
  12659. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12660. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12661. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12662. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12663. sendGetInstalledCertificateIdsConfirmation(uuid);
  12664. return result;
  12665. }
  12666. int handleGetLogRequest(char *uuid, char *payload)
  12667. {
  12668. mtrace();
  12669. int result = PASS;
  12670. json_object *GetLog;
  12671. DEBUG_INFO("handleGetLogRequest...\n");
  12672. GetLog = json_tokener_parse(payload);
  12673. if(!is_error(GetLog))
  12674. {
  12675. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12676. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12677. if(json_object_object_get(GetLog, "retries") != NULL)
  12678. {
  12679. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12680. }
  12681. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12682. {
  12683. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12684. }
  12685. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12686. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12687. {
  12688. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12689. }
  12690. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12691. {
  12692. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12693. }
  12694. }
  12695. json_object_put(GetLog);
  12696. /*
  12697. * TODO: Upload log process
  12698. */
  12699. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12700. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12701. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12702. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12703. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12704. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12705. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12706. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12707. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12708. sendGetLogConfirmation(uuid);
  12709. return result;
  12710. }
  12711. int handleInstallCertificateRequest(char *uuid, char *payload)
  12712. {
  12713. mtrace();
  12714. int result = PASS;
  12715. json_object *InstallCertificate;
  12716. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12717. InstallCertificate = json_tokener_parse(payload);
  12718. if(!is_error(InstallCertificate))
  12719. {
  12720. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12721. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12722. /*
  12723. * TODO: Install certificate process
  12724. */
  12725. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12726. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12727. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12728. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12729. sendInstallCertificateConfirmation(uuid);
  12730. }
  12731. json_object_put(InstallCertificate);
  12732. return result;
  12733. }
  12734. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12735. {
  12736. mtrace();
  12737. int result = PASS;
  12738. json_object *SignedUpdateFirmware;
  12739. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12740. SignedUpdateFirmware = json_tokener_parse(payload);
  12741. if(!is_error(SignedUpdateFirmware))
  12742. {
  12743. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12744. {
  12745. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12746. }
  12747. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12748. {
  12749. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12750. }
  12751. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12752. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12753. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12754. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12755. {
  12756. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12757. }
  12758. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12759. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12760. }
  12761. json_object_put(SignedUpdateFirmware);
  12762. /*
  12763. * TODO: Upgrade firmware process
  12764. */
  12765. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12766. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12767. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12768. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12769. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12770. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12771. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12772. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12773. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12774. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12775. sendInstallCertificateConfirmation(uuid);
  12776. return result;
  12777. }
  12778. int handleUnknownRequest(char *uuid, char *payload)
  12779. {
  12780. mtrace();
  12781. int result = PASS;
  12782. DEBUG_INFO("handleUnknownRequest...\n");
  12783. sendUnknownConfirmation(uuid);
  12784. result = PASS;
  12785. return result;
  12786. }
  12787. //==========================================
  12788. // Handle server response routine
  12789. //==========================================
  12790. void handleAuthorizeResponse(char *payload, int gun_index)
  12791. {
  12792. mtrace();
  12793. char expiryDatestr[30]={0};
  12794. char parentIdTagstr[20]={0};
  12795. char statusstr[20]={0};
  12796. int expiryDateISNULL=FALSE;
  12797. int parentIdTagISNULL=FALSE;
  12798. DEBUG_INFO("handleAuthorizeResponse...\n");
  12799. json_object *Authorize;
  12800. Authorize = json_tokener_parse(payload);
  12801. if(!is_error(Authorize))
  12802. {
  12803. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12804. {
  12805. // Required data
  12806. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12807. // Optional data
  12808. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12809. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12810. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12811. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12812. }
  12813. }
  12814. json_object_put(Authorize);
  12815. if(expiryDateISNULL == FALSE)
  12816. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12817. if(parentIdTagISNULL == FALSE)
  12818. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12819. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12820. //Update idTag information to authorization cache if supproted
  12821. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12822. {
  12823. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12824. }
  12825. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12826. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12827. authorizeRetryTimes = 0;
  12828. }
  12829. void handleBootNotificationResponse(char *payload, int gun_index)
  12830. {
  12831. mtrace();
  12832. char statusStr[12]={0};
  12833. char currentTimeStr[30]={0};
  12834. int intervalInt = 0;
  12835. DEBUG_INFO("handleBootNotificationResponse...\n");
  12836. json_object *BootNotification;
  12837. BootNotification = json_tokener_parse(payload);
  12838. if(!is_error(BootNotification))
  12839. {
  12840. // Required data
  12841. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12842. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12843. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12844. }
  12845. json_object_put(BootNotification);
  12846. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12847. BootNotificationInterval = intervalInt;
  12848. HeartBeatWaitTime = intervalInt;
  12849. //write back to ShmOCPP16DataPH->BootNotification
  12850. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12851. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12852. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12853. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12854. {
  12855. if((intervalInt == 0) || (intervalInt >= 10))
  12856. {
  12857. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12858. HeartBeatWaitTime = intervalInt;
  12859. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12860. }
  12861. server_sign = TRUE;
  12862. server_pending =FALSE;
  12863. }
  12864. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12865. {
  12866. server_pending = TRUE;
  12867. }
  12868. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12869. srand(time(NULL));
  12870. refreshStartTimer(&clientTime.Heartbeat);
  12871. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12872. SetOcppConnStatus(TRUE);
  12873. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12874. }
  12875. void handleDataTransferResponse(char *payload, int gun_index)
  12876. {
  12877. json_object *DataTransfer = json_tokener_parse(payload);
  12878. if(!is_error(DataTransfer))
  12879. {
  12880. // Required data
  12881. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  12882. // Optional data
  12883. if(json_object_object_get(DataTransfer, "data") != NULL)
  12884. {
  12885. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12886. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12887. if(!is_error(Data))
  12888. {
  12889. if(json_object_object_get(Data, "msgId") != NULL)
  12890. {
  12891. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  12892. {
  12893. 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")));
  12894. }
  12895. }
  12896. }
  12897. json_object_put(Data);
  12898. }
  12899. }
  12900. json_object_put(DataTransfer);
  12901. }
  12902. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12903. {
  12904. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12905. //struct json_object *obj;
  12906. // obj = json_tokener_parse(payload);
  12907. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12908. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12909. //No fields are defined.
  12910. }
  12911. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12912. {
  12913. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12914. //struct json_object *obj;
  12915. // obj = json_tokener_parse(payload);
  12916. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12917. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12918. //No fields are defined.
  12919. }
  12920. void handleHeartbeatResponse(char *payload, int gun_index)
  12921. {
  12922. mtrace();
  12923. DEBUG_INFO("handleHeartbeatResponse...\n");
  12924. json_object *Heartbeat;
  12925. Heartbeat = json_tokener_parse(payload);
  12926. if(!is_error(Heartbeat))
  12927. {
  12928. // Required data
  12929. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12930. }
  12931. json_object_put(Heartbeat);
  12932. if(FirstHeartBeat == 0)
  12933. {
  12934. FirstHeartBeat = 1;
  12935. DEBUG_INFO("FirstHeartBeat \n");
  12936. }
  12937. HeartBeatWithNOResponse = 0;
  12938. refreshStartTimer(&clientTime.Heartbeat);
  12939. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12940. }
  12941. void handleMeterValuesResponse(char *payload, int gun_index)
  12942. {
  12943. mtrace();
  12944. DEBUG_INFO("handleMeterValuesResponse...\n");
  12945. isQueueSendable = 1;
  12946. }
  12947. void handleStartTransactionResponse(char *payload, int gun_index)
  12948. {
  12949. mtrace();
  12950. //int transactionIdInt = 0;
  12951. FILE *outfile;
  12952. char data[100]={0};
  12953. DEBUG_INFO("handleStartTransactionResponse...\n");
  12954. json_object *StartTransaction;
  12955. StartTransaction = json_tokener_parse(payload);
  12956. if(!is_error(StartTransaction))
  12957. {
  12958. // Required data
  12959. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12960. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12961. // Optional data
  12962. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12963. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12964. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12965. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12966. }
  12967. json_object_put(StartTransaction);
  12968. isQueueSendable = 1;
  12969. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12970. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12971. //-----------Start : write to the Queue TransactionId file -----------------//
  12972. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12973. {}
  12974. else
  12975. {
  12976. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12977. if(log == NULL)
  12978. {
  12979. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12980. return ;
  12981. }
  12982. else
  12983. {
  12984. fclose(log);
  12985. }
  12986. }
  12987. // open file for writing
  12988. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12989. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12990. {
  12991. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12992. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12993. fputs(data, outfile);
  12994. fclose (outfile);
  12995. }
  12996. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12997. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12998. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12999. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13000. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13001. }
  13002. void handleStatusNotificationResponse(char *payload, int gun_index)
  13003. {
  13004. mtrace();
  13005. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13006. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13007. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13008. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13009. }
  13010. void handleStopTransactionnResponse(char *payload, int gun_index)
  13011. {
  13012. mtrace();
  13013. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13014. json_object *StopTransaction;
  13015. StopTransaction = json_tokener_parse(payload);
  13016. if(!is_error(StopTransaction))
  13017. {
  13018. // Optional data
  13019. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13020. {
  13021. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13022. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13023. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13024. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13025. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13026. }
  13027. }
  13028. json_object_put(StopTransaction);
  13029. isQueueSendable = 1;
  13030. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13031. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13032. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13033. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13034. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13035. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13036. }
  13037. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13038. {
  13039. mtrace();
  13040. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13041. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13042. }
  13043. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13044. {
  13045. mtrace();
  13046. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13047. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13048. }
  13049. void handleSignCertificateResponse(char *payload, int gun_index)
  13050. {
  13051. mtrace();
  13052. DEBUG_INFO("handleSignCertificateResponse...\n");
  13053. json_object *SignCertificate;
  13054. SignCertificate = json_tokener_parse(payload);
  13055. if(!is_error(SignCertificate))
  13056. {
  13057. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13058. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13059. }
  13060. json_object_put(SignCertificate);
  13061. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13062. }
  13063. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13064. {
  13065. mtrace();
  13066. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13067. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13068. }
  13069. //==========================================
  13070. // Handle Error routine
  13071. //==========================================
  13072. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13073. {
  13074. mtrace();
  13075. #ifdef SystemLogMessage
  13076. DEBUG_INFO("errorCode: %s\n", errorCode);
  13077. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13078. DEBUG_INFO("errorDetails: %s\n", payload);
  13079. #endif
  13080. }
  13081. //===============================================
  13082. // Common routine
  13083. //===============================================
  13084. int initialConfigurationTable(void)
  13085. {
  13086. //clock_t start_t, end_t, total_t;
  13087. FILE *fp;
  13088. FILE *outfile;
  13089. char str[512]={0};
  13090. char sstr[256]={0};
  13091. int c = 0;
  13092. char *loc;
  13093. int confVersion = 12;
  13094. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13095. //start_t = clock();
  13096. //printf("Starting of the program, start_t = %ld\n", start_t);
  13097. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13098. // Check configuration file size is correct
  13099. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13100. {
  13101. struct stat st;
  13102. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13103. if(st.st_size < 3100)
  13104. {
  13105. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13106. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13107. }
  13108. }
  13109. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13110. {
  13111. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13112. if(outfile == NULL)
  13113. {
  13114. DEBUG_INFO("Error opening file\n");
  13115. return FALSE;
  13116. }
  13117. /*Core Profile*/
  13118. //AllowOfflineTxForUnknownId
  13119. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13123. //AuthorizationCacheEnabled
  13124. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13128. //AuthorizeRemoteTxRequests
  13129. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13133. //BlinkRepeat
  13134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13138. //ClockAlignedDataInterval
  13139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13143. //ConnectionTimeOut
  13144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13148. //GetConfigurationMaxKeys
  13149. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13151. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13153. // HeartbeatInterval
  13154. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13158. // LightIntensity
  13159. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13163. // LocalAuthorizeOffline
  13164. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13166. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13168. // LocalPreAuthorize
  13169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13173. // MaxEnergyOnInvalidId
  13174. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13178. // MeterValuesAlignedData
  13179. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13180. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13182. 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" );
  13183. else
  13184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13186. // MeterValuesAlignedDataMaxLength
  13187. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13191. else
  13192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13194. // MeterValuesSampledData
  13195. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13198. 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" );
  13199. else
  13200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13202. // MeterValuesSampledDataMaxLength
  13203. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13205. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13207. else
  13208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13210. // MeterValueSampleInterval
  13211. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13215. // MinimumStatusDuration
  13216. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13219. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13221. // NumberOfConnectors
  13222. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13223. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13225. {
  13226. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13227. }
  13228. else
  13229. {
  13230. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13231. }
  13232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13233. // ResetRetries
  13234. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13236. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13238. // ConnectorPhaseRotation
  13239. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13243. // ConnectorPhaseRotationMaxLength
  13244. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13245. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13246. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13248. // StopTransactionOnEVSideDisconnect
  13249. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13250. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13251. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13253. // StopTransactionOnInvalidId
  13254. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13258. // StopTxnAlignedData
  13259. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13261. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13263. // StopTxnAlignedDataMaxLength
  13264. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13266. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13268. // StopTxnSampledData
  13269. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13271. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13272. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13273. else
  13274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13276. // StopTxnSampledDataMaxLength
  13277. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13278. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13280. {
  13281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13282. }
  13283. else
  13284. {
  13285. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13286. }
  13287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13288. // SupportedFeatureProfiles
  13289. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13293. // SupportedFeatureProfilesMaxLength
  13294. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13298. // TransactionMessageAttempts
  13299. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13301. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13302. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13304. // TransactionMessageRetryInterval
  13305. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13308. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13310. // UnlockConnectorOnEVSideDisconnect
  13311. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13313. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13315. // WebSocketPingInterval
  13316. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13317. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13320. // QueueOffLineMeterValues
  13321. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13322. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13325. // AuthorizationKey
  13326. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13327. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13330. // SecurityProfile
  13331. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13333. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13335. // DefaultPrice
  13336. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13340. // CustomDisplayCostAndPrice
  13341. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13345. // CustomIdleFeeAfterStop
  13346. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13350. // SystemUptimeSec
  13351. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13355. // FreeVend
  13356. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13358. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13360. // OcppServer
  13361. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13363. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13365. // MaintainServer
  13366. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13367. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13368. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13370. // StatusNotificationPeriodically
  13371. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13373. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13375. // StatusNotificationInterval
  13376. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13377. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13380. // Configuration Version
  13381. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13383. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13385. //* Local Auth List Management Profile*/
  13386. #if 0
  13387. //For OCTT Test Case
  13388. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13390. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13391. #endif
  13392. #if 1
  13393. //LocalAuthListEnabled
  13394. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13395. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13396. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13398. #endif
  13399. //LocalAuthListMaxLength
  13400. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13401. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13402. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13404. //SendLocalListMaxLength
  13405. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13406. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13407. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13409. //ReserveConnectorZeroSupported
  13410. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13414. //* Smart Charging Profile */
  13415. //ChargeProfileMaxStackLevel
  13416. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13418. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13420. // ChargingScheduleAllowedChargingRateUnit
  13421. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13425. // ChargingScheduleMaxPeriods
  13426. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13428. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13430. // ConnectorSwitch3to1PhaseSupported
  13431. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13433. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13435. // MaxChargingProfilesInstalled
  13436. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13437. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13440. fclose(outfile);
  13441. }
  13442. else
  13443. {
  13444. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13445. char keystr[60]={0};
  13446. char readonlystr[10]={0};
  13447. char valuestr[256]={0};
  13448. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13449. if(fp == NULL) {
  13450. DEBUG_INFO("Error opening file");
  13451. return FALSE;
  13452. }
  13453. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13454. {
  13455. //DEBUG_INFO("Get Configuration \n");
  13456. if(strlen(str) > 0)
  13457. {
  13458. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13459. //*************************key*********************************/
  13460. if(strstr(str, "key") != NULL)
  13461. {
  13462. loc = strstr(str, "key");
  13463. c = 0;
  13464. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13465. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13466. {
  13467. sstr[c] = loc[strlen("key")+3+c];
  13468. c++;
  13469. }
  13470. sstr[c] = '\0';
  13471. strcpy(keystr,sstr);
  13472. }
  13473. //*************************readonly*********************************/
  13474. if(strstr(str, "readonly") != NULL)
  13475. {
  13476. loc = strstr(str, "readonly");
  13477. c = 0;
  13478. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13479. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13480. {
  13481. sstr[c] = loc[strlen("readonly")+2+c];
  13482. c++;
  13483. }
  13484. sstr[c] = '\0';
  13485. strcpy(readonlystr,sstr);
  13486. }
  13487. //*************************value*********************************/
  13488. if(strstr(str, "value") != NULL)
  13489. {
  13490. loc = strstr(str, "value");
  13491. c = 0;
  13492. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13493. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13494. {
  13495. sstr[c] = loc[strlen("value")+3+c];
  13496. c++;
  13497. }
  13498. sstr[c] = '\0';
  13499. strcpy(valuestr,sstr);
  13500. }
  13501. // DEBUG_INFO("keystr=%s\n",keystr);
  13502. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13503. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13504. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13505. {
  13506. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13507. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13508. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13509. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13510. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13511. }
  13512. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13513. {
  13514. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13515. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13516. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13517. }
  13518. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13519. {
  13520. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13521. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13522. }
  13523. if(strcmp(keystr, "BlinkRepeat") == 0)
  13524. {
  13525. //Charger.BlinkRepeat = Integer.parseInt(value);
  13526. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13527. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13528. }
  13529. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13530. {
  13531. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13532. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13533. }
  13534. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13535. {
  13536. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13537. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13538. }
  13539. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13540. {
  13541. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13542. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13543. }
  13544. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13545. {
  13546. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13547. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13548. HeartBeatWaitTime = atoi(valuestr);
  13549. }
  13550. if(strcmp(keystr, "LightIntensity") == 0)
  13551. {
  13552. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13553. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13554. }
  13555. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13556. {
  13557. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13558. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13559. }
  13560. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13561. {
  13562. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13563. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13564. }
  13565. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13566. {
  13567. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13568. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13569. }
  13570. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13571. {
  13572. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13573. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13574. }
  13575. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13576. {
  13577. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13578. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13579. }
  13580. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13581. {
  13582. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13583. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13584. }
  13585. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13586. {
  13587. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13588. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13589. }
  13590. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13591. {
  13592. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13593. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13594. }
  13595. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13596. {
  13597. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13598. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13599. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13600. }
  13601. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13602. {
  13603. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13604. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13605. }
  13606. if(strcmp(keystr, "ResetRetries") == 0)
  13607. {
  13608. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13609. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13610. }
  13611. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13612. {
  13613. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13614. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13615. }
  13616. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13617. {
  13618. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13619. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13620. }
  13621. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13622. {
  13623. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13624. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13625. }
  13626. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13627. {
  13628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13629. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13630. }
  13631. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13632. {
  13633. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13635. }
  13636. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13637. {
  13638. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13639. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13640. }
  13641. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13642. {
  13643. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13644. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13645. }
  13646. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13647. {
  13648. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13649. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13650. }
  13651. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13652. {
  13653. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13654. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13655. }
  13656. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13657. {
  13658. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13659. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13660. }
  13661. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13662. {
  13663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13664. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13665. TransactionMessageAttemptsValue = atoi(valuestr);
  13666. }
  13667. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13668. {
  13669. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13670. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13671. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13672. }
  13673. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13674. {
  13675. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13676. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13677. }
  13678. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13679. {
  13680. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13681. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13682. }
  13683. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13684. {
  13685. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13686. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13687. }
  13688. if(strcmp(keystr, "AuthorizationKey") == 0)
  13689. {
  13690. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13691. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13692. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13693. }
  13694. if(strcmp(keystr, "SecurityProfile") == 0)
  13695. {
  13696. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13697. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13698. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13699. }
  13700. if(strcmp(keystr, "DefaultPrice") == 0)
  13701. {
  13702. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13703. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13704. }
  13705. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13706. {
  13707. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13708. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13709. }
  13710. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13711. {
  13712. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13713. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13714. }
  13715. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13716. {
  13717. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13718. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13719. }
  13720. if(strcmp(keystr, "FreeVend") == 0)
  13721. {
  13722. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13723. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13724. }
  13725. if(strcmp(keystr, "OcppServer") == 0)
  13726. {
  13727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13728. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13729. }
  13730. if(strcmp(keystr, "MaintainServer") == 0)
  13731. {
  13732. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13733. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13734. }
  13735. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  13736. {
  13737. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13738. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  13739. }
  13740. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  13741. {
  13742. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13743. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  13744. }
  13745. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13746. {
  13747. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13748. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13749. }
  13750. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13751. {
  13752. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13753. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13754. }
  13755. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13756. {
  13757. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13758. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13759. }
  13760. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13761. {
  13762. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13763. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13764. }
  13765. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13766. {
  13767. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13768. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13769. }
  13770. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13771. {
  13772. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13773. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13774. }
  13775. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13776. {
  13777. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13778. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13779. }
  13780. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13781. {
  13782. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13784. }
  13785. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13786. {
  13787. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13788. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13789. }
  13790. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13791. {
  13792. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13793. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13794. }
  13795. }
  13796. }
  13797. fclose(fp);
  13798. }
  13799. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13800. {
  13801. return PASS;
  13802. }
  13803. else
  13804. {
  13805. return FAIL;
  13806. }
  13807. }
  13808. void StoreConfigurationTable(void)
  13809. {
  13810. FILE *outfile;
  13811. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13812. if(outfile == NULL)
  13813. {
  13814. DEBUG_INFO("Error opening file");
  13815. return ;
  13816. }
  13817. /*Core Profile*/
  13818. //AllowOfflineTxForUnknownId
  13819. /*
  13820. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13821. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13822. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13823. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13824. */
  13825. //DEBUG_INFO("data=%s\n",data);
  13826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13827. //AuthorizationCacheEnabled
  13828. /*
  13829. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13832. */
  13833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13834. //AuthorizeRemoteTxRequests
  13835. /*
  13836. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13838. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13839. */
  13840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13841. //BlinkRepeat
  13842. /*
  13843. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13846. */
  13847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13848. //ClockAlignedDataInterval
  13849. /*
  13850. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13853. */
  13854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13855. //ConnectionTimeOut
  13856. /*
  13857. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13860. */
  13861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13862. //GetConfigurationMaxKeys
  13863. /*
  13864. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13867. */
  13868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13869. // HeartbeatInterval
  13870. /*
  13871. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13874. */
  13875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13876. // LightIntensity
  13877. /*
  13878. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13879. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13881. */
  13882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13883. // LocalAuthorizeOffline
  13884. /*
  13885. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13888. */
  13889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13890. // LocalPreAuthorize
  13891. /*
  13892. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13893. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13895. */
  13896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13897. // MaxEnergyOnInvalidId
  13898. /*
  13899. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13900. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13902. */
  13903. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13905. // MeterValuesAlignedData
  13906. /*
  13907. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13908. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13909. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13910. */
  13911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13912. // MeterValuesAlignedDataMaxLength
  13913. /*
  13914. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13917. */
  13918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13919. // MeterValuesSampledData
  13920. /*
  13921. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13922. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13923. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13924. */
  13925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13926. // MeterValuesSampledDataMaxLength
  13927. /*
  13928. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13929. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13930. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13931. */
  13932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13933. // MeterValueSampleInterval
  13934. /*
  13935. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13938. */
  13939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13940. // MinimumStatusDuration
  13941. /*
  13942. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13944. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13945. */
  13946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13947. // NumberOfConnectors
  13948. /*
  13949. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13951. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13952. {
  13953. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13954. }
  13955. else
  13956. {
  13957. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13958. }
  13959. */
  13960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13961. // ResetRetries
  13962. /*
  13963. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13966. */
  13967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13968. // ConnectorPhaseRotation
  13969. /*
  13970. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13972. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13973. */
  13974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13975. // ConnectorPhaseRotationMaxLength
  13976. /*
  13977. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13979. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13980. */
  13981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13982. // StopTransactionOnEVSideDisconnect
  13983. /*
  13984. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13987. */
  13988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13989. // StopTransactionOnInvalidId
  13990. /*
  13991. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13993. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13994. */
  13995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13996. // StopTxnAlignedData
  13997. /*
  13998. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14001. */
  14002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14003. // StopTxnAlignedDataMaxLength
  14004. /*
  14005. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14008. */
  14009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14010. // StopTxnSampledData
  14011. /*
  14012. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14014. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14015. */
  14016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14017. // StopTxnSampledDataMaxLength
  14018. /*
  14019. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14020. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14022. */
  14023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14024. // SupportedFeatureProfiles
  14025. /*
  14026. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14027. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14029. */
  14030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14031. // SupportedFeatureProfilesMaxLength
  14032. /*
  14033. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14034. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14036. */
  14037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14038. // TransactionMessageAttempts
  14039. /*
  14040. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14041. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14043. */
  14044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14045. // TransactionMessageRetryInterval
  14046. /*
  14047. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14050. */
  14051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14052. // UnlockConnectorOnEVSideDisconnect
  14053. /*
  14054. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14057. */
  14058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14059. // WebSocketPingInterval
  14060. /*
  14061. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14064. */
  14065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14066. // QueueOffLineMeterValues
  14067. /*
  14068. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14069. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14070. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14071. */
  14072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14073. // AuthorizationKey
  14074. /*
  14075. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14076. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14078. */
  14079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14080. // SecurityProfile
  14081. /*
  14082. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14085. */
  14086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14087. // DefaultPrice
  14088. /*
  14089. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14090. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14092. */
  14093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14094. // CustomDisplayCostAndPrice
  14095. /*
  14096. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14098. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14099. */
  14100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14101. // CustomIdleFeeAfterStop
  14102. /*
  14103. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14104. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14106. */
  14107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14108. // SystemUptimeSec
  14109. /*
  14110. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14111. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14113. */
  14114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14115. // FreeVend
  14116. /*
  14117. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14120. */
  14121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14122. // OcppServer
  14123. /*
  14124. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14127. */
  14128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14129. // MaintainServer
  14130. /*
  14131. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14132. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14133. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14134. */
  14135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14136. // StatusNotificationPeriodically
  14137. /*
  14138. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14141. */
  14142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14143. // StatusNotificationInterval
  14144. /*
  14145. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14147. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14148. */
  14149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14150. // ConfigurationVersion
  14151. /*
  14152. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14153. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14155. */
  14156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14157. //* Local Auth List Management Profile*/
  14158. //LocalAuthListEnabled
  14159. /*
  14160. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14162. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14163. */
  14164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14165. //LocalAuthListMaxLength
  14166. /*
  14167. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14170. */
  14171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14172. //SendLocalListMaxLength
  14173. /*
  14174. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14177. */
  14178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14179. //ReserveConnectorZeroSupported
  14180. /*
  14181. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14183. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14184. */
  14185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14186. //* Smart Charging Profile */
  14187. //ChargeProfileMaxStackLevel
  14188. /*
  14189. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14192. */
  14193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14194. // ChargingScheduleAllowedChargingRateUnit
  14195. /*
  14196. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14199. */
  14200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14201. // ChargingScheduleMaxPeriods
  14202. /*
  14203. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14206. */
  14207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14208. // ConnectorSwitch3to1PhaseSupported
  14209. /*
  14210. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14213. */
  14214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14215. // MaxChargingProfilesInstalled
  14216. /*
  14217. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14220. */
  14221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14222. fclose(outfile);
  14223. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14224. }
  14225. void getKeyValue(char *keyReq)
  14226. {
  14227. int isEmpty = FALSE;
  14228. int isKnowKey = FALSE;
  14229. DEBUG_INFO("keyReq = %s\n", keyReq);
  14230. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14231. isEmpty = TRUE;
  14232. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14233. {
  14234. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14235. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14236. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14237. {
  14238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14239. }
  14240. else
  14241. {
  14242. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14243. }
  14244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14245. isKnowKey = TRUE;
  14246. }
  14247. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14248. {
  14249. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14251. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14252. {
  14253. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14254. }
  14255. else
  14256. {
  14257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14258. }
  14259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14260. isKnowKey = TRUE;
  14261. }
  14262. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14263. {
  14264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14266. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14267. {
  14268. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14269. }
  14270. else
  14271. {
  14272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14273. }
  14274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14275. isKnowKey = TRUE;
  14276. }
  14277. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14278. {
  14279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14281. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14282. {
  14283. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14284. }
  14285. else
  14286. {
  14287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14288. }
  14289. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14290. isKnowKey = TRUE;
  14291. }
  14292. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14293. {
  14294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14296. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14297. {
  14298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14299. }
  14300. else
  14301. {
  14302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14303. }
  14304. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14305. isKnowKey = TRUE;
  14306. }
  14307. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14308. {
  14309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14311. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14312. {
  14313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14314. }
  14315. else
  14316. {
  14317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14318. }
  14319. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14320. isKnowKey = TRUE;
  14321. }
  14322. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14323. {
  14324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14326. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14327. {
  14328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14329. }
  14330. else
  14331. {
  14332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14333. }
  14334. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14335. isKnowKey = TRUE;
  14336. }
  14337. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14338. {
  14339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14341. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14342. {
  14343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14344. }
  14345. else
  14346. {
  14347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14348. }
  14349. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14350. isKnowKey = TRUE;
  14351. }
  14352. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14353. {
  14354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14356. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14357. {
  14358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14359. }
  14360. else
  14361. {
  14362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14363. }
  14364. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14365. isKnowKey = TRUE;
  14366. }
  14367. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14368. {
  14369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14371. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14372. {
  14373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14374. }
  14375. else
  14376. {
  14377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14378. }
  14379. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14380. isKnowKey = TRUE;
  14381. }
  14382. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14383. {
  14384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14386. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14387. {
  14388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14389. }
  14390. else
  14391. {
  14392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14393. }
  14394. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14395. isKnowKey = TRUE;
  14396. }
  14397. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14398. {
  14399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14401. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14402. {
  14403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14404. }
  14405. else
  14406. {
  14407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14408. }
  14409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14410. isKnowKey = TRUE;
  14411. }
  14412. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14413. {
  14414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14416. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14417. {
  14418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14419. }
  14420. else
  14421. {
  14422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14423. }
  14424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14425. isKnowKey = TRUE;
  14426. }
  14427. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14428. {
  14429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14431. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14432. {
  14433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14434. }
  14435. else
  14436. {
  14437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14438. }
  14439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14440. isKnowKey = TRUE;
  14441. }
  14442. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14443. {
  14444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14446. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14447. {
  14448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14449. }
  14450. else
  14451. {
  14452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14453. }
  14454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14455. isKnowKey = TRUE;
  14456. }
  14457. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14458. {
  14459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14461. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14462. {
  14463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14464. }
  14465. else
  14466. {
  14467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14468. }
  14469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14470. isKnowKey = TRUE;
  14471. }
  14472. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14473. {
  14474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14476. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14477. {
  14478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14479. }
  14480. else
  14481. {
  14482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14483. }
  14484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14485. isKnowKey = TRUE;
  14486. }
  14487. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14488. {
  14489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14490. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14491. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14492. {
  14493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14494. }
  14495. else
  14496. {
  14497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14498. }
  14499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14500. isKnowKey = TRUE;
  14501. }
  14502. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14503. {
  14504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14505. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14506. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14507. {
  14508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14509. }
  14510. else
  14511. {
  14512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14513. }
  14514. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14516. isKnowKey = TRUE;
  14517. }
  14518. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14519. {
  14520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14522. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14523. {
  14524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14525. }
  14526. else
  14527. {
  14528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14529. }
  14530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14531. isKnowKey = TRUE;
  14532. }
  14533. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14534. {
  14535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14537. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14538. {
  14539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14540. }
  14541. else
  14542. {
  14543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14544. }
  14545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14546. isKnowKey = TRUE;
  14547. }
  14548. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14549. {
  14550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14552. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14553. {
  14554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14555. }
  14556. else
  14557. {
  14558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14559. }
  14560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14561. isKnowKey = TRUE;
  14562. }
  14563. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14564. {
  14565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14567. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14568. {
  14569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14570. }
  14571. else
  14572. {
  14573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14574. }
  14575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14576. isKnowKey = TRUE;
  14577. }
  14578. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14579. {
  14580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14582. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14583. {
  14584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14585. }
  14586. else
  14587. {
  14588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14589. }
  14590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14591. isKnowKey = TRUE;
  14592. }
  14593. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14594. {
  14595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14597. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14598. {
  14599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14600. }
  14601. else
  14602. {
  14603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14604. }
  14605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14606. isKnowKey = TRUE;
  14607. }
  14608. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14609. {
  14610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14612. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14613. {
  14614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14615. }
  14616. else
  14617. {
  14618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14619. }
  14620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14621. isKnowKey = TRUE;
  14622. }
  14623. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14624. {
  14625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14626. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14627. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14628. {
  14629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14630. }
  14631. else
  14632. {
  14633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14634. }
  14635. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14636. isKnowKey = TRUE;
  14637. }
  14638. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14639. {
  14640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14641. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14642. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14643. {
  14644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14645. }
  14646. else
  14647. {
  14648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14649. }
  14650. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14651. isKnowKey = TRUE;
  14652. }
  14653. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14654. {
  14655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14656. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14657. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14658. {
  14659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14660. }
  14661. else
  14662. {
  14663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14664. }
  14665. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14666. isKnowKey = TRUE;
  14667. }
  14668. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14669. {
  14670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14671. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14672. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14673. {
  14674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14675. }
  14676. else
  14677. {
  14678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14679. }
  14680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14681. isKnowKey = TRUE;
  14682. }
  14683. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14684. {
  14685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14686. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14687. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14688. {
  14689. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14690. }
  14691. else
  14692. {
  14693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14694. }
  14695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14696. isKnowKey = TRUE;
  14697. }
  14698. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14699. {
  14700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14702. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14703. {
  14704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14705. }
  14706. else
  14707. {
  14708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14709. }
  14710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14711. isKnowKey = TRUE;
  14712. }
  14713. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14714. {
  14715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14717. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14718. {
  14719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14720. }
  14721. else
  14722. {
  14723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14724. }
  14725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14726. isKnowKey = TRUE;
  14727. }
  14728. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14729. {
  14730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14732. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14733. {
  14734. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14735. }
  14736. else
  14737. {
  14738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14739. }
  14740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14741. isKnowKey = TRUE;
  14742. }
  14743. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14744. {
  14745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14747. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14748. {
  14749. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14750. }
  14751. else
  14752. {
  14753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14754. }
  14755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14756. isKnowKey = TRUE;
  14757. }
  14758. /*
  14759. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14760. {
  14761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14763. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14764. {
  14765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14766. }
  14767. else
  14768. {
  14769. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14770. }
  14771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14772. isKnowKey = TRUE;
  14773. }*/
  14774. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14775. {
  14776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14778. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14779. {
  14780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14781. }
  14782. else
  14783. {
  14784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14785. }
  14786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14787. isKnowKey = TRUE;
  14788. }
  14789. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14790. {
  14791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14793. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14794. {
  14795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14796. }
  14797. else
  14798. {
  14799. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14800. }
  14801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14802. isKnowKey = TRUE;
  14803. }
  14804. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14805. {
  14806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14808. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14809. {
  14810. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14811. }
  14812. else
  14813. {
  14814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14815. }
  14816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14817. isKnowKey = TRUE;
  14818. }
  14819. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14820. {
  14821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14823. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14824. {
  14825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14826. }
  14827. else
  14828. {
  14829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14830. }
  14831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14832. isKnowKey = TRUE;
  14833. }
  14834. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14835. {
  14836. struct sysinfo s_info;
  14837. int error = sysinfo(&s_info);
  14838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14839. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14840. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14841. {
  14842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14843. }
  14844. else
  14845. {
  14846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14847. }
  14848. if(error != 0)
  14849. {
  14850. DEBUG_WARN("System uptime get error: %d\n", error);
  14851. }
  14852. else
  14853. {
  14854. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14855. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14856. }
  14857. isKnowKey = TRUE;
  14858. }
  14859. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14860. {
  14861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14862. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14863. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14864. {
  14865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14866. }
  14867. else
  14868. {
  14869. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14870. }
  14871. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14872. isKnowKey = TRUE;
  14873. }
  14874. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  14875. {
  14876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  14877. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  14878. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  14879. {
  14880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  14881. }
  14882. else
  14883. {
  14884. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  14885. }
  14886. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14887. isKnowKey = TRUE;
  14888. }
  14889. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  14890. {
  14891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  14892. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  14893. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  14894. {
  14895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  14896. }
  14897. else
  14898. {
  14899. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  14900. }
  14901. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14902. isKnowKey = TRUE;
  14903. }
  14904. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  14905. {
  14906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  14907. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  14908. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  14909. {
  14910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  14911. }
  14912. else
  14913. {
  14914. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  14915. }
  14916. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  14917. isKnowKey = TRUE;
  14918. }
  14919. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  14920. {
  14921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  14922. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  14923. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  14924. {
  14925. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  14926. }
  14927. else
  14928. {
  14929. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  14930. }
  14931. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  14932. isKnowKey = TRUE;
  14933. }
  14934. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14935. {
  14936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14937. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14938. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14939. {
  14940. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14941. }
  14942. else
  14943. {
  14944. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14945. }
  14946. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14947. isKnowKey = TRUE;
  14948. }
  14949. #if 1
  14950. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14951. {
  14952. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14954. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14955. {
  14956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14957. }
  14958. else
  14959. {
  14960. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14961. }
  14962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14963. isKnowKey = TRUE;
  14964. }
  14965. #endif
  14966. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14967. {
  14968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14969. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14970. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14971. {
  14972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14973. }
  14974. else
  14975. {
  14976. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14977. }
  14978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14979. isKnowKey = TRUE;
  14980. }
  14981. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14982. {
  14983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14984. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14985. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14986. {
  14987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14988. }
  14989. else
  14990. {
  14991. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14992. }
  14993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14994. isKnowKey = TRUE;
  14995. }
  14996. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14997. {
  14998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15000. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15001. {
  15002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15003. }
  15004. else
  15005. {
  15006. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15007. }
  15008. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15009. isKnowKey = TRUE;
  15010. }
  15011. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15012. {
  15013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15015. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15016. {
  15017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15018. }
  15019. else
  15020. {
  15021. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15022. }
  15023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15024. isKnowKey = TRUE;
  15025. }
  15026. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15027. {
  15028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15030. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15031. {
  15032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15033. }
  15034. else
  15035. {
  15036. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15037. }
  15038. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15039. isKnowKey = TRUE;
  15040. }
  15041. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15042. {
  15043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15045. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15046. {
  15047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15048. }
  15049. else
  15050. {
  15051. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15052. }
  15053. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15054. isKnowKey = TRUE;
  15055. }
  15056. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15057. {
  15058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15059. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15060. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15061. {
  15062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15063. }
  15064. else
  15065. {
  15066. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15067. }
  15068. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15069. isKnowKey = TRUE;
  15070. }
  15071. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15072. {
  15073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15074. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15075. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15076. {
  15077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15078. }
  15079. else
  15080. {
  15081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15082. }
  15083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15084. isKnowKey = TRUE;
  15085. }
  15086. //=========================================================
  15087. if(!isEmpty && !isKnowKey)
  15088. {
  15089. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15090. strcpy(unknownkey[UnknownKeynum], keyReq);
  15091. UnknownKeynum = UnknownKeynum + 1;
  15092. }
  15093. }
  15094. void processUnkownKey(void)
  15095. {
  15096. DEBUG_INFO("processUnkownKey...\n");
  15097. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15098. for(int index=0; index < UnknownKeynum; index++)
  15099. {
  15100. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15101. {
  15102. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15103. }
  15104. }
  15105. }
  15106. int setKeyValue(char *key, char *value)
  15107. {
  15108. int isSuccess = NotSupported;
  15109. int check_ascii=0;
  15110. char str[501]={0};
  15111. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15112. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15113. {
  15114. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15115. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15116. {
  15117. strcpy(str, (const char*)value);
  15118. for(int i = 0; str[i]; i++){
  15119. str[i] = tolower(str[i]);
  15120. }
  15121. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15122. isSuccess = ConfigurationStatus_Accepted;
  15123. }
  15124. else
  15125. {
  15126. isSuccess = ConfigurationStatus_Rejected;
  15127. }
  15128. }
  15129. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15130. {
  15131. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15132. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15133. {
  15134. strcpy(str, (const char*)value);
  15135. for(int i = 0; str[i]; i++){
  15136. str[i] = tolower(str[i]);
  15137. }
  15138. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15139. isSuccess = ConfigurationStatus_Accepted;
  15140. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15141. }
  15142. else
  15143. {
  15144. isSuccess = ConfigurationStatus_Rejected;
  15145. }
  15146. }
  15147. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15148. {
  15149. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15150. {
  15151. strcpy(str, (const char*)value);
  15152. for(int i = 0; str[i]; i++)
  15153. {
  15154. str[i] = tolower(str[i]);
  15155. }
  15156. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15157. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15158. isSuccess = ConfigurationStatus_Accepted;
  15159. }
  15160. else
  15161. {
  15162. isSuccess = ConfigurationStatus_Rejected;
  15163. }
  15164. }
  15165. if(strcmp(key, "BlinkRepeat") == 0)
  15166. {
  15167. //Charger.BlinkRepeat = Integer.parseInt(value);
  15168. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15169. {
  15170. check_ascii = value[0];
  15171. if( (check_ascii < 48) || (check_ascii > 57) )
  15172. {
  15173. isSuccess = ConfigurationStatus_Rejected;
  15174. }
  15175. else
  15176. {
  15177. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15178. isSuccess = ConfigurationStatus_Accepted;
  15179. }
  15180. }
  15181. else
  15182. {
  15183. isSuccess = ConfigurationStatus_Rejected;
  15184. }
  15185. }
  15186. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15187. {
  15188. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15189. {
  15190. check_ascii = value[0];
  15191. if( (check_ascii < 48) || (check_ascii > 57) )
  15192. {
  15193. isSuccess = ConfigurationStatus_Rejected;
  15194. }
  15195. else
  15196. {
  15197. if((atoi(value) == 0) || (atoi(value) >= 5))
  15198. {
  15199. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15200. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15201. isSuccess = ConfigurationStatus_Accepted;
  15202. }
  15203. else
  15204. isSuccess = ConfigurationStatus_Rejected;
  15205. }
  15206. }
  15207. else
  15208. {
  15209. isSuccess = ConfigurationStatus_Rejected;
  15210. }
  15211. }
  15212. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15213. {
  15214. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15215. {
  15216. check_ascii = value[0];
  15217. if( (check_ascii < 48) || (check_ascii > 57) )
  15218. {
  15219. isSuccess = ConfigurationStatus_Rejected;
  15220. }
  15221. else
  15222. {
  15223. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15224. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15225. isSuccess = ConfigurationStatus_Accepted;
  15226. }
  15227. }
  15228. else
  15229. {
  15230. isSuccess = ConfigurationStatus_Rejected;
  15231. }
  15232. }
  15233. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15234. {
  15235. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15236. {
  15237. check_ascii = value[0];
  15238. if( (check_ascii < 48) || (check_ascii > 57) )
  15239. {
  15240. isSuccess = ConfigurationStatus_Rejected;
  15241. }
  15242. else
  15243. {
  15244. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15245. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15246. isSuccess = ConfigurationStatus_Accepted;
  15247. }
  15248. }
  15249. else
  15250. {
  15251. isSuccess = ConfigurationStatus_Rejected;
  15252. }
  15253. }
  15254. if(strcmp(key, "HeartbeatInterval") == 0)
  15255. {
  15256. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].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. if((atoi(value) == 0) || (atoi(value) >= 10))
  15266. {
  15267. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15268. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15269. HeartBeatWaitTime = atoi(value);
  15270. isSuccess = ConfigurationStatus_Accepted;
  15271. }
  15272. else
  15273. {
  15274. isSuccess = ConfigurationStatus_Rejected;
  15275. }
  15276. }
  15277. }
  15278. else
  15279. {
  15280. isSuccess = ConfigurationStatus_Rejected;
  15281. }
  15282. }
  15283. if(strcmp(key, "LightIntensity") == 0)
  15284. {
  15285. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15286. {
  15287. check_ascii = value[0];
  15288. if( (check_ascii < 48) || (check_ascii > 57) )
  15289. {
  15290. isSuccess = ConfigurationStatus_Rejected;
  15291. }
  15292. else
  15293. {
  15294. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15295. isSuccess = ConfigurationStatus_Accepted;
  15296. }
  15297. }
  15298. else
  15299. {
  15300. isSuccess = ConfigurationStatus_Rejected;
  15301. }
  15302. }
  15303. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15304. {
  15305. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15306. {
  15307. strcpy(str, (const char*)value);
  15308. for(int i = 0; str[i]; i++)
  15309. {
  15310. str[i] = tolower(str[i]);
  15311. }
  15312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15313. isSuccess = ConfigurationStatus_Accepted;
  15314. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15315. }
  15316. else
  15317. {
  15318. isSuccess = ConfigurationStatus_Rejected;
  15319. }
  15320. }
  15321. if(strcmp(key, "LocalPreAuthorize") == 0)
  15322. {
  15323. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15324. {
  15325. strcpy(str, (const char*)value);
  15326. for(int i = 0; str[i]; i++)
  15327. {
  15328. str[i] = tolower(str[i]);
  15329. }
  15330. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15331. isSuccess = ConfigurationStatus_Accepted;
  15332. }
  15333. else
  15334. {
  15335. isSuccess = ConfigurationStatus_Rejected;
  15336. }
  15337. }
  15338. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15339. {
  15340. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15341. {
  15342. check_ascii = value[0];
  15343. if( (check_ascii < 48) || (check_ascii > 57) )
  15344. {
  15345. isSuccess = ConfigurationStatus_Rejected;
  15346. }
  15347. else
  15348. {
  15349. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15350. isSuccess = ConfigurationStatus_Accepted;
  15351. }
  15352. }
  15353. else
  15354. {
  15355. isSuccess = ConfigurationStatus_Rejected;
  15356. }
  15357. }
  15358. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15359. {
  15360. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15361. {
  15362. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15363. isSuccess = ConfigurationStatus_Accepted;
  15364. }
  15365. else
  15366. {
  15367. isSuccess = ConfigurationStatus_Rejected;
  15368. }
  15369. }
  15370. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15371. {
  15372. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15373. {
  15374. check_ascii = value[0];
  15375. if( (check_ascii < 48) || (check_ascii > 57) )
  15376. {
  15377. isSuccess = ConfigurationStatus_Rejected;
  15378. }
  15379. else
  15380. {
  15381. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15382. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15383. isSuccess = ConfigurationStatus_Accepted;
  15384. }
  15385. }
  15386. else
  15387. {
  15388. isSuccess = ConfigurationStatus_Rejected;
  15389. }
  15390. }
  15391. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15392. {
  15393. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15394. {
  15395. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15396. isSuccess = ConfigurationStatus_Accepted;
  15397. }
  15398. else
  15399. {
  15400. isSuccess = ConfigurationStatus_Rejected;
  15401. }
  15402. }
  15403. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15404. {
  15405. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15406. {
  15407. check_ascii = value[0];
  15408. if( (check_ascii < 48) || (check_ascii > 57) )
  15409. {
  15410. isSuccess = ConfigurationStatus_Rejected;
  15411. }
  15412. else
  15413. {
  15414. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15415. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15416. isSuccess = ConfigurationStatus_Accepted;
  15417. }
  15418. }
  15419. else
  15420. {
  15421. isSuccess = ConfigurationStatus_Rejected;
  15422. }
  15423. }
  15424. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15425. {
  15426. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15427. {
  15428. check_ascii = value[0];
  15429. if( (check_ascii < 48) || (check_ascii > 57) )
  15430. {
  15431. isSuccess = ConfigurationStatus_Rejected;
  15432. }
  15433. else
  15434. {
  15435. if((atoi(value) == 0) || (atoi(value) >= 3))
  15436. {
  15437. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15438. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15439. isSuccess = ConfigurationStatus_Accepted;
  15440. }
  15441. else
  15442. {
  15443. isSuccess = ConfigurationStatus_Rejected;
  15444. }
  15445. }
  15446. }
  15447. else
  15448. {
  15449. isSuccess = ConfigurationStatus_Rejected;
  15450. }
  15451. }
  15452. if(strcmp(key, "MinimumStatusDuration") == 0)
  15453. {
  15454. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15455. {
  15456. check_ascii = value[0];
  15457. if( (check_ascii < 48) || (check_ascii > 57) )
  15458. {
  15459. isSuccess = ConfigurationStatus_Rejected;
  15460. }
  15461. else
  15462. {
  15463. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15464. {
  15465. isSuccess = ConfigurationStatus_Rejected;
  15466. }
  15467. else
  15468. {
  15469. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15470. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15471. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15472. isSuccess = ConfigurationStatus_Accepted;
  15473. }
  15474. }
  15475. }
  15476. else
  15477. {
  15478. isSuccess = ConfigurationStatus_Rejected;
  15479. }
  15480. }
  15481. if(strcmp(key, "NumberOfConnectors") == 0)
  15482. {
  15483. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15484. {
  15485. check_ascii = value[0];
  15486. if( (check_ascii < 48) || (check_ascii > 57) )
  15487. {
  15488. isSuccess = ConfigurationStatus_Rejected;
  15489. }
  15490. else
  15491. {
  15492. //Charger.ResetRetries = Integer.parseInt(value);
  15493. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15494. isSuccess = ConfigurationStatus_Accepted;
  15495. }
  15496. }
  15497. else
  15498. {
  15499. isSuccess = ConfigurationStatus_Rejected;
  15500. }
  15501. }
  15502. if(strcmp(key, "ResetRetries") == 0)
  15503. {
  15504. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15505. {
  15506. check_ascii = value[0];
  15507. if( (check_ascii < 48) || (check_ascii > 57) )
  15508. {
  15509. isSuccess = ConfigurationStatus_Rejected;
  15510. }
  15511. else
  15512. {
  15513. //Charger.ResetRetries = Integer.parseInt(value);
  15514. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15515. isSuccess = ConfigurationStatus_Accepted;
  15516. }
  15517. }
  15518. else
  15519. {
  15520. isSuccess = ConfigurationStatus_Rejected;
  15521. }
  15522. }
  15523. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15524. {
  15525. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15526. {
  15527. strcpy(str, (const char*)value);
  15528. for(int i = 0; str[i]; i++)
  15529. {
  15530. str[i] = tolower(str[i]);
  15531. }
  15532. if(strcmp(str, "notapplicable")== 0)
  15533. {
  15534. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15535. isSuccess = ConfigurationStatus_Accepted;
  15536. }
  15537. else if(strcmp(str, "unknown")== 0)
  15538. {
  15539. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15540. isSuccess = ConfigurationStatus_Accepted;
  15541. }
  15542. else if(strcmp(str, "rst")== 0)
  15543. {
  15544. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15545. isSuccess = ConfigurationStatus_Accepted;
  15546. }
  15547. else if(strcmp(str, "rts")== 0)
  15548. {
  15549. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15550. isSuccess = ConfigurationStatus_Accepted;
  15551. }
  15552. else if(strcmp(str, "srt")== 0)
  15553. {
  15554. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15555. isSuccess = ConfigurationStatus_Accepted;
  15556. }
  15557. else if(strcmp(str, "str")== 0)
  15558. {
  15559. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15560. isSuccess = ConfigurationStatus_Accepted;
  15561. }
  15562. else if(strcmp(str, "trs")== 0)
  15563. {
  15564. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15565. isSuccess = ConfigurationStatus_Accepted;
  15566. }
  15567. else if(strcmp(str, "tsr")== 0)
  15568. {
  15569. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15570. isSuccess = ConfigurationStatus_Accepted;
  15571. }
  15572. else
  15573. {
  15574. isSuccess = ConfigurationStatus_Rejected;
  15575. }
  15576. }
  15577. else
  15578. {
  15579. isSuccess = ConfigurationStatus_Rejected;
  15580. }
  15581. }
  15582. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15583. {
  15584. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15585. {
  15586. check_ascii = value[0];
  15587. if( (check_ascii < 48) || (check_ascii > 57) )
  15588. {
  15589. isSuccess = ConfigurationStatus_Rejected;
  15590. }
  15591. else
  15592. {
  15593. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15594. isSuccess = ConfigurationStatus_Accepted;
  15595. }
  15596. }
  15597. else
  15598. {
  15599. isSuccess = ConfigurationStatus_Rejected;
  15600. }
  15601. }
  15602. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15603. {
  15604. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15605. {
  15606. strcpy(str, (const char*)value);
  15607. for(int i = 0; str[i]; i++)
  15608. {
  15609. str[i] = tolower(str[i]);
  15610. }
  15611. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15612. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15613. isSuccess = ConfigurationStatus_Accepted;
  15614. }
  15615. else
  15616. {
  15617. isSuccess = ConfigurationStatus_Rejected;
  15618. }
  15619. }
  15620. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15621. {
  15622. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15623. {
  15624. strcpy(str, (const char*)value);
  15625. for(int i = 0; str[i]; i++)
  15626. {
  15627. str[i] = tolower(str[i]);
  15628. }
  15629. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15630. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15631. isSuccess = ConfigurationStatus_Accepted;
  15632. }
  15633. else
  15634. {
  15635. isSuccess = ConfigurationStatus_Rejected;
  15636. }
  15637. }
  15638. if(strcmp(key, "StopTxnAlignedData") == 0)
  15639. {
  15640. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15641. {
  15642. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15643. isSuccess = ConfigurationStatus_Accepted;
  15644. }
  15645. else
  15646. {
  15647. isSuccess = ConfigurationStatus_Rejected;
  15648. }
  15649. }
  15650. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15651. {
  15652. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15653. {
  15654. check_ascii = value[0];
  15655. if( (check_ascii < 48) || (check_ascii > 57) )
  15656. {
  15657. isSuccess = ConfigurationStatus_Rejected;
  15658. }
  15659. else
  15660. {
  15661. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15662. isSuccess = ConfigurationStatus_Accepted;
  15663. }
  15664. }
  15665. else
  15666. {
  15667. isSuccess = ConfigurationStatus_Rejected;
  15668. }
  15669. }
  15670. if(strcmp(key, "StopTxnSampledData") == 0)
  15671. {
  15672. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15673. {
  15674. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15675. isSuccess = ConfigurationStatus_Accepted;
  15676. }
  15677. else
  15678. {
  15679. isSuccess = ConfigurationStatus_Rejected;
  15680. }
  15681. }
  15682. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15683. {
  15684. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15685. {
  15686. check_ascii = value[0];
  15687. if( (check_ascii < 48) || (check_ascii > 57) )
  15688. {
  15689. isSuccess = ConfigurationStatus_Rejected;
  15690. }
  15691. else
  15692. {
  15693. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15694. isSuccess = ConfigurationStatus_Accepted;
  15695. }
  15696. }
  15697. else
  15698. {
  15699. isSuccess = ConfigurationStatus_Rejected;
  15700. }
  15701. }
  15702. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15703. {
  15704. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15705. {
  15706. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15707. isSuccess = ConfigurationStatus_Accepted;
  15708. }
  15709. else
  15710. {
  15711. isSuccess = ConfigurationStatus_Rejected;
  15712. }
  15713. }
  15714. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15715. {
  15716. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15717. {
  15718. check_ascii = value[0];
  15719. if( (check_ascii < 48) || (check_ascii > 57) )
  15720. {
  15721. isSuccess = ConfigurationStatus_Rejected;
  15722. }
  15723. else
  15724. {
  15725. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15726. isSuccess = ConfigurationStatus_Accepted;
  15727. }
  15728. }
  15729. else
  15730. {
  15731. isSuccess = ConfigurationStatus_Rejected;
  15732. }
  15733. }
  15734. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15735. {
  15736. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15737. {
  15738. check_ascii = value[0];
  15739. if( (check_ascii < 48) || (check_ascii > 57) )
  15740. {
  15741. isSuccess = ConfigurationStatus_Rejected;
  15742. }
  15743. else
  15744. {
  15745. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15746. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15747. TransactionMessageAttemptsValue = atoi(value);
  15748. isSuccess = ConfigurationStatus_Accepted;
  15749. }
  15750. }
  15751. else
  15752. {
  15753. isSuccess = ConfigurationStatus_Rejected;
  15754. }
  15755. }
  15756. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15757. {
  15758. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15759. {
  15760. check_ascii = value[0];
  15761. if( (check_ascii < 48) || (check_ascii > 57) )
  15762. {
  15763. isSuccess = ConfigurationStatus_Rejected;
  15764. }
  15765. else
  15766. {
  15767. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15768. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15769. TransactionMessageRetryIntervalValue = atoi(value);
  15770. isSuccess = ConfigurationStatus_Accepted;
  15771. }
  15772. }
  15773. else
  15774. {
  15775. isSuccess = ConfigurationStatus_Rejected;
  15776. }
  15777. }
  15778. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15779. {
  15780. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15781. {
  15782. strcpy(str, (const char*)value);
  15783. for(int i = 0; str[i]; i++)
  15784. {
  15785. str[i] = tolower(str[i]);
  15786. }
  15787. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15788. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15789. isSuccess = ConfigurationStatus_Accepted;
  15790. }
  15791. else
  15792. {
  15793. isSuccess = ConfigurationStatus_Rejected;
  15794. }
  15795. }
  15796. if(strcmp(key, "WebSocketPingInterval") == 0)
  15797. {
  15798. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15799. {
  15800. check_ascii = value[0];
  15801. if( (check_ascii < 48) || (check_ascii > 57) )
  15802. {
  15803. isSuccess = ConfigurationStatus_Rejected;
  15804. }
  15805. else
  15806. {
  15807. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15808. isSuccess = ConfigurationStatus_Accepted;
  15809. if((atoi(value) == 0) || (atoi(value) >= 10))
  15810. {
  15811. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15812. isSuccess = ConfigurationStatus_Accepted;
  15813. }
  15814. else
  15815. isSuccess = ConfigurationStatus_Rejected;
  15816. }
  15817. }
  15818. else
  15819. {
  15820. isSuccess = ConfigurationStatus_Rejected;
  15821. }
  15822. }
  15823. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15824. {
  15825. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15826. {
  15827. strcpy(str, (const char*)value);
  15828. for(int i = 0; str[i]; i++)
  15829. {
  15830. str[i] = tolower(str[i]);
  15831. }
  15832. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15833. isSuccess = ConfigurationStatus_Accepted;
  15834. }
  15835. else
  15836. {
  15837. isSuccess = ConfigurationStatus_Rejected;
  15838. }
  15839. }
  15840. if(strcmp(key, "AuthorizationKey") == 0)
  15841. {
  15842. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15843. {
  15844. strcpy(str, (const char*)value);
  15845. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15846. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15847. isSuccess = ConfigurationStatus_Accepted;
  15848. }
  15849. else
  15850. {
  15851. isSuccess = ConfigurationStatus_Rejected;
  15852. }
  15853. }
  15854. if(strcmp(key, "SecurityProfile") == 0)
  15855. {
  15856. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15857. {
  15858. check_ascii = value[0];
  15859. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15860. {
  15861. isSuccess = ConfigurationStatus_Rejected;
  15862. }
  15863. else if(check_ascii == 0x33)
  15864. {
  15865. isSuccess = NotSupported;
  15866. }
  15867. else
  15868. {
  15869. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15870. {
  15871. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15872. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  15873. isSuccess = ConfigurationStatus_Accepted;
  15874. }
  15875. else
  15876. isSuccess = ConfigurationStatus_Rejected;
  15877. }
  15878. }
  15879. else
  15880. {
  15881. isSuccess = ConfigurationStatus_Rejected;
  15882. }
  15883. }
  15884. if(strcmp(key, "DefaultPrice") == 0)
  15885. {
  15886. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15887. {
  15888. strcpy(str, (const char*)value);
  15889. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15890. isSuccess = ConfigurationStatus_Accepted;
  15891. }
  15892. else
  15893. {
  15894. isSuccess = ConfigurationStatus_Rejected;
  15895. }
  15896. }
  15897. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15898. {
  15899. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15900. {
  15901. strcpy(str, (const char*)value);
  15902. for(int i = 0; str[i]; i++)
  15903. {
  15904. str[i] = tolower(str[i]);
  15905. }
  15906. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15907. isSuccess = ConfigurationStatus_Accepted;
  15908. }
  15909. else
  15910. {
  15911. isSuccess = ConfigurationStatus_Rejected;
  15912. }
  15913. }
  15914. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15915. {
  15916. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15917. {
  15918. strcpy(str, (const char*)value);
  15919. for(int i = 0; str[i]; i++)
  15920. {
  15921. str[i] = tolower(str[i]);
  15922. }
  15923. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15924. isSuccess = ConfigurationStatus_Accepted;
  15925. }
  15926. else
  15927. {
  15928. isSuccess = ConfigurationStatus_Rejected;
  15929. }
  15930. }
  15931. if(strcmp(key, "SystemUptimeSec") == 0)
  15932. {
  15933. isSuccess = NotSupported;
  15934. }
  15935. if(strcmp(key, "FreeVend") == 0)
  15936. {
  15937. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15938. {
  15939. strcpy(str, (const char*)value);
  15940. for(int i = 0; str[i]; i++)
  15941. {
  15942. str[i] = tolower(str[i]);
  15943. }
  15944. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15945. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15946. isSuccess = ConfigurationStatus_Accepted;
  15947. }
  15948. else
  15949. {
  15950. isSuccess = ConfigurationStatus_Rejected;
  15951. }
  15952. }
  15953. if(strcmp(key, "OcppServer") == 0)
  15954. {
  15955. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15956. {
  15957. strcpy(str, (const char*)value);
  15958. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  15959. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  15960. isSuccess = ConfigurationStatus_Accepted;
  15961. }
  15962. else
  15963. {
  15964. isSuccess = ConfigurationStatus_Rejected;
  15965. }
  15966. }
  15967. if(strcmp(key, "MaintainServer") == 0)
  15968. {
  15969. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15970. {
  15971. strcpy(str, (const char*)value);
  15972. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  15973. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  15974. isSuccess = ConfigurationStatus_Accepted;
  15975. }
  15976. else
  15977. {
  15978. isSuccess = ConfigurationStatus_Rejected;
  15979. }
  15980. }
  15981. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  15982. {
  15983. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15984. {
  15985. strcpy(str, (const char*)value);
  15986. for(int i = 0; str[i]; i++)
  15987. {
  15988. str[i] = tolower(str[i]);
  15989. }
  15990. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  15991. isSuccess = ConfigurationStatus_Accepted;
  15992. }
  15993. else
  15994. {
  15995. isSuccess = ConfigurationStatus_Rejected;
  15996. }
  15997. }
  15998. if(strcmp(key, "StatusNotificationInterval") == 0)
  15999. {
  16000. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16001. {
  16002. check_ascii = value[0];
  16003. if( (check_ascii < 48) || (check_ascii > 57) )
  16004. {
  16005. isSuccess = ConfigurationStatus_Rejected;
  16006. }
  16007. else
  16008. {
  16009. if((atoi(value) == 0) || (atoi(value) >= 10))
  16010. {
  16011. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16012. isSuccess = ConfigurationStatus_Accepted;
  16013. }
  16014. else
  16015. isSuccess = ConfigurationStatus_Rejected;
  16016. }
  16017. }
  16018. else
  16019. {
  16020. isSuccess = ConfigurationStatus_Rejected;
  16021. }
  16022. }
  16023. #if 0
  16024. //For OCPP Test Case
  16025. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16026. {
  16027. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16028. {
  16029. strcpy(str, (const char*)value);
  16030. for(int i = 0; str[i]; i++)
  16031. {
  16032. str[i] = tolower(str[i]);
  16033. }
  16034. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16035. isSuccess = ConfigurationStatus_Accepted;
  16036. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16037. }
  16038. else
  16039. {
  16040. isSuccess = ConfigurationStatus_Rejected;
  16041. }
  16042. }
  16043. #endif
  16044. #if 1
  16045. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16046. {
  16047. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16048. {
  16049. strcpy(str, (const char*)value);
  16050. for(int i = 0; str[i]; i++)
  16051. {
  16052. str[i] = tolower(str[i]);
  16053. }
  16054. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16055. isSuccess = ConfigurationStatus_Accepted;
  16056. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16057. }
  16058. else
  16059. {
  16060. isSuccess = ConfigurationStatus_Rejected;
  16061. }
  16062. }
  16063. #endif
  16064. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16065. {
  16066. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16067. {
  16068. check_ascii = value[0];
  16069. if( (check_ascii < 48) || (check_ascii > 57) )
  16070. {
  16071. isSuccess = ConfigurationStatus_Rejected;
  16072. }
  16073. else
  16074. {
  16075. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16076. isSuccess = ConfigurationStatus_Accepted;
  16077. }
  16078. }
  16079. else
  16080. {
  16081. isSuccess = ConfigurationStatus_Rejected;
  16082. }
  16083. }
  16084. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16085. {
  16086. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16087. {
  16088. check_ascii = value[0];
  16089. if( (check_ascii < 48) || (check_ascii > 57) )
  16090. {
  16091. isSuccess = ConfigurationStatus_Rejected;
  16092. }
  16093. else
  16094. {
  16095. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16096. isSuccess = ConfigurationStatus_Accepted;
  16097. }
  16098. }
  16099. else
  16100. {
  16101. isSuccess = ConfigurationStatus_Rejected;
  16102. }
  16103. }
  16104. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16105. {
  16106. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16107. {
  16108. strcpy(str, (const char*)value);
  16109. for(int i = 0; str[i]; i++)
  16110. {
  16111. str[i] = tolower(str[i]);
  16112. }
  16113. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16114. isSuccess = ConfigurationStatus_Accepted;
  16115. }
  16116. else
  16117. {
  16118. isSuccess = ConfigurationStatus_Rejected;
  16119. }
  16120. }
  16121. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16122. {
  16123. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16124. {
  16125. check_ascii = value[0];
  16126. if( (check_ascii < 48) || (check_ascii > 57) )
  16127. {
  16128. isSuccess = ConfigurationStatus_Rejected;
  16129. }
  16130. else
  16131. {
  16132. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16133. isSuccess = ConfigurationStatus_Accepted;
  16134. }
  16135. }
  16136. else
  16137. {
  16138. isSuccess = ConfigurationStatus_Rejected;
  16139. }
  16140. }
  16141. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16142. {
  16143. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16144. {
  16145. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16146. isSuccess = ConfigurationStatus_Accepted;
  16147. }
  16148. else
  16149. {
  16150. isSuccess = ConfigurationStatus_Rejected;
  16151. }
  16152. }
  16153. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16154. {
  16155. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16156. {
  16157. check_ascii = value[0];
  16158. if( (check_ascii < 48) || (check_ascii > 57) )
  16159. {
  16160. isSuccess = ConfigurationStatus_Rejected;
  16161. }
  16162. else
  16163. {
  16164. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16165. isSuccess = ConfigurationStatus_Accepted;
  16166. }
  16167. }
  16168. else
  16169. {
  16170. isSuccess = ConfigurationStatus_Rejected;
  16171. }
  16172. }
  16173. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16174. {
  16175. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16176. {
  16177. strcpy(str, (const char*)value);
  16178. for(int i = 0; str[i]; i++)
  16179. {
  16180. str[i] = tolower(str[i]);
  16181. }
  16182. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16183. isSuccess = ConfigurationStatus_Accepted;
  16184. }
  16185. else
  16186. {
  16187. isSuccess = ConfigurationStatus_Rejected;
  16188. }
  16189. }
  16190. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16191. {
  16192. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16193. {
  16194. check_ascii = value[0];
  16195. if( (check_ascii < 48) || (check_ascii > 57) )
  16196. {
  16197. isSuccess = ConfigurationStatus_Rejected;
  16198. }
  16199. else
  16200. {
  16201. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16202. isSuccess = ConfigurationStatus_Accepted;
  16203. }
  16204. }
  16205. else
  16206. {
  16207. isSuccess = ConfigurationStatus_Rejected;
  16208. }
  16209. }
  16210. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16211. return isSuccess;
  16212. }
  16213. int TransactionMessageAttemptsGet(void)
  16214. {
  16215. return TransactionMessageAttemptsValue;
  16216. }
  16217. int FirstHeartBeatResponse(void)
  16218. {
  16219. return FirstHeartBeat;
  16220. }
  16221. int TransactionMessageRetryIntervalGet(void)
  16222. {
  16223. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16224. }
  16225. int ReadHttpStatus(int sock)
  16226. {
  16227. //char c;
  16228. char buff[1024]="",*ptr=buff+1;
  16229. int bytes_received, status;
  16230. DEBUG_INFO("Begin Response ..\n");
  16231. while((bytes_received = recv(sock, ptr, 1, 0))){
  16232. if(bytes_received==-1){
  16233. perror("ReadHttpStatus");
  16234. exit(1);
  16235. }
  16236. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16237. ptr++;
  16238. }
  16239. *ptr=0;
  16240. ptr=buff+1;
  16241. sscanf(ptr,"%*s %d ", &status);
  16242. DEBUG_INFO("%s\n",ptr);
  16243. DEBUG_INFO("status=%d\n",status);
  16244. DEBUG_INFO("End Response ..\n");
  16245. return (bytes_received>0)?status:0;
  16246. }
  16247. //the only filed that it parsed is 'Content-Length'
  16248. int ParseHeader(int sock)
  16249. {
  16250. //char c;
  16251. char buff[1024]="",*ptr=buff+4;
  16252. int bytes_received;
  16253. DEBUG_INFO("Begin HEADER ..\n");
  16254. while((bytes_received = recv(sock, ptr, 1, 0))){
  16255. if(bytes_received==-1){
  16256. perror("Parse Header");
  16257. exit(1);
  16258. }
  16259. if(
  16260. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16261. (ptr[-1]=='\r') && (*ptr=='\n' )
  16262. ) break;
  16263. ptr++;
  16264. }
  16265. *ptr=0;
  16266. ptr=buff+4;
  16267. //printf("%s",ptr);
  16268. if(bytes_received){
  16269. ptr=strstr(ptr,"Content-Length:");
  16270. if(ptr){
  16271. sscanf(ptr,"%*s %d",&bytes_received);
  16272. }else
  16273. bytes_received=-1; //unknown size
  16274. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16275. }
  16276. DEBUG_INFO("End HEADER ..\n");
  16277. return bytes_received ;
  16278. }
  16279. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16280. {
  16281. int result = TRUE;
  16282. char rmFileCmd[100]={0};
  16283. char FilePath[100]={0};
  16284. char ftpbuf[200];
  16285. int systemresult;
  16286. sprintf(FilePath,"/mnt/%s",filename);
  16287. system("ping 8.8.8.8 &");
  16288. if((access(FilePath,F_OK))!=-1)
  16289. {
  16290. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16291. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16292. system(rmFileCmd);
  16293. }
  16294. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16295. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16296. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16297. systemresult = system(ftpbuf);
  16298. if(systemresult != 0)
  16299. {
  16300. DEBUG_INFO("http DownLoad error!\n");
  16301. result = FALSE;
  16302. }
  16303. system("pkill ping");
  16304. return result;
  16305. }
  16306. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16307. {
  16308. int result = TRUE;
  16309. char rmFileCmd[100]={0};
  16310. char FilePath[100]={0};
  16311. char ftpbuf[200];
  16312. int systemresult;
  16313. sprintf(FilePath,"/mnt/%s",filename);
  16314. system("ping 8.8.8.8 &");
  16315. if((access(FilePath,F_OK))!=-1)
  16316. {
  16317. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16318. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16319. system(rmFileCmd);
  16320. }
  16321. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16322. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16323. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16324. systemresult = system(ftpbuf);
  16325. if(systemresult != 0)
  16326. {
  16327. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16328. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16329. systemresult = system(ftpbuf);
  16330. if(systemresult != 0)
  16331. {
  16332. DEBUG_WARN("wget error!\n");
  16333. result = FALSE;
  16334. }
  16335. }
  16336. system("pkill ping");
  16337. return result;
  16338. }
  16339. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16340. {
  16341. char rmFileCmd[100]={0};
  16342. char FilePath[100]={0};
  16343. char buf[512];
  16344. int systemresult = 0;
  16345. //DEBUG_INFO("filename=%s\n",filename);
  16346. //DEBUG_INFO("url=%s\n",url);
  16347. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16348. if((access(FilePath,F_OK))!=-1)
  16349. {
  16350. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16351. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16352. system(rmFileCmd);
  16353. }
  16354. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16355. if(fp == NULL)
  16356. {
  16357. DEBUG_INFO("log is NULL\n");
  16358. return FALSE;
  16359. }
  16360. else
  16361. {
  16362. fprintf(fp, "%s\n", url);
  16363. fprintf(fp, "%s\n", filename);
  16364. fclose(fp);
  16365. }
  16366. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16367. if(phpFP == NULL)
  16368. {
  16369. DEBUG_INFO("PHP upload fail.\n");
  16370. return FALSE;
  16371. }
  16372. else
  16373. {
  16374. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16375. {
  16376. if(strstr(buf, "result") != NULL)
  16377. {
  16378. sscanf(buf, "result: %d", &systemresult);
  16379. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16380. }
  16381. }
  16382. pclose(phpFP);
  16383. }
  16384. if(systemresult != 1)
  16385. {
  16386. DEBUG_INFO("HTTP upload error!\n");
  16387. return FALSE;
  16388. }
  16389. return TRUE;
  16390. }
  16391. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16392. {
  16393. int result = FALSE;
  16394. char ftpbuf[200];
  16395. int systemresult;
  16396. /*
  16397. // Domaind name transfer to IP address
  16398. struct hostent* server;
  16399. char *IPbuffer;
  16400. server = gethostbyname(location);
  16401. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16402. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16403. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16404. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16405. systemresult = system(ftpbuf);
  16406. if(systemresult != 0)
  16407. {
  16408. DEBUG_INFO("ftpput error!\n");
  16409. }
  16410. else
  16411. {
  16412. result = TRUE;
  16413. DEBUG_INFO("ftpput OK!\n");
  16414. }
  16415. return result;
  16416. }
  16417. int GetOcppServerURL()
  16418. {
  16419. int result = FALSE;
  16420. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16421. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16422. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16423. struct yuarel url;
  16424. char urlStr[512];
  16425. // OCPPPH only
  16426. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16427. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16428. {
  16429. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16430. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16431. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16432. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16433. if(yuarel_parse(&url, urlStr) != -1)
  16434. {
  16435. sprintf(OcppProtocol, "%s", url.scheme);
  16436. sprintf(OcppHost, "%s", url.host);
  16437. if(url.path == NULL)
  16438. OcppTempPath[0] = '\0';
  16439. else
  16440. sprintf(OcppTempPath, "%s", url.path);
  16441. if(url.port == 0)
  16442. {
  16443. if(strcmp(OcppProtocol, "wss") == 0)
  16444. OcppPort = 443;
  16445. else
  16446. OcppPort = 80;
  16447. }
  16448. else
  16449. OcppPort = url.port;
  16450. result = TRUE;
  16451. }
  16452. }
  16453. else
  16454. {
  16455. strcpy(OcppHost,"");
  16456. }
  16457. return result;
  16458. }
  16459. int GetOcppPath()
  16460. {
  16461. int result = FALSE;
  16462. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16463. {
  16464. if(OcppTempPath == NULL)
  16465. {
  16466. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16467. }
  16468. else
  16469. {
  16470. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16471. }
  16472. result = TRUE;
  16473. goto End;
  16474. }
  16475. else
  16476. {
  16477. strcpy(OcppPath,"");
  16478. }
  16479. End:
  16480. return result;
  16481. }
  16482. int GetOcppPort()
  16483. {
  16484. return OcppPort;
  16485. }
  16486. int GetOcppConnStatus(void)
  16487. {
  16488. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16489. }
  16490. void SetOcppConnStatus(uint8_t status)
  16491. {
  16492. ShmOCPP16DataPH->OcppConnStatus = status;
  16493. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16494. }
  16495. int GetHeartBeatWithNOResponse(void)
  16496. {
  16497. return HeartBeatWithNOResponse;
  16498. }
  16499. void SetHeartBeatWithNOResponse(void)
  16500. {
  16501. HeartBeatWithNOResponse = 0;
  16502. }
  16503. void GetStartTransactionIdTag(int gun_index)
  16504. {
  16505. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16506. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16507. }
  16508. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16509. {
  16510. char ch;
  16511. FILE *fptr1;
  16512. int temptransactionId;
  16513. char str[100]={0};
  16514. temptransactionId = 0;
  16515. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16516. {
  16517. DEBUG_INFO("IdTag is empty.\n");
  16518. return temptransactionId;
  16519. }
  16520. /*------ Read the file ----------------*/
  16521. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16522. if (!fptr1)
  16523. {
  16524. DEBUG_INFO("QueueTransactionId file open error.\n");
  16525. //printf(" File not found or unable to open the input file!!\n");
  16526. return temptransactionId;
  16527. }
  16528. ch=fgetc(fptr1);
  16529. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16530. rewind(fptr1);
  16531. if(ch!=EOF)
  16532. {
  16533. // printf("%c",ch);
  16534. while (fgets(str, 100, fptr1) != NULL)
  16535. {
  16536. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16537. if(str[0]=='\0')
  16538. {
  16539. break;
  16540. }
  16541. char *revbuf[8] = {0}; // Variable store string split
  16542. int num = 0;// Quantity after string split
  16543. DEBUG_INFO("Transaction queue data= %s\n", str);
  16544. splitstring(str,",",revbuf,&num); // String split
  16545. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16546. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16547. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16548. DEBUG_INFO("------------------------------\n");
  16549. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16550. {
  16551. if(isStopTransaction)
  16552. {
  16553. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16554. {
  16555. temptransactionId = atoi(revbuf[2]);
  16556. //break;
  16557. }
  16558. }
  16559. else
  16560. {
  16561. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16562. {
  16563. temptransactionId = atoi(revbuf[2]);
  16564. //break;
  16565. }
  16566. }
  16567. }
  16568. }
  16569. }
  16570. else
  16571. DEBUG_INFO("EOF\n");
  16572. fclose(fptr1);
  16573. /*------- End of reading ---------------*/
  16574. return temptransactionId;
  16575. }
  16576. void SetTransactionIdZero(int transactionId)
  16577. {
  16578. char ch;
  16579. FILE *fptr1, *fptr2;
  16580. int temptransactionId = 0;
  16581. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16582. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16583. if (!fptr1)
  16584. {
  16585. //printf(" File not found or unable to open the input file!!\n");
  16586. return ;
  16587. }
  16588. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16589. if (!fptr2)
  16590. {
  16591. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16592. fclose(fptr1);
  16593. return ;
  16594. }
  16595. ch=fgetc(fptr1);
  16596. rewind(fptr1);
  16597. if(ch!=EOF)
  16598. {
  16599. // copy all contents to the temporary file except the specific line
  16600. while (fgets(str, 100, fptr1) != NULL)
  16601. {
  16602. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16603. if(str[0]=='\0')
  16604. {
  16605. break;
  16606. }
  16607. char *revbuf[8] = {0};
  16608. int num = 0;
  16609. strcpy(strtemp, str);
  16610. splitstring(str,",",revbuf,&num);
  16611. if(revbuf[2][0] != '\0')
  16612. {
  16613. temptransactionId = atoi(revbuf[2]);
  16614. if(transactionId != temptransactionId)
  16615. {
  16616. fprintf(fptr2, "%s\n", strtemp);
  16617. }
  16618. }
  16619. }
  16620. }
  16621. fclose(fptr1);
  16622. fclose(fptr2);
  16623. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16624. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16625. /*------ Read the file ----------------*/
  16626. }
  16627. int InternetDisconnect(void)
  16628. {
  16629. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16630. }
  16631. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16632. void storeTempStopTransaction(int gun_index)
  16633. {
  16634. char guid[37]={0};
  16635. int tempIndex = 0;
  16636. char TempStopTransaction[256];
  16637. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16638. DEBUG_INFO("storeTempStopTransaction...\n");
  16639. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16640. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16641. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16642. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16643. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16644. {
  16645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16646. {
  16647. tempIndex = ((gun_index==2) ? 1: 0);
  16648. }
  16649. else
  16650. {
  16651. tempIndex = gun_index;
  16652. }
  16653. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16654. {
  16655. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16656. {
  16657. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16658. }
  16659. }// END OF CHAdeMO_QUANTITY
  16660. }
  16661. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16662. {
  16663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16664. {
  16665. tempIndex = ((gun_index==2) ? 1: 0);
  16666. }
  16667. else
  16668. {
  16669. tempIndex = gun_index;
  16670. }
  16671. for (int index = 0; index < CCS_QUANTITY; index++)
  16672. {
  16673. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16674. {
  16675. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16676. }
  16677. }// END OF CCS_QUANTITY
  16678. }
  16679. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16680. {
  16681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16682. {
  16683. tempIndex = ((gun_index==2) ? 1: 0);
  16684. }
  16685. else
  16686. {
  16687. tempIndex = gun_index;
  16688. }
  16689. for (int index = 0; index < GB_QUANTITY; index++)
  16690. {
  16691. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16692. {
  16693. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16694. }
  16695. }// END OF GB_QUANTITY
  16696. }
  16697. else if(gunType[gun_index] == GUN_TYPE_DO)
  16698. {
  16699. tempIndex = gun_index;
  16700. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16701. {
  16702. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16703. {
  16704. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16705. }
  16706. }
  16707. }
  16708. else
  16709. {
  16710. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16711. {
  16712. tempIndex = 2;
  16713. }
  16714. else
  16715. {
  16716. tempIndex = gun_index;
  16717. }
  16718. for (int index = 0; index < AC_QUANTITY; index++)
  16719. {
  16720. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16721. {
  16722. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16723. }
  16724. }// END OF AC_QUANTITY
  16725. }
  16726. //Stop Transaction Time
  16727. struct timeval tmnow;
  16728. struct tm *tm;
  16729. char buf[28];//, usec_buf[6];
  16730. gettimeofday(&tmnow, NULL);
  16731. time_t t;
  16732. t = time(NULL);
  16733. /*UTC time and date*/
  16734. tm = gmtime(&t);
  16735. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16736. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16737. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16739. random_uuid(guid);
  16740. /***********************************transactionData******************************************************/
  16741. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16742. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16743. //=================================
  16744. //1. Transaction_Begin
  16745. //=================================
  16746. //============================== Energy.Active.Import.Interval ===========================================
  16747. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16748. {
  16749. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16750. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16751. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16752. 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*/]);
  16753. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16754. 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))
  16755. {
  16756. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16757. }
  16758. else
  16759. {
  16760. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16761. }
  16762. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16763. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16764. }
  16765. //=================================
  16766. //2. Transaction_End
  16767. //=================================
  16768. //2.1====================================== Current.Import L1 ==============================================
  16769. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16770. {
  16771. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16772. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16773. {
  16774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16775. {
  16776. tempIndex = ((gun_index==2) ? 1: 0);
  16777. }
  16778. else
  16779. {
  16780. tempIndex = gun_index;
  16781. }
  16782. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16783. {
  16784. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16785. {
  16786. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16787. }
  16788. }// End of for CHAdeMO_QUANTITY
  16789. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16790. }
  16791. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16792. {
  16793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16794. {
  16795. tempIndex = ((gun_index==2) ? 1: 0);
  16796. }
  16797. else
  16798. {
  16799. tempIndex = gun_index;
  16800. }
  16801. for (int index = 0; index < CCS_QUANTITY; index++)
  16802. {
  16803. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16804. {
  16805. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16806. }
  16807. }// End of for CCS_QUANTITY
  16808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16809. }
  16810. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16811. {
  16812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16813. {
  16814. tempIndex = ((gun_index==2) ? 1: 0);
  16815. }
  16816. else
  16817. {
  16818. tempIndex = gun_index;
  16819. }
  16820. for (int index = 0; index < GB_QUANTITY; index++)
  16821. {
  16822. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16823. {
  16824. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16825. }
  16826. }// End of for GB_QUANTITY
  16827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16828. }
  16829. else if(gunType[gun_index] == GUN_TYPE_DO)
  16830. {
  16831. tempIndex = gun_index;
  16832. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16833. {
  16834. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16835. {
  16836. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16837. }
  16838. }
  16839. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16840. }
  16841. else
  16842. {
  16843. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16844. {
  16845. tempIndex = 2;
  16846. }
  16847. else
  16848. {
  16849. tempIndex = gun_index;
  16850. }
  16851. for (int index = 0; index < AC_QUANTITY; index++)
  16852. {
  16853. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16854. {
  16855. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16856. }
  16857. }// End of for AC_QUANTITY
  16858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16859. }
  16860. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16861. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16862. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16863. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16864. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16865. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16866. }
  16867. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16868. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16869. {
  16870. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16871. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16872. {
  16873. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16874. {
  16875. tempIndex = ((gun_index==2) ? 1: 0);
  16876. }
  16877. else
  16878. {
  16879. tempIndex = gun_index;
  16880. }
  16881. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16882. {
  16883. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16884. {
  16885. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16886. }
  16887. }// END OF CHAdeMO_QUANTITY
  16888. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16889. }
  16890. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16891. {
  16892. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16893. {
  16894. tempIndex = ((gun_index==2) ? 1: 0);
  16895. }
  16896. else
  16897. {
  16898. tempIndex = gun_index;
  16899. }
  16900. for (int index = 0; index < CCS_QUANTITY; index++)
  16901. {
  16902. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16903. {
  16904. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16905. }
  16906. }// END OF CCS_QUANTITY
  16907. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16908. }
  16909. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16910. {
  16911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16912. {
  16913. tempIndex = ((gun_index==2) ? 1: 0);
  16914. }
  16915. else
  16916. {
  16917. tempIndex = gun_index;
  16918. }
  16919. for (int index = 0; index < GB_QUANTITY; index++)
  16920. {
  16921. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16922. {
  16923. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16924. }
  16925. }// END OF GB_QUANTITY
  16926. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16927. }
  16928. else if(gunType[gun_index] == GUN_TYPE_DO)
  16929. {
  16930. tempIndex = gun_index;
  16931. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16932. {
  16933. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16934. {
  16935. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16936. }
  16937. }
  16938. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16939. }
  16940. else
  16941. {
  16942. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16943. {
  16944. tempIndex = 2;
  16945. }
  16946. else
  16947. {
  16948. tempIndex = gun_index;
  16949. }
  16950. for (int index = 0; index < AC_QUANTITY; index++)
  16951. {
  16952. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16953. {
  16954. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16955. }
  16956. }// END OF AC_QUANTITY
  16957. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16958. }
  16959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16960. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16961. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16962. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16963. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16964. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16965. }
  16966. //2.3====================================== Power.Active.Import =========================================
  16967. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16968. {
  16969. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16970. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16971. {
  16972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16973. {
  16974. tempIndex = ((gun_index==2) ? 1: 0);
  16975. }
  16976. else
  16977. {
  16978. tempIndex = gun_index;
  16979. }
  16980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16981. {
  16982. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16983. {
  16984. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16985. }
  16986. } // End for CHAdeMO_QUANTITY
  16987. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16988. }
  16989. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16990. {
  16991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16992. {
  16993. tempIndex = ((gun_index==2) ? 1: 0);
  16994. }
  16995. else
  16996. {
  16997. tempIndex = gun_index;
  16998. }
  16999. for (int index = 0; index < CCS_QUANTITY; index++)
  17000. {
  17001. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17002. {
  17003. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17004. }
  17005. } // END for CCS_QUANTITY
  17006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17007. }
  17008. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17009. {
  17010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17011. {
  17012. tempIndex = ((gun_index==2) ? 1: 0);
  17013. }
  17014. else
  17015. {
  17016. tempIndex = gun_index;
  17017. }
  17018. for (int index = 0; index < GB_QUANTITY; index++)
  17019. {
  17020. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17021. {
  17022. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17023. }
  17024. }// END for GB_QUANTITY
  17025. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17026. }
  17027. else if(gunType[gun_index] == GUN_TYPE_DO)
  17028. {
  17029. tempIndex = gun_index;
  17030. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17031. {
  17032. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17033. {
  17034. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17035. }
  17036. }
  17037. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17038. }
  17039. else
  17040. {
  17041. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17042. {
  17043. tempIndex = 2;
  17044. }
  17045. else
  17046. {
  17047. tempIndex = gun_index;
  17048. }
  17049. for (int index = 0; index < AC_QUANTITY; index++)
  17050. {
  17051. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17052. {
  17053. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17054. }
  17055. } // END for AC_QUANTITY
  17056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17057. }
  17058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17061. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17062. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17063. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17064. }
  17065. //2.4====================================== Voltage L1 ====================================================
  17066. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17067. {
  17068. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17069. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17070. {
  17071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17072. {
  17073. tempIndex = ((gun_index==2) ? 1: 0);
  17074. }
  17075. else
  17076. {
  17077. tempIndex = gun_index;
  17078. }
  17079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17080. {
  17081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17082. {
  17083. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17084. }
  17085. } // END OF FOR CHAdeMO_QUANTITY
  17086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17087. }
  17088. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17089. {
  17090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17091. {
  17092. tempIndex = ((gun_index==2) ? 1: 0);
  17093. }
  17094. else
  17095. {
  17096. tempIndex = gun_index;
  17097. }
  17098. for (int index = 0; index < CCS_QUANTITY; index++)
  17099. {
  17100. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17101. {
  17102. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17103. }
  17104. } // END OF FOR CCS_QUANTITY
  17105. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17106. }
  17107. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17108. {
  17109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17110. {
  17111. tempIndex = ((gun_index==2) ? 1: 0);
  17112. }
  17113. else
  17114. {
  17115. tempIndex = gun_index;
  17116. }
  17117. for (int index = 0; index < GB_QUANTITY; index++)
  17118. {
  17119. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17120. {
  17121. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17122. }
  17123. } // END OF FOR GB_QUANTITY
  17124. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17125. }
  17126. else if(gunType[gun_index] == GUN_TYPE_DO)
  17127. {
  17128. tempIndex = gun_index;
  17129. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17130. {
  17131. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17132. {
  17133. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17134. }
  17135. }
  17136. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17137. }
  17138. else
  17139. {
  17140. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17141. {
  17142. tempIndex = 2;
  17143. }
  17144. else
  17145. {
  17146. tempIndex = gun_index;
  17147. }
  17148. for (int index = 0; index < AC_QUANTITY; index++)
  17149. {
  17150. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17151. {
  17152. 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
  17153. }
  17154. } // END OF FOR AC_QUANTITY
  17155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17156. }
  17157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17158. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17160. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17161. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17162. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17163. }
  17164. //2.5============================================== End SoC =========================================================
  17165. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17166. {
  17167. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17168. 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))
  17169. {
  17170. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17171. {
  17172. tempIndex = ((gun_index==2) ? 1: 0);
  17173. }
  17174. else
  17175. {
  17176. tempIndex = gun_index;
  17177. }
  17178. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17179. {
  17180. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17181. {
  17182. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17183. {
  17184. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17185. }
  17186. }
  17187. }
  17188. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17189. {
  17190. for (int index = 0; index < CCS_QUANTITY; index++)
  17191. {
  17192. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17193. {
  17194. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17195. }
  17196. }
  17197. }
  17198. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17199. {
  17200. for (int index = 0; index < GB_QUANTITY; index++)
  17201. {
  17202. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17203. {
  17204. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17205. }
  17206. }
  17207. }
  17208. else if(gunType[gun_index] == GUN_TYPE_DO)
  17209. {
  17210. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17211. {
  17212. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17213. {
  17214. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17215. }
  17216. }
  17217. }
  17218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17220. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17221. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17222. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17223. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17224. } // END FOR DC CASE
  17225. }
  17226. //2.6====================================== Current.Import L2 ==============================================
  17227. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17228. {
  17229. // AC 3 phase L2 current
  17230. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17231. {
  17232. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17233. {
  17234. tempIndex = 2;
  17235. }
  17236. else
  17237. {
  17238. tempIndex = gun_index;
  17239. }
  17240. for (int index = 0; index < AC_QUANTITY; index++)
  17241. {
  17242. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17243. {
  17244. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17245. }
  17246. }// End of for AC_QUANTITY
  17247. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17248. }
  17249. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17250. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17251. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17252. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17253. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17254. }
  17255. //2.7====================================== Current.Import L3 ==============================================
  17256. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17257. {
  17258. // AC 3 phase L3 current
  17259. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17260. {
  17261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17262. {
  17263. tempIndex = 2;
  17264. }
  17265. else
  17266. {
  17267. tempIndex = gun_index;
  17268. }
  17269. for (int index = 0; index < AC_QUANTITY; index++)
  17270. {
  17271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17272. {
  17273. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17274. }
  17275. }// End of for AC_QUANTITY
  17276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17277. }
  17278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17280. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17282. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17283. }
  17284. //2.9====================================== Voltage L2 ====================================================
  17285. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17286. {
  17287. // AC 3 phase L2 volatge
  17288. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17289. {
  17290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17291. {
  17292. tempIndex = 2;
  17293. }
  17294. else
  17295. {
  17296. tempIndex = gun_index;
  17297. }
  17298. for (int index = 0; index < AC_QUANTITY; index++)
  17299. {
  17300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17301. {
  17302. 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
  17303. }
  17304. } // END OF FOR AC_QUANTITY
  17305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17306. }
  17307. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17309. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17310. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17311. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17312. }
  17313. //2.10====================================== Voltage L3 ====================================================
  17314. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17315. {
  17316. // AC 3 phase L3 volatge
  17317. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17318. {
  17319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17320. {
  17321. tempIndex = 2;
  17322. }
  17323. else
  17324. {
  17325. tempIndex = gun_index;
  17326. }
  17327. for (int index = 0; index < AC_QUANTITY; index++)
  17328. {
  17329. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17330. {
  17331. 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
  17332. }
  17333. } // END OF FOR AC_QUANTITY
  17334. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17335. }
  17336. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17337. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17338. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17339. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17340. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17341. }
  17342. //====================== Start SoC ================================
  17343. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17344. {
  17345. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17346. 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))
  17347. {
  17348. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17349. {
  17350. tempIndex = ((gun_index==2) ? 1: 0);
  17351. }
  17352. else
  17353. {
  17354. tempIndex = gun_index;
  17355. }
  17356. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17357. {
  17358. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17359. {
  17360. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17361. {
  17362. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17363. }
  17364. }
  17365. }
  17366. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17367. {
  17368. for (int index = 0; index < CCS_QUANTITY; index++)
  17369. {
  17370. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17371. {
  17372. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17373. }
  17374. }
  17375. }
  17376. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17377. {
  17378. for (int index = 0; index < GB_QUANTITY; index++)
  17379. {
  17380. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17381. {
  17382. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17383. }
  17384. }
  17385. }
  17386. else if(gunType[gun_index] == GUN_TYPE_DO)
  17387. {
  17388. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17389. {
  17390. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17391. {
  17392. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17393. }
  17394. }
  17395. }
  17396. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17397. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17398. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17399. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17400. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17401. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17402. } // END FOR DC CASE
  17403. }
  17404. //======================================== Message create ==============================================
  17405. json_object *StopTransaction = json_object_new_object();
  17406. json_object *transactionDatas = json_object_new_array();
  17407. json_object *sampledValues = json_object_new_array();
  17408. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17409. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17410. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17411. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17412. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17413. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17414. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17415. {
  17416. json_object *transactionData = json_object_new_object();
  17417. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17418. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17419. {
  17420. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17421. {
  17422. json_object *sampledValue = json_object_new_object();
  17423. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17424. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17425. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17426. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17427. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17428. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17429. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17430. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17431. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17432. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17433. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17434. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17435. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17436. json_object_array_add(sampledValues, sampledValue);
  17437. }
  17438. }
  17439. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17440. json_object_array_add(transactionDatas, transactionData);
  17441. }
  17442. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17443. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17444. ,MESSAGE_TYPE_CALL
  17445. ,guid
  17446. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17447. json_object_put(StopTransaction);
  17448. // Check File "TempStopTransaction" Exist
  17449. if((access(TempStopTransaction,F_OK))!=-1)
  17450. {
  17451. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17452. fclose(fopen(TempStopTransaction, "w"));
  17453. }
  17454. else
  17455. {
  17456. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17457. FILE *log = fopen(TempStopTransaction, "w+");
  17458. if(log == NULL)
  17459. {
  17460. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17461. return ;
  17462. }
  17463. else
  17464. {
  17465. fclose(log);
  17466. }
  17467. }
  17468. //Add TempStopTransaction | Update TempStopTransaction
  17469. // open file for writing
  17470. FILE *outfile;
  17471. outfile = fopen (TempStopTransaction, "a");
  17472. //DEBUG_INFO("data = %s\n", queuedata);
  17473. fputs(queuedata, outfile);
  17474. fputs("\n", outfile);
  17475. fclose (outfile);
  17476. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17477. }
  17478. void checkTempStopTransaction(int gun_index)
  17479. {
  17480. FILE *fptr1;
  17481. char ch;
  17482. char str[QUEUE_MESSAGE_LENGTH]={0};
  17483. char guid[37]={0};
  17484. char tempdata[65]={0};
  17485. char connectorStr[2]={0};
  17486. char TempStopTransaction[256];
  17487. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17488. fptr1 = fopen(TempStopTransaction, "r");
  17489. //TempStopTransaction格式: 槍號,StopTransaction封包
  17490. if (!fptr1)
  17491. {
  17492. //printf(" File not found or unable to open the input file!!\n");
  17493. return ;
  17494. }
  17495. ch=fgetc(fptr1);
  17496. //printf(" Now the content of the file %s is : \n",fname);
  17497. rewind(fptr1);
  17498. if(ch!=EOF)
  17499. {
  17500. // copy all contents to the temporary file except the specific line
  17501. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17502. {
  17503. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17504. if(str[0]=='\0')
  17505. {
  17506. break;
  17507. }
  17508. //TempStopTransaction格式: 槍號,StopTransaction封包
  17509. strncpy(connectorStr, str, 1);
  17510. if(atoi(connectorStr) != (gun_index+1))
  17511. {
  17512. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17513. fclose(fptr1);
  17514. return ;
  17515. }
  17516. //random_uuid(guid);
  17517. strncpy(guid, str+6, 36); //copy guid
  17518. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17519. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17520. {
  17521. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17522. }
  17523. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17524. OCPP_insert_transaction_msg(NO, str);
  17525. memset(str,0,ARRAY_SIZE(str));
  17526. }
  17527. }
  17528. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17529. fclose(fptr1);
  17530. remove(TempStopTransaction); // remove the original file
  17531. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17532. }
  17533. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17534. {
  17535. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17536. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17537. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17538. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17539. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17540. }
  17541. int GetWebSocketPingInterval(void)
  17542. {
  17543. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17544. }
  17545. int GetServerSign(void)
  17546. {
  17547. return server_sign;
  17548. }
  17549. uint8_t GetOcppSecurityProfile()
  17550. {
  17551. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17552. }
  17553. void GetOcppChargerBoxId(uint8_t *data)
  17554. {
  17555. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17556. }
  17557. void GetOcppSecurityPassword(uint8_t *data)
  17558. {
  17559. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17560. }
  17561. void SetOcppVersion(uint8_t *version)
  17562. {
  17563. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17564. DEBUG_INFO("ocpp version: %s\n", version);
  17565. if(strstr((char*)version, "ocpp1.6") != NULL)
  17566. {
  17567. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17568. }
  17569. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17570. {
  17571. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17572. system("pkill OcppBackend");
  17573. }
  17574. }
  17575. void SetServerSign(int value)
  17576. {
  17577. server_sign = value;
  17578. }
  17579. int GetBootNotificationInterval(void)
  17580. {
  17581. return BootNotificationInterval;
  17582. }
  17583. int GetInternetConn(void)
  17584. {
  17585. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17586. }
  17587. int GetBackendConnectionTimeout(void)
  17588. {
  17589. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17590. }
  17591. int isConnectorInitMode(int gun_index)
  17592. {
  17593. int tempIndex = 0;
  17594. int result = TRUE;
  17595. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17596. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17597. {
  17598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17599. {
  17600. tempIndex = ((gun_index==2) ? 1: 0);
  17601. }
  17602. else
  17603. {
  17604. tempIndex = gun_index;
  17605. }
  17606. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17607. {
  17608. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17609. {
  17610. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17611. } //end of the same index
  17612. }//end of for CHAdeMO_QUANTITY
  17613. }
  17614. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17615. {
  17616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17617. {
  17618. tempIndex = ((gun_index==2) ? 1: 0);
  17619. }
  17620. else
  17621. {
  17622. tempIndex = gun_index;
  17623. }
  17624. for (int index = 0; index < CCS_QUANTITY; index++)
  17625. {
  17626. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17627. {
  17628. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17629. } //end of the same index
  17630. } // end of for CCS_QUANTITY
  17631. }
  17632. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17633. {
  17634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17635. {
  17636. tempIndex = ((gun_index==2) ? 1: 0);
  17637. }
  17638. else
  17639. {
  17640. tempIndex = gun_index;
  17641. }
  17642. for (int index = 0; index < GB_QUANTITY; index++)
  17643. {
  17644. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17645. {
  17646. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17647. } //end of the same index
  17648. } // end of for GB_QUANTITY
  17649. }
  17650. else if(gunType[gun_index] == GUN_TYPE_DO)
  17651. {
  17652. tempIndex = gun_index;
  17653. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17654. {
  17655. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17656. {
  17657. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17658. } //end of the same index
  17659. }
  17660. }
  17661. else
  17662. {
  17663. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17664. {
  17665. tempIndex = 2;
  17666. }
  17667. else
  17668. {
  17669. tempIndex = gun_index;
  17670. }
  17671. for (int index = 0; index < AC_QUANTITY; index++)
  17672. {
  17673. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17674. {
  17675. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17676. }//end of the same index
  17677. }//end of for AC_QUANTITY
  17678. }
  17679. return result;
  17680. }
  17681. void refreshProcDogTimer()
  17682. {
  17683. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17684. }
  17685. void InitialSystemValue(void)
  17686. {
  17687. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17688. locallistVersion=0;
  17689. BootNotificationInterval = 0;
  17690. authorizeRetryTimes = 0;
  17691. GunStatusInterval = 10;
  17692. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17693. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17694. //Hear Beat
  17695. HeartBeatWithNOResponse = 0;
  17696. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17697. FirstHeartBeat = 0;
  17698. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17699. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17700. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17701. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17702. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17703. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17704. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17705. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17706. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17707. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17708. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17709. //Status && ConnectorPlugIn Setting
  17710. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17711. {
  17712. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17713. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17714. }
  17715. for (int index = 0; index < CCS_QUANTITY; index++)
  17716. {
  17717. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17718. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17719. }
  17720. for (int index = 0; index < GB_QUANTITY; index++)
  17721. {
  17722. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17723. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17724. }
  17725. for (int index = 0; index < AC_QUANTITY; index++)
  17726. {
  17727. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17728. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17729. }
  17730. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17731. {
  17732. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17733. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17734. }
  17735. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17736. {
  17737. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17738. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17739. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17740. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17741. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17742. }
  17743. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17744. refreshStartTimer(&clientTime.Heartbeat);
  17745. sleep(1);
  17746. }
  17747. void LWS_Send(char *str)
  17748. {
  17749. //=====================================================
  17750. // Check InternetConn 0: disconnected, 1: connected
  17751. //====================================================
  17752. if(GetOcppConnStatus() == 0)
  17753. {
  17754. DEBUG_INFO("offline now !!!\n");
  17755. return;
  17756. }
  17757. // Only disable isWebsocketSendable operation initiated by charger
  17758. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17759. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17760. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17761. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17762. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17763. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17764. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17765. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17766. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17767. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17768. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17769. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17770. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17771. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17772. {
  17773. isWebsocketSendable = 0;
  17774. }
  17775. pthread_mutex_lock(&lock_send);
  17776. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17777. sprintf((char *)SendBuffer, "%s", str);
  17778. SendBufLen = strlen(str);
  17779. pthread_mutex_unlock(&lock_send);
  17780. lws_callback_on_writable(wsi_client);
  17781. //lws_service(context, 0);
  17782. //sleep(1);
  17783. }
  17784. void LWS_SendNow(char *str)
  17785. {
  17786. //=====================================================
  17787. // Check InternetConn 0: disconnected, 1: connected
  17788. //====================================================
  17789. if(GetOcppConnStatus() == 0)
  17790. {
  17791. DEBUG_INFO("offline now !!!\n");
  17792. return;
  17793. }
  17794. // Only disable isWebsocketSendable operation initiated by charger
  17795. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17796. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17797. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17798. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17799. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17800. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17801. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17802. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17803. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17804. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17805. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17806. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17807. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17808. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17809. {
  17810. isWebsocketSendable = 0;
  17811. }
  17812. pthread_mutex_lock(&lock_send);
  17813. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17814. sprintf((char *)SendBuffer, "%s", str);
  17815. SendBufLen = strlen(str);
  17816. pthread_mutex_unlock(&lock_send);
  17817. lws_callback_on_writable(wsi_client);
  17818. lws_service(context, 0);
  17819. //sleep(1);
  17820. }