MessageHandler.c 903 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431
  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_DsiplayLcdPage") != 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, "Page_Index") != NULL)
  9043. {
  9044. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9045. }
  9046. if(json_object_object_get(data, "Duration") != NULL)
  9047. {
  9048. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9049. }
  9050. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9051. }
  9052. else
  9053. {
  9054. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9055. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9056. }
  9057. json_object_put(data);
  9058. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9059. json_object_put(response);
  9060. }
  9061. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9062. {
  9063. json_object *data;
  9064. data = json_tokener_parse(tempdata);
  9065. if(!is_error(data))
  9066. {
  9067. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9068. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9069. {
  9070. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9071. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9072. else
  9073. {
  9074. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9075. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9076. }
  9077. }
  9078. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9079. {
  9080. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9081. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9082. else
  9083. {
  9084. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9085. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9086. }
  9087. }
  9088. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9089. {
  9090. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9091. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9092. else
  9093. {
  9094. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9095. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9096. }
  9097. }
  9098. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9099. {
  9100. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9101. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9102. else
  9103. {
  9104. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9105. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9106. }
  9107. }
  9108. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9109. {
  9110. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9111. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9112. else
  9113. {
  9114. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9115. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9116. }
  9117. }
  9118. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9119. {
  9120. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9121. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9122. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9123. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9124. else
  9125. {
  9126. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9127. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9128. }
  9129. }
  9130. if(json_object_object_get(data, "isAuthentication") != NULL)
  9131. {
  9132. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9133. {
  9134. case 0:
  9135. case 1:
  9136. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9137. break;
  9138. default:
  9139. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9140. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9141. break;
  9142. }
  9143. }
  9144. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9145. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9146. }
  9147. else
  9148. {
  9149. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9150. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9151. }
  9152. json_object_put(data);
  9153. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9154. json_object_put(response);
  9155. }
  9156. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9157. {
  9158. json_object *data;
  9159. data = json_tokener_parse(tempdata);
  9160. if(!is_error(data))
  9161. {
  9162. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9163. if(json_object_object_get(data, "stationName") != NULL)
  9164. {
  9165. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9166. }
  9167. else
  9168. {
  9169. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9170. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9171. }
  9172. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9173. {
  9174. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9175. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9176. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9177. }
  9178. }
  9179. else
  9180. {
  9181. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9182. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9183. }
  9184. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9185. json_object_put(response);
  9186. }
  9187. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9188. {
  9189. json_object *data;
  9190. data = json_tokener_parse(tempdata);
  9191. if(!is_error(data))
  9192. {
  9193. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9194. if(json_object_object_get(data, "weatherId") != NULL)
  9195. {
  9196. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9197. }
  9198. else
  9199. {
  9200. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9201. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9202. }
  9203. if(json_object_object_get(data, "Temperature") != NULL)
  9204. {
  9205. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9206. }
  9207. else
  9208. {
  9209. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9210. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9211. }
  9212. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9213. {
  9214. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9215. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9216. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9217. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9218. }
  9219. }
  9220. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9221. {
  9222. json_object *data;
  9223. data = json_tokener_parse(tempdata);
  9224. if(!is_error(data))
  9225. {
  9226. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9227. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9228. {
  9229. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9230. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9231. }
  9232. else
  9233. {
  9234. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9235. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9236. }
  9237. }
  9238. else
  9239. {
  9240. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9241. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9242. }
  9243. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9244. json_object_put(response);
  9245. }
  9246. else
  9247. {
  9248. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9249. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9250. }
  9251. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9252. json_object_put(response);
  9253. }
  9254. else
  9255. {
  9256. // Can not find valid message id
  9257. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9258. }
  9259. }
  9260. else
  9261. {
  9262. // Payload is null
  9263. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9264. }
  9265. LWS_Send(message);
  9266. return result;
  9267. }
  9268. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9269. {
  9270. mtrace();
  9271. int result = FAIL;
  9272. int connectorIdInt, durationInt;
  9273. char chargingRateUnitStr[4]={0};
  9274. char comfirmstr[20];
  9275. int confirmPeriods = 0;
  9276. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9277. json_object *GetCompositeSchedule;
  9278. GetCompositeSchedule = json_tokener_parse(payload);
  9279. if(!is_error(GetCompositeSchedule))
  9280. {
  9281. // Required data
  9282. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9283. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9284. else
  9285. connectorIdInt = -1;
  9286. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9287. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9288. else
  9289. durationInt = 86400;
  9290. // Optional data
  9291. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9292. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9293. }
  9294. json_object_put(GetCompositeSchedule);
  9295. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9296. if((connectorIdInt == 0) ||
  9297. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9298. {
  9299. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9300. struct StructChargingProfile tmpProfile[1];
  9301. if(strstr(chargingRateUnitStr, "W") != NULL)
  9302. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9303. else
  9304. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9305. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9306. {
  9307. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9308. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9309. }
  9310. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9311. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9312. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9313. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9314. {
  9315. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9316. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9317. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9318. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9319. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9320. {
  9321. confirmPeriods = idx;
  9322. break;
  9323. }
  9324. }
  9325. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9326. {
  9327. confirmPeriods += 1;
  9328. }
  9329. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9330. }
  9331. else
  9332. {
  9333. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9334. }
  9335. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9336. return result;
  9337. }
  9338. int handleGetConfigurationRequest(char *uuid, char *payload)
  9339. {
  9340. mtrace();
  9341. int result = FAIL;
  9342. int MaxKeySupported = 0;
  9343. int n_keys = 0;
  9344. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9345. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9346. json_object *GetConfiguration;
  9347. GetConfiguration = json_tokener_parse(payload);
  9348. if(!is_error(GetConfiguration))
  9349. {
  9350. // Optional data
  9351. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9352. {
  9353. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9354. {
  9355. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9356. n_keys = idx + 1;
  9357. }
  9358. }
  9359. }
  9360. json_object_put(GetConfiguration);
  9361. UnknownKeynum = 0;
  9362. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9363. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9364. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9365. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9366. if(n_keys != 0)
  9367. {
  9368. for(int i=0;i<n_keys;i++)
  9369. {
  9370. getKeyValue(requestKey[i]);
  9371. }
  9372. }
  9373. else
  9374. {
  9375. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9376. getKeyValue("");
  9377. }
  9378. processUnkownKey();
  9379. sendGetConfigurationConfirmation(uuid);
  9380. return result;
  9381. }
  9382. static char fnamePlusPath[100]={0};
  9383. static char fnamePWithNoPath[60]={0};
  9384. void checkUploadLog(void)
  9385. {
  9386. FILE *fp;
  9387. /* Open the command for reading. */
  9388. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9389. if (fp == NULL) {
  9390. DEBUG_WARN("Failed to run command\n" );
  9391. exit(1);
  9392. }
  9393. int ftppathlen = 0;
  9394. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9395. int i = 0;
  9396. /* Read the output a line at a time - output it. */
  9397. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9398. if(i==0)
  9399. {
  9400. ftppathlen = strlen(fnamePlusPath);
  9401. DEBUG_INFO("%s\n", fnamePlusPath);
  9402. fnamePlusPath[ftppathlen]='\0';
  9403. break;
  9404. }
  9405. i= i+1;
  9406. }
  9407. /* close */
  9408. pclose(fp);
  9409. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9410. {
  9411. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9412. {
  9413. fnamePlusPath[k]='\0';
  9414. }
  9415. }
  9416. i=1;
  9417. //char fname[60]={0};
  9418. while(i < ftppathlen)
  9419. {
  9420. int len=ftppathlen-i;
  9421. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9422. {
  9423. DEBUG_INFO("compare '/' all right\n");
  9424. break;
  9425. }
  9426. i=i+1;
  9427. }
  9428. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9429. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9430. fnamePWithNoPath[i+1] = '\0';
  9431. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9432. {
  9433. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9434. {
  9435. fnamePWithNoPath[j]='\0';
  9436. }
  9437. }
  9438. FILE* fp1 = fopen(fnamePlusPath, "r");
  9439. if (fp1)
  9440. {
  9441. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9442. // file exists
  9443. fclose(fp1);
  9444. }
  9445. else
  9446. {
  9447. // file doesn't exist
  9448. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9449. }
  9450. }
  9451. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9452. {
  9453. mtrace();
  9454. int result = FAIL;
  9455. time_t CurrentTime;
  9456. struct tm *tm;
  9457. pthread_t th_Status;
  9458. CurrentTime = time(NULL);
  9459. tm = localtime(&CurrentTime);
  9460. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9461. 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);
  9462. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9463. if(!interLock.isGetDiagnosticGoing)
  9464. {
  9465. interLock.isGetDiagnosticGoing = 1;
  9466. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9467. sleep(1);
  9468. }
  9469. else
  9470. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9471. return result;
  9472. }
  9473. void* GetDiagnosticsProcess(void* data)
  9474. {
  9475. pthread_detach(pthread_self());
  9476. mtrace();
  9477. int retriesInt=0, retryIntervalInt=0;
  9478. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9479. 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};
  9480. int port=0;
  9481. int isSuccess = FALSE;
  9482. char ftpbuf[200]={0};
  9483. char cmdBuf[2048];
  9484. struct tm *tmNow;
  9485. time_t CurrentTime;
  9486. struct tm tmStart;
  9487. struct tm tmStop;
  9488. CurrentTime = time(NULL);
  9489. tmNow=localtime(&CurrentTime);
  9490. uint16_t targetYear, targetMonth;
  9491. json_object *GetDiagnostics;
  9492. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9493. GetDiagnostics = json_tokener_parse(data);
  9494. if(!is_error(GetDiagnostics))
  9495. {
  9496. // Required data
  9497. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9498. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9499. // Optional data
  9500. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9501. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9502. else
  9503. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9504. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9505. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9506. else
  9507. retryIntervalInt = 30;
  9508. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9509. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9510. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9511. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9512. }
  9513. json_object_put(GetDiagnostics);
  9514. // Pack log to compress file
  9515. 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) &&
  9516. (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))
  9517. {
  9518. // Pack system log
  9519. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9520. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9521. targetYear = tmStart.tm_year;
  9522. targetMonth = tmStart.tm_mon;
  9523. do
  9524. {
  9525. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9526. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9527. if(targetMonth+1>=13)
  9528. {
  9529. targetYear += 1;
  9530. targetMonth = 1;
  9531. }
  9532. else
  9533. {
  9534. targetMonth += 1;
  9535. }
  9536. }while((targetYear < (tmNow->tm_year+1900)) ||
  9537. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9538. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9539. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9540. system(cmdBuf);
  9541. // Pack charging & event log
  9542. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9543. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9544. targetYear = tmStart.tm_year;
  9545. targetMonth = tmStart.tm_mon;
  9546. do
  9547. {
  9548. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9549. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9550. if(targetMonth+1>=13)
  9551. {
  9552. targetYear += 1;
  9553. targetMonth = 1;
  9554. }
  9555. else
  9556. {
  9557. targetMonth += 1;
  9558. }
  9559. }while((targetYear < (tmNow->tm_year+1900)) ||
  9560. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9561. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9562. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9563. system(cmdBuf);
  9564. // Combine log file
  9565. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9566. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9567. }
  9568. else
  9569. {
  9570. system("exec /root/logPackTools 'log' 6");
  9571. }
  9572. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9573. system(cmdBuf);
  9574. checkUploadLog();
  9575. //****************location*******************/
  9576. if(strcmp(locationstr,"")==0)
  9577. {
  9578. DEBUG_INFO("location is <Empty>!\n");
  9579. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9580. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9581. goto end;
  9582. }
  9583. memset(protocol, 0, ARRAY_SIZE(protocol));
  9584. memset(user, 0, ARRAY_SIZE(user) );
  9585. memset(password, 0, ARRAY_SIZE(password));
  9586. memset(host, 0, ARRAY_SIZE(host));
  9587. memset(path, 0, ARRAY_SIZE(path));
  9588. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9589. memset(host1, 0, ARRAY_SIZE(host1));
  9590. memset(path1, 0, ARRAY_SIZE(path1));
  9591. /*location: ftp://user:password@host:port/path*/
  9592. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9593. if((access(fnamePlusPath,F_OK))!=-1)
  9594. {
  9595. DEBUG_INFO("fnamePlusPath exist.\n");
  9596. }
  9597. else
  9598. {
  9599. DEBUG_INFO("fnamePlusPath not exist!\n");
  9600. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9601. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9602. goto end;
  9603. }
  9604. if(strchr(locationstr,'@')==NULL)
  9605. {
  9606. sscanf(locationstr,
  9607. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9608. protocol, host, &port, path);
  9609. strcpy(user,"anonymous");
  9610. strcpy(password,"");
  9611. }
  9612. else
  9613. {
  9614. //DEBUG_INFO("pch=%s\n", pch);
  9615. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9616. protocol, user, password, host, &port, path);
  9617. }
  9618. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9619. {
  9620. DEBUG_INFO("protocol is not ftp/http ! \n");
  9621. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9622. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9623. goto end;
  9624. }
  9625. if(strncmp(locationstr,"http", 4) == 0)
  9626. {
  9627. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9628. sprintf(ftppath,"/%s", path);
  9629. do
  9630. {
  9631. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9632. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9633. sleep(3);
  9634. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9635. if(!isSuccess)
  9636. {
  9637. DEBUG_INFO("Diagnostics fail.\n");
  9638. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9639. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9640. sleep(retryIntervalInt);
  9641. }
  9642. else
  9643. {
  9644. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9645. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9646. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9647. }
  9648. retriesInt--;
  9649. }while((isSuccess == 0)&&(retriesInt >= 0));
  9650. }
  9651. else
  9652. {
  9653. sscanf(host,"%[^/]%s",host1, path1);
  9654. if(strlen(path) > 0)
  9655. sprintf(ftppath,"/%s", path);
  9656. else
  9657. sprintf(ftppath,"/%s", path1);
  9658. int ftppathlen=strlen(ftppath);
  9659. int i=1;
  9660. char filenametemp[50];
  9661. while(i < ftppathlen)
  9662. {
  9663. int len=ftppathlen-i;
  9664. if(ftppath[len]== 47) // '/' ascll code: 47
  9665. {
  9666. DEBUG_INFO("find '/' all right\n");
  9667. break;
  9668. }
  9669. i=i+1;
  9670. }
  9671. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9672. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9673. filenametemp[i+1] = 0;
  9674. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9675. if(port == 0)
  9676. port = 21;
  9677. do
  9678. {
  9679. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9680. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9681. sleep(3);
  9682. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9683. if(!isSuccess)
  9684. {
  9685. DEBUG_INFO("Diagnostics fail.\n");
  9686. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9687. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9688. sleep(retryIntervalInt);
  9689. }
  9690. else
  9691. {
  9692. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9693. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9694. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9695. }
  9696. retriesInt--;
  9697. }while((!isSuccess)&&(retriesInt >= 0));
  9698. }
  9699. end:
  9700. system("rm -f /mnt/*");
  9701. sleep(5);
  9702. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9703. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9704. interLock.isGetDiagnosticGoing = 0;
  9705. pthread_exit(NULL);
  9706. }
  9707. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9708. {
  9709. mtrace();
  9710. int result = FAIL;
  9711. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9712. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9713. {
  9714. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9715. locallistVersion = -1;
  9716. }
  9717. else
  9718. {
  9719. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9720. OCPP_getListVerion();
  9721. }
  9722. //from db.OCPP_getListVerion
  9723. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9724. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9725. sendGetLocalListVersionConfirmation(uuid,"");
  9726. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9727. return result;
  9728. }
  9729. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9730. {
  9731. mtrace();
  9732. int result = FAIL;
  9733. int connectorIdInt=-1;
  9734. int tempIndex = 0;
  9735. int connectorIdIsNULL, chargingProfileIsNULL;
  9736. char comfirmstr[20]={0};
  9737. char cmdBuf[512];
  9738. json_object *RemoteStartTransaction;
  9739. FILE *fp;
  9740. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9741. if(server_pending == TRUE)
  9742. {
  9743. return 0;
  9744. }
  9745. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9746. RemoteStartTransaction = json_tokener_parse(payload);
  9747. if(!is_error(RemoteStartTransaction))
  9748. {
  9749. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9750. {
  9751. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9752. }
  9753. else
  9754. {
  9755. connectorIdIsNULL = TRUE;
  9756. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9757. {
  9758. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9759. {
  9760. connectorIdIsNULL = FALSE;
  9761. connectorIdInt = (gun_index+1);
  9762. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9763. break;
  9764. }
  9765. }
  9766. }
  9767. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9768. {
  9769. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9770. // Required data
  9771. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9772. // Optional data
  9773. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9774. {
  9775. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9776. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9777. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9778. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9779. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9780. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9781. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9782. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9783. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9784. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9785. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9786. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9787. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9788. {
  9789. 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")));
  9790. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9791. 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"));
  9792. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9793. 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"));
  9794. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9795. 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")));
  9796. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9797. {
  9798. 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++)
  9799. {
  9800. 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"));
  9801. 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"));
  9802. 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)
  9803. 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"));
  9804. }
  9805. }
  9806. }
  9807. }
  9808. else
  9809. {
  9810. chargingProfileIsNULL = TRUE;
  9811. }
  9812. }
  9813. }
  9814. else
  9815. {
  9816. connectorIdIsNULL = TRUE;
  9817. }
  9818. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9819. {
  9820. DEBUG_WARN("Connector id is NULL\n.");
  9821. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9822. goto end;
  9823. }
  9824. /*
  9825. enum _SYSTEM_STATUS
  9826. {
  9827. S_BOOTING = 0,
  9828. S_IDLE, = 1
  9829. S_AUTHORIZING, = 2
  9830. S_REASSIGN_CHECK, = 3
  9831. S_REASSIGN, = 4
  9832. S_PRECHARGE, = 5
  9833. S_PREPARING_FOR_EV, = 6
  9834. S_PREPARING_FOR_EVSE, = 7
  9835. S_CHARGING, = 8
  9836. S_TERMINATING, = 9
  9837. S_COMPLETE, = 10
  9838. S_ALARM, = 11
  9839. S_FAULT = 12
  9840. }
  9841. */
  9842. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9843. {
  9844. //check Transaction active
  9845. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9846. {
  9847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9848. {
  9849. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9850. }
  9851. else
  9852. {
  9853. tempIndex = connectorIdInt -1;
  9854. }
  9855. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9856. {
  9857. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9858. {
  9859. 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))
  9860. {
  9861. //Reserved
  9862. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9863. }
  9864. 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))
  9865. {
  9866. //Reserved
  9867. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9868. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9869. goto end;
  9870. }
  9871. else
  9872. {
  9873. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9874. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9875. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9876. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9877. {
  9878. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9879. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9880. goto end;
  9881. }
  9882. }//END FOR ELSE
  9883. }
  9884. }// END FOR CHAdeMO_QUANTITY
  9885. }
  9886. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9887. {
  9888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9889. {
  9890. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9891. }
  9892. else
  9893. {
  9894. tempIndex = connectorIdInt -1;
  9895. }
  9896. for (int index = 0; index < CCS_QUANTITY; index++)
  9897. {
  9898. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9899. {
  9900. 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))
  9901. {
  9902. //Reserved
  9903. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9904. }
  9905. 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))
  9906. {
  9907. //Reserved
  9908. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9909. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9910. goto end;
  9911. }
  9912. else
  9913. {
  9914. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9915. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9916. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9917. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9918. {
  9919. DEBUG_WARN("CCS connector not allow start\n.");
  9920. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9921. goto end;
  9922. }
  9923. }// END FOR ELSE
  9924. }
  9925. }// END FOR CCS_QUANTITY
  9926. }
  9927. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9928. {
  9929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9930. {
  9931. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9932. }
  9933. else
  9934. {
  9935. tempIndex = connectorIdInt -1;
  9936. }
  9937. for (int index = 0; index < GB_QUANTITY; index++)
  9938. {
  9939. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9940. {
  9941. 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))
  9942. {
  9943. //Reserved
  9944. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9945. }
  9946. 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))
  9947. {
  9948. //Reserved
  9949. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9950. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9951. goto end;
  9952. }
  9953. else
  9954. {
  9955. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9956. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9957. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9958. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9959. {
  9960. DEBUG_WARN("GB connector not allow start\n.");
  9961. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9962. goto end;
  9963. }
  9964. }// END FOR ELSE
  9965. }
  9966. } // END FOR GB_QUANTITY
  9967. }
  9968. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9969. {
  9970. tempIndex = connectorIdInt -1;
  9971. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9972. {
  9973. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9974. {
  9975. 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))
  9976. {
  9977. //Reserved
  9978. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9979. }
  9980. 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))
  9981. {
  9982. //Reserved
  9983. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9984. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9985. goto end;
  9986. }
  9987. else
  9988. {
  9989. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9990. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9991. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9992. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9993. {
  9994. DEBUG_WARN("GB connector not allow start\n.");
  9995. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9996. goto end;
  9997. }
  9998. }// END FOR ELSE
  9999. }
  10000. } // END FOR GB_QUANTITY
  10001. }
  10002. else
  10003. {
  10004. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10005. {
  10006. tempIndex = 2;
  10007. }
  10008. else
  10009. {
  10010. tempIndex = connectorIdInt -1;
  10011. }
  10012. for (int index = 0; index < AC_QUANTITY; index++)
  10013. {
  10014. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10015. {
  10016. 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))
  10017. {
  10018. //Reserved
  10019. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10020. }
  10021. 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))
  10022. {
  10023. //Reserved
  10024. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10025. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10026. goto end;
  10027. }
  10028. else
  10029. {
  10030. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10031. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10032. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10033. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10034. {
  10035. DEBUG_WARN("AC connector not allow start\n.");
  10036. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10037. goto end;
  10038. }
  10039. }//END FOR ELSE
  10040. }
  10041. }// END FOR AC_QUANTITY
  10042. }
  10043. if(chargingProfileIsNULL == FALSE)
  10044. {
  10045. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10046. {
  10047. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10048. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10049. //memset idTag
  10050. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10051. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10052. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10053. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10054. // Save profile to file
  10055. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10056. system(cmdBuf);
  10057. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10058. fp = fopen(cmdBuf, "w");
  10059. 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));
  10060. fclose(fp);
  10061. }
  10062. else
  10063. {
  10064. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10065. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10066. }
  10067. }
  10068. else
  10069. {
  10070. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10071. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10072. //memset idTag
  10073. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10074. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10075. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10076. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10077. }
  10078. }
  10079. else
  10080. {
  10081. DEBUG_WARN("Connector id over\n.");
  10082. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10083. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10084. }
  10085. end:
  10086. json_object_put(RemoteStartTransaction);
  10087. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10088. {
  10089. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10090. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10091. }
  10092. //OCPP send RemoteStartConfirmation by first.
  10093. sendRemoteStartConfirmation(uuid, comfirmstr);
  10094. return result;
  10095. }
  10096. int handleRemoteStartRequest(char *uuid, char *payload)
  10097. {
  10098. mtrace();
  10099. int result = PASS;
  10100. int connectorIdInt=-1;
  10101. int tempIndex = 0;
  10102. char comfirmstr[20]={0};
  10103. char cmdBuf[512];
  10104. json_object *RemoteStartTransaction;
  10105. FILE *fp;
  10106. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10107. if(server_pending == TRUE)
  10108. {
  10109. result = FAIL;
  10110. }
  10111. RemoteStartTransaction = json_tokener_parse(payload);
  10112. if(!is_error(RemoteStartTransaction))
  10113. {
  10114. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10115. {
  10116. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10117. }
  10118. else
  10119. {
  10120. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10121. {
  10122. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10123. {
  10124. connectorIdInt = (gun_index+1);
  10125. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10126. break;
  10127. }
  10128. }
  10129. }
  10130. if(connectorIdInt == 0)
  10131. {
  10132. DEBUG_WARN("Connector id shall not equal 0.\n");
  10133. result = FAIL;
  10134. }
  10135. else if(connectorIdInt == -1)
  10136. {
  10137. DEBUG_INFO("Connector id does not specific.\n");
  10138. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10139. {
  10140. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10141. // Required data
  10142. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10143. // Optional data
  10144. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10145. {
  10146. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10147. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10148. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10149. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10150. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10151. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10152. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10153. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10154. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10155. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10156. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10157. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10158. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10159. {
  10160. 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")));
  10161. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10162. 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"));
  10163. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10164. 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"));
  10165. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10166. 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")));
  10167. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10168. {
  10169. 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++)
  10170. {
  10171. 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"));
  10172. 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"));
  10173. 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)
  10174. 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"));
  10175. }
  10176. }
  10177. }
  10178. }
  10179. else
  10180. {
  10181. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10182. }
  10183. }
  10184. }
  10185. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10186. {
  10187. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10188. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10189. // Required data
  10190. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10191. // Optional data
  10192. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10193. {
  10194. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10195. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10196. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10197. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10198. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10199. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10200. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10201. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10202. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10203. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10204. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10205. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10206. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10207. {
  10208. 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")));
  10209. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10210. 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"));
  10211. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10212. 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"));
  10213. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10214. 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")));
  10215. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10216. {
  10217. 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++)
  10218. {
  10219. 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"));
  10220. 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"));
  10221. 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)
  10222. 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"));
  10223. }
  10224. }
  10225. }
  10226. }
  10227. else
  10228. {
  10229. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10230. }
  10231. }
  10232. else
  10233. {
  10234. DEBUG_WARN("Connector id is over maximun value.\n");
  10235. result = FAIL;
  10236. }
  10237. }
  10238. if(result == PASS)
  10239. {
  10240. if(connectorIdInt > 0)
  10241. {
  10242. //check Transaction active
  10243. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10244. {
  10245. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10246. {
  10247. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10248. }
  10249. else
  10250. {
  10251. tempIndex = connectorIdInt -1;
  10252. }
  10253. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10254. {
  10255. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10256. {
  10257. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10258. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10259. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10260. {
  10261. //Reserved
  10262. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10263. }
  10264. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10265. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10266. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10267. {
  10268. //Reserved
  10269. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10270. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10271. goto end;
  10272. }
  10273. else
  10274. {
  10275. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10276. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10277. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10278. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10279. {
  10280. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10281. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10282. goto end;
  10283. }
  10284. }//END FOR ELSE
  10285. }
  10286. }// END FOR CHAdeMO_QUANTITY
  10287. }
  10288. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10289. {
  10290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10291. {
  10292. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10293. }
  10294. else
  10295. {
  10296. tempIndex = connectorIdInt -1;
  10297. }
  10298. for (int index = 0; index < CCS_QUANTITY; index++)
  10299. {
  10300. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10301. {
  10302. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10303. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10304. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10305. {
  10306. //Reserved
  10307. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10308. }
  10309. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10310. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10311. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10312. {
  10313. //Reserved
  10314. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10316. goto end;
  10317. }
  10318. else
  10319. {
  10320. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10321. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10322. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10323. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10324. {
  10325. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10326. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10327. goto end;
  10328. }
  10329. }// END FOR ELSE
  10330. }
  10331. }// END FOR CCS_QUANTITY
  10332. }
  10333. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10334. {
  10335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10336. {
  10337. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10338. }
  10339. else
  10340. {
  10341. tempIndex = connectorIdInt -1;
  10342. }
  10343. for (int index = 0; index < GB_QUANTITY; index++)
  10344. {
  10345. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10346. {
  10347. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10348. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10349. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10350. {
  10351. //Reserved
  10352. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10353. }
  10354. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10355. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10356. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10357. {
  10358. //Reserved
  10359. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10360. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10361. goto end;
  10362. }
  10363. else
  10364. {
  10365. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10366. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10367. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10368. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10369. {
  10370. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10371. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10372. goto end;
  10373. }
  10374. }// END FOR ELSE
  10375. }
  10376. } // END FOR GB_QUANTITY
  10377. }
  10378. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10379. {
  10380. tempIndex = connectorIdInt -1;
  10381. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10382. {
  10383. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10384. {
  10385. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10386. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10387. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10388. {
  10389. //Reserved
  10390. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10391. }
  10392. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10393. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10394. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10395. {
  10396. //Reserved
  10397. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10398. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10399. goto end;
  10400. }
  10401. else
  10402. {
  10403. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10404. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10405. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10406. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10407. {
  10408. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10409. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10410. goto end;
  10411. }
  10412. }// END FOR ELSE
  10413. }
  10414. } // END FOR GB_QUANTITY
  10415. }
  10416. else
  10417. {
  10418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10419. {
  10420. tempIndex = 2;
  10421. }
  10422. else
  10423. {
  10424. tempIndex = connectorIdInt -1;
  10425. }
  10426. for (int index = 0; index < AC_QUANTITY; index++)
  10427. {
  10428. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10429. {
  10430. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10431. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10432. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10433. {
  10434. //Reserved
  10435. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10436. }
  10437. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10438. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10439. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10440. {
  10441. //Reserved
  10442. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10443. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10444. goto end;
  10445. }
  10446. else
  10447. {
  10448. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10449. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10450. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10451. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10452. {
  10453. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10454. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10455. goto end;
  10456. }
  10457. }//END FOR ELSE
  10458. }
  10459. }// END FOR AC_QUANTITY
  10460. }
  10461. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10462. {
  10463. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10464. {
  10465. // Save profile to file
  10466. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10467. system(cmdBuf);
  10468. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10469. fp = fopen(cmdBuf, "w");
  10470. 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));
  10471. fclose(fp);
  10472. }
  10473. else
  10474. {
  10475. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10476. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10477. goto end;
  10478. }
  10479. }
  10480. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10481. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10482. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10483. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10484. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10486. }
  10487. else
  10488. {
  10489. uint8_t isHasIdleConnector = FALSE;
  10490. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10491. {
  10492. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10493. {
  10494. isHasIdleConnector = TRUE;
  10495. break;
  10496. }
  10497. }
  10498. if(isHasIdleConnector == TRUE)
  10499. {
  10500. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10501. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10502. {
  10503. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10504. {
  10505. // Save profile to file
  10506. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10507. system(cmdBuf);
  10508. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10509. fp = fopen(cmdBuf, "w");
  10510. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10511. fclose(fp);
  10512. refreshStartTimer(&clientTime.RemoteStartWait);
  10513. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10514. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10515. }
  10516. else
  10517. {
  10518. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10519. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10520. }
  10521. }
  10522. else
  10523. {
  10524. refreshStartTimer(&clientTime.RemoteStartWait);
  10525. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10526. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10527. }
  10528. }
  10529. else
  10530. {
  10531. DEBUG_INFO("There is not any connector is idle.\n");
  10532. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10533. }
  10534. }
  10535. }
  10536. else
  10537. {
  10538. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10539. }
  10540. end:
  10541. json_object_put(RemoteStartTransaction);
  10542. sendRemoteStartConfirmation(uuid, comfirmstr);
  10543. return result;
  10544. }
  10545. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10546. {
  10547. mtrace();
  10548. int result = FAIL;
  10549. int match = FALSE;
  10550. int GunNO = 0;
  10551. int tempIndex = 0;
  10552. int transactionIdInt=0;
  10553. int transactionIdIsNULL= TRUE;
  10554. char comfirmstr[20];
  10555. json_object *RemoteStopTransaction;
  10556. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10557. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10558. if(server_pending == TRUE)
  10559. {
  10560. return 0;
  10561. }
  10562. RemoteStopTransaction = json_tokener_parse(payload);
  10563. if(!is_error(RemoteStopTransaction))
  10564. {
  10565. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10566. {
  10567. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10568. transactionIdIsNULL = FALSE;
  10569. }
  10570. }
  10571. json_object_put(RemoteStopTransaction);
  10572. if(transactionIdIsNULL == FALSE)
  10573. {
  10574. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10575. {
  10576. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10577. {
  10578. //check Transaction active
  10579. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10580. {
  10581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10582. {
  10583. tempIndex = ((gun_index==2) ? 1: 0);
  10584. }
  10585. else
  10586. {
  10587. tempIndex = gun_index;
  10588. }
  10589. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10590. {
  10591. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10592. {
  10593. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10594. {
  10595. match = TRUE;
  10596. GunNO = gun_index;
  10597. }
  10598. }
  10599. }// END FOR CHAdeMO_QUANTITY
  10600. }
  10601. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10602. {
  10603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10604. {
  10605. tempIndex = ((gun_index==2) ? 1: 0);
  10606. }
  10607. else
  10608. {
  10609. tempIndex = gun_index;
  10610. }
  10611. for (int index = 0; index < CCS_QUANTITY; index++)
  10612. {
  10613. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10614. {
  10615. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10616. {
  10617. match = TRUE;
  10618. GunNO = gun_index;
  10619. }
  10620. }
  10621. }// END FOR CCS_QUANTITY
  10622. }
  10623. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10624. {
  10625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10626. {
  10627. tempIndex = ((gun_index==2) ? 1: 0);
  10628. }
  10629. else
  10630. {
  10631. tempIndex = gun_index;
  10632. }
  10633. for (int index = 0; index < GB_QUANTITY; index++)
  10634. {
  10635. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10636. {
  10637. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10638. {
  10639. match = TRUE;
  10640. GunNO = gun_index;
  10641. }
  10642. }
  10643. }// END FOR GB_QUANTITY
  10644. }
  10645. else if(gunType[gun_index] == GUN_TYPE_DO)
  10646. {
  10647. tempIndex = gun_index;
  10648. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10649. {
  10650. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10651. {
  10652. 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
  10653. {
  10654. match = TRUE;
  10655. GunNO = gun_index;
  10656. }
  10657. }
  10658. }// END FOR GB_QUANTITY
  10659. }
  10660. else
  10661. {
  10662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10663. {
  10664. tempIndex = 2;
  10665. }
  10666. else
  10667. {
  10668. tempIndex = gun_index;
  10669. }
  10670. for (int index = 0; index < AC_QUANTITY; index++)
  10671. {
  10672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10673. {
  10674. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10675. {
  10676. match = TRUE;
  10677. GunNO = gun_index;
  10678. }
  10679. }
  10680. }// END FOR CHAdeMO_QUANTITY
  10681. } // END FOR AC ELSE
  10682. }// CHECK IF ResponseTransactionId == transactionIdInt
  10683. }//END FOR
  10684. if( match == TRUE)
  10685. {
  10686. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10687. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10688. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10689. }
  10690. else
  10691. {
  10692. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10693. }
  10694. }
  10695. else
  10696. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10697. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10698. return result;
  10699. }
  10700. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10701. {
  10702. mtrace();
  10703. int result = FAIL;
  10704. int connectorIdInt=0, reservationIdInt=0;
  10705. int tempIndex = 0;
  10706. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10707. char comfirmstr[20]={0};
  10708. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10709. int c = 0;
  10710. char *loc;
  10711. //char *ptr;
  10712. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10713. strcpy(sstrtemp, stringtrimspace(payload));
  10714. //***(1)connectorId ****/
  10715. c=0;
  10716. loc = strstr(sstrtemp, "connectorId");
  10717. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10718. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10719. {
  10720. sstr[c] = loc[strlen("connectorId")+2+c];
  10721. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10722. c++;
  10723. }
  10724. sstr[c] = '\0';
  10725. connectorIdInt = atoi(sstr);
  10726. //***(2)expiryDate ****/
  10727. loc = strstr(sstrtemp, "expiryDate");
  10728. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10729. c = 0;
  10730. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10731. {
  10732. sstr[c] = loc[3+strlen("expiryDate")+c];
  10733. c++;
  10734. }
  10735. sstr[c] = '\0';
  10736. strcpy(expiryDatestr, sstr);
  10737. //***(3)idTag ****/
  10738. loc = strstr(sstrtemp, "idTag");
  10739. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10740. c = 0;
  10741. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10742. {
  10743. sstr[c] = loc[3+strlen("idTag")+c];
  10744. c++;
  10745. }
  10746. sstr[c] = '\0';
  10747. strcpy(idTagstr, sstr);
  10748. //***(4)parentIdTag ****/
  10749. loc = strstr(sstrtemp, "parentIdTag");
  10750. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10751. c = 0;
  10752. if(loc == NULL)
  10753. {
  10754. strcpy(parentIdTagstr, "");
  10755. }
  10756. else
  10757. {
  10758. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10759. {
  10760. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10761. c++;
  10762. }
  10763. sstr[c] = '\0';
  10764. strcpy(parentIdTagstr, sstr);
  10765. }
  10766. //***(5)reservationId ****/
  10767. c=0;
  10768. loc = strstr(sstrtemp, "reservationId");
  10769. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10770. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10771. {
  10772. sstr[c] = loc[strlen("reservationId")+2+c];
  10773. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10774. c++;
  10775. }
  10776. sstr[c] = '\0';
  10777. reservationIdInt = atoi(sstr);
  10778. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10779. /*
  10780. enum SYSTEM_STATUS
  10781. {
  10782. SYS_MODE_BOOTING = 0,
  10783. SYS_MODE_IDLE = 1,
  10784. SYS_MODE_AUTHORIZING = 2,
  10785. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10786. SYS_MODE_REASSIGN = 4,
  10787. SYS_MODE_PREPARING = 5,
  10788. SYS_MODE_PREPARE_FOR_EV = 6,
  10789. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10790. SYS_MODE_CHARGING = 8,
  10791. SYS_MODE_TERMINATING = 9,
  10792. SYS_MODE_COMPLETE = 10,
  10793. SYS_MODE_ALARM = 11,
  10794. SYS_MODE_FAULT = 12,
  10795. SYS_MODE_RESERVATION = 13,
  10796. SYS_MODE_BOOKING = 14,
  10797. SYS_MODE_MAINTAIN = 15,
  10798. SYS_MODE_DEBUG = 16,
  10799. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10800. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10801. SYS_MODE_UPDATE = 19
  10802. };
  10803. */
  10804. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10805. {
  10806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10807. goto end;
  10808. }
  10809. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10810. {
  10811. //check Transaction active
  10812. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10813. {
  10814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10815. {
  10816. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10817. }
  10818. else
  10819. {
  10820. tempIndex = connectorIdInt -1;
  10821. }
  10822. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10823. {
  10824. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10825. {
  10826. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10827. {
  10828. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10829. {
  10830. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10831. {
  10832. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10833. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10834. }
  10835. 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'))
  10836. {
  10837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10838. }
  10839. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10840. {
  10841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10842. }
  10843. else
  10844. {
  10845. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10846. }
  10847. }
  10848. 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
  10849. {
  10850. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10851. }
  10852. }
  10853. else
  10854. {
  10855. //replace reservation
  10856. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10858. }
  10859. }
  10860. } // END FOR CHAdeMO_QUANTITY
  10861. }
  10862. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10863. {
  10864. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10865. {
  10866. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10867. }
  10868. else
  10869. {
  10870. tempIndex = connectorIdInt -1;
  10871. }
  10872. for (int index = 0; index < CCS_QUANTITY; index++)
  10873. {
  10874. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10875. {
  10876. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10877. {
  10878. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10879. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10880. {
  10881. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10882. {
  10883. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10885. }
  10886. 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'))
  10887. {
  10888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10889. }
  10890. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10891. {
  10892. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10893. }
  10894. else
  10895. {
  10896. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10897. }
  10898. }
  10899. 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
  10900. {
  10901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10902. }
  10903. }
  10904. else
  10905. {
  10906. //replace reservation
  10907. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10908. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10909. }
  10910. }
  10911. } // END FOR CCS_QUANTITY
  10912. }
  10913. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10914. {
  10915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10916. {
  10917. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10918. }
  10919. else
  10920. {
  10921. tempIndex = connectorIdInt -1;
  10922. }
  10923. for (int index = 0; index < GB_QUANTITY; index++)
  10924. {
  10925. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10926. {
  10927. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10928. {
  10929. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10930. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10931. {
  10932. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10933. {
  10934. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10936. }
  10937. 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'))
  10938. {
  10939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10940. }
  10941. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10942. {
  10943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10944. }
  10945. else
  10946. {
  10947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10948. }
  10949. }
  10950. 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
  10951. {
  10952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10953. }
  10954. }
  10955. else
  10956. {
  10957. //replace reservation
  10958. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10959. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10960. }
  10961. }
  10962. }// END FOR GB_QUANTITY
  10963. }
  10964. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10965. {
  10966. tempIndex = connectorIdInt -1;
  10967. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10968. {
  10969. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10970. {
  10971. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10972. {
  10973. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10974. 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
  10975. {
  10976. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10977. {
  10978. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10980. }
  10981. 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'))
  10982. {
  10983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10984. }
  10985. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10986. {
  10987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10988. }
  10989. else
  10990. {
  10991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10992. }
  10993. }
  10994. 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
  10995. {
  10996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10997. }
  10998. }
  10999. else
  11000. {
  11001. //replace reservation
  11002. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11004. }
  11005. }
  11006. }// END FOR GB_QUANTITY
  11007. }
  11008. else
  11009. {
  11010. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11011. {
  11012. tempIndex = 2;
  11013. }
  11014. else
  11015. {
  11016. tempIndex = (connectorIdInt -1);
  11017. }
  11018. for (int index = 0; index < AC_QUANTITY; index++)
  11019. {
  11020. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11021. {
  11022. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11023. {
  11024. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11025. {
  11026. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11027. {
  11028. 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))
  11029. {
  11030. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11031. }
  11032. else
  11033. {
  11034. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11035. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11036. }
  11037. }
  11038. 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'))
  11039. {
  11040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11041. }
  11042. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11043. {
  11044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11045. }
  11046. else
  11047. {
  11048. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11049. }
  11050. }
  11051. 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
  11052. {
  11053. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11054. }
  11055. }
  11056. else
  11057. {
  11058. //replace reservation
  11059. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11061. }
  11062. }
  11063. } // END FOR AC_QUANTITY
  11064. }
  11065. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11066. }
  11067. else if(connectorIdInt == 0)
  11068. {
  11069. //check Transaction active
  11070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11071. {
  11072. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11073. {
  11074. 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'))
  11075. {
  11076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11077. goto end;
  11078. }
  11079. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11080. {
  11081. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11082. goto end;
  11083. }
  11084. 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
  11085. {
  11086. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11087. goto end;
  11088. }
  11089. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11090. {
  11091. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11092. goto end;
  11093. }
  11094. }
  11095. }// END FOR CHAdeMO_QUANTITY
  11096. for (int index = 0; index < CCS_QUANTITY; index++)
  11097. {
  11098. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11099. {
  11100. 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'))
  11101. {
  11102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11103. goto end;
  11104. }
  11105. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11106. {
  11107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11108. goto end;
  11109. }
  11110. 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
  11111. {
  11112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11113. goto end;
  11114. }
  11115. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11116. {
  11117. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11118. goto end;
  11119. }
  11120. }
  11121. } // END FOR CCS_QUANTITY
  11122. for (int index = 0; index < GB_QUANTITY; index++)
  11123. {
  11124. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11125. {
  11126. 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'))
  11127. {
  11128. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11129. goto end;
  11130. }
  11131. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11132. {
  11133. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11134. goto end;
  11135. }
  11136. 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
  11137. {
  11138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11139. goto end;
  11140. }
  11141. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11142. {
  11143. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11144. goto end;
  11145. }
  11146. }
  11147. } // END FOR GB_QUANTITY
  11148. for (int index = 0; index < AC_QUANTITY; index++)
  11149. {
  11150. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11151. {
  11152. 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'))
  11153. {
  11154. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11155. goto end;
  11156. }
  11157. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11158. {
  11159. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11160. goto end;
  11161. }
  11162. 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
  11163. {
  11164. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11165. goto end;
  11166. }
  11167. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11168. {
  11169. 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))
  11170. {
  11171. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11172. goto end;
  11173. }
  11174. }
  11175. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11176. {
  11177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11178. goto end;
  11179. }
  11180. }
  11181. }// END FOR AC_QUANTITY
  11182. //The connectorId is 0
  11183. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11184. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11185. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11186. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11187. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11188. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11189. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11190. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11191. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11192. result = TRUE;
  11193. return result;
  11194. }
  11195. else
  11196. {
  11197. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11198. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11199. }
  11200. if(strcmp(comfirmstr,"Accepted") == 0)
  11201. {
  11202. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11203. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11204. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11205. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11206. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11207. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11208. result = TRUE;
  11209. return result;
  11210. }
  11211. end:
  11212. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11213. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11214. return result;
  11215. }
  11216. int handleResetRequest(char *uuid, char *payload)
  11217. {
  11218. mtrace();
  11219. int result = FAIL;
  11220. char sstr[10]={0},sstrtemp[30]={ 0 };
  11221. char typestr[10]={0};
  11222. char comfirmstr[20]={0};
  11223. int c = 0;
  11224. char *loc;
  11225. DEBUG_INFO("handleResetRequest...\n");
  11226. strcpy(sstrtemp, stringtrimspace(payload));
  11227. loc = strstr(sstrtemp, "type");
  11228. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11229. c = 0;
  11230. while (loc[3+strlen("type")+c] != '\"')
  11231. {
  11232. sstr[c] = loc[3+strlen("type")+c];
  11233. c++;
  11234. }
  11235. sstr[c] = '\0';
  11236. strcpy(typestr,sstr);
  11237. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11238. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11239. {
  11240. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11241. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11242. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11243. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11244. }
  11245. else
  11246. {
  11247. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11248. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11249. result = PASS;
  11250. }
  11251. sendResetConfirmation(uuid, comfirmstr);
  11252. return result;
  11253. }
  11254. int handleSendLocalListRequest(char *uuid, char *payload)
  11255. {
  11256. mtrace();
  11257. int result = FAIL;
  11258. char comfirmstr[20];
  11259. int checkState_Faulted = FALSE;
  11260. json_object *SendLocalList;
  11261. DEBUG_INFO("handleSendLocalListRequest...\n");
  11262. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11263. {
  11264. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11265. goto end;
  11266. }
  11267. //check Charge Point state
  11268. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11269. {
  11270. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11271. {
  11272. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11273. }
  11274. }
  11275. for (int index = 0; index < CCS_QUANTITY; index++)
  11276. {
  11277. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11278. {
  11279. checkState_Faulted = TRUE; //OCPP Status
  11280. }
  11281. }
  11282. for (int index = 0; index < GB_QUANTITY; index++)
  11283. {
  11284. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11285. {
  11286. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11287. }
  11288. }
  11289. //check Charge Point state
  11290. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11291. {
  11292. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11293. {
  11294. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11295. }
  11296. }
  11297. //check Charge Point state
  11298. for (int index = 0; index < AC_QUANTITY; index++)
  11299. {
  11300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11301. {
  11302. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11303. }
  11304. }
  11305. if(checkState_Faulted == TRUE)
  11306. {
  11307. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11308. goto end;
  11309. }
  11310. // Parsing payload
  11311. SendLocalList = json_tokener_parse(payload);
  11312. if(!is_error(SendLocalList))
  11313. {
  11314. // Required data
  11315. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11316. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11317. // Optional data
  11318. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11319. {
  11320. //Check UpdateType
  11321. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11322. {
  11323. //Local list full update
  11324. DEBUG_INFO("Local list full update.\n");
  11325. OCPP_getListVerion();
  11326. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11327. {
  11328. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11329. goto end;
  11330. }
  11331. OCPP_cleanLocalList();
  11332. }
  11333. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11334. {
  11335. //Local list different update
  11336. DEBUG_INFO("Local list different update.\n");
  11337. OCPP_getListVerion();
  11338. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11339. {
  11340. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11341. goto end;
  11342. }
  11343. }
  11344. else
  11345. {
  11346. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11347. goto end;
  11348. }
  11349. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11350. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11351. {
  11352. 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")));
  11353. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11354. {
  11355. 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")));
  11356. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11357. 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")));
  11358. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11359. 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")));
  11360. }
  11361. // Add to db
  11362. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11363. {
  11364. //Local list full update
  11365. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11366. idx,
  11367. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11368. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11369. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11370. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11371. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11372. // update list
  11373. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11374. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11375. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11376. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11377. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11378. }
  11379. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11380. {
  11381. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11382. idx,
  11383. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11384. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11385. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11386. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11387. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11388. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11389. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11390. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11391. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11392. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11393. }
  11394. }
  11395. }
  11396. else
  11397. {
  11398. //Check UpdateType
  11399. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11400. {
  11401. //Local list full update
  11402. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11403. OCPP_cleanLocalList();
  11404. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11405. goto end;
  11406. }
  11407. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11408. {
  11409. //Local list different update
  11410. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11411. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11412. goto end;
  11413. }
  11414. }
  11415. result = PASS;
  11416. }
  11417. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11418. end:
  11419. json_object_put(SendLocalList);
  11420. sendSendLocalListConfirmation(uuid, comfirmstr);
  11421. return result;
  11422. }
  11423. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11424. {
  11425. mtrace();
  11426. int result = FAIL;
  11427. struct StructSetChargingProfile SetProfileReq = {0};
  11428. int tempchargingProfileIdInt;
  11429. int chargingSchedulePeriodCount = 0;
  11430. char comfirmstr[20]={0};
  11431. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11432. char rmFileCmd[128]={0};
  11433. int profileQuantity = 0;
  11434. json_object *SetChargingProfile;
  11435. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11436. SetChargingProfile = json_tokener_parse(payload);
  11437. if(!is_error(SetChargingProfile))
  11438. {
  11439. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11440. {
  11441. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11442. }
  11443. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11444. {
  11445. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11446. {
  11447. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11448. }
  11449. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11450. {
  11451. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11452. }
  11453. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11454. {
  11455. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11456. }
  11457. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11458. {
  11459. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11460. }
  11461. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11462. {
  11463. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11464. }
  11465. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11466. {
  11467. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11468. }
  11469. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11470. {
  11471. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11472. }
  11473. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11474. {
  11475. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11476. }
  11477. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11478. {
  11479. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11480. {
  11481. 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")));
  11482. }
  11483. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11484. {
  11485. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11486. }
  11487. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11488. {
  11489. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11490. }
  11491. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11492. {
  11493. 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")));
  11494. }
  11495. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11496. {
  11497. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11498. if(chargingSchedulePeriodCount <= 10)
  11499. {
  11500. 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++)
  11501. {
  11502. 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)
  11503. {
  11504. 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"));
  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), "limit") != NULL)
  11507. {
  11508. 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"));
  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), "numberPhases") != NULL)
  11511. {
  11512. 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"));
  11513. }
  11514. }
  11515. }
  11516. }
  11517. }
  11518. }
  11519. }
  11520. // Profile periods quantity check
  11521. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11522. {
  11523. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11524. goto end;
  11525. }
  11526. // Check invalid limit
  11527. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11528. {
  11529. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11530. {
  11531. 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)))) ||
  11532. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11533. {
  11534. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11535. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11536. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11537. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11538. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11539. goto end;
  11540. }
  11541. }
  11542. }
  11543. else
  11544. {
  11545. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11546. {
  11547. 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))
  11548. {
  11549. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11550. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11551. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11552. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11553. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11554. goto end;
  11555. }
  11556. }
  11557. }
  11558. // Profile purpose info check
  11559. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11560. {
  11561. FILE *fp;
  11562. char dataLine[4096]={0};
  11563. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11564. if(SetProfileReq.ConnectorId != 0)
  11565. {
  11566. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11567. goto end;
  11568. }
  11569. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11570. if (!fp)
  11571. {
  11572. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11573. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11574. }
  11575. else
  11576. {
  11577. while(fscanf(fp, "%s", dataLine) != EOF)
  11578. {
  11579. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11580. {
  11581. profileQuantity += 1;
  11582. }
  11583. }
  11584. }
  11585. fclose(fp);
  11586. }
  11587. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11588. {
  11589. FILE *fp;
  11590. char dataLine[4096]={0};
  11591. char filename[128]={0};
  11592. int tmpProfileQuantity;
  11593. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11594. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11595. {
  11596. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11597. goto end;
  11598. }
  11599. if(SetProfileReq.ConnectorId == 0)
  11600. {
  11601. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11602. {
  11603. tmpProfileQuantity = 0;
  11604. memset(filename, 0, ARRAY_SIZE(filename));
  11605. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11606. fp = fopen(filename, "r");
  11607. if (!fp)
  11608. {
  11609. DEBUG_INFO("%s does not create.\n", filename);
  11610. fp = fopen(filename, "w+");
  11611. }
  11612. else
  11613. {
  11614. while(fscanf(fp, "%s", dataLine) != EOF)
  11615. {
  11616. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11617. {
  11618. tmpProfileQuantity += 1;
  11619. }
  11620. }
  11621. }
  11622. fclose(fp);
  11623. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11624. }
  11625. }
  11626. else
  11627. {
  11628. memset(filename, 0, ARRAY_SIZE(filename));
  11629. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11630. fp = fopen(filename, "r");
  11631. if (!fp)
  11632. {
  11633. DEBUG_INFO("%s does not create.\n", filename);
  11634. fp = fopen(filename, "w+");
  11635. }
  11636. else
  11637. {
  11638. while(fscanf(fp, "%s", dataLine) != EOF)
  11639. {
  11640. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11641. {
  11642. profileQuantity += 1;
  11643. }
  11644. }
  11645. }
  11646. fclose(fp);
  11647. }
  11648. }
  11649. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11650. {
  11651. int isMatchTransactiodId= FALSE;
  11652. FILE *fp;
  11653. char dataLine[4096]={0};
  11654. char filename[128]={0};
  11655. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11656. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11657. if(SetProfileReq.ConnectorId == 0)
  11658. {
  11659. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11660. goto end;
  11661. }
  11662. int tempIndex = 0;
  11663. //check Transaction active
  11664. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11665. {
  11666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11667. {
  11668. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11669. }
  11670. else
  11671. {
  11672. tempIndex = SetProfileReq.ConnectorId -1;
  11673. }
  11674. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11675. {
  11676. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11677. {
  11678. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11679. {
  11680. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11681. {
  11682. isMatchTransactiodId = TRUE;
  11683. break;
  11684. }
  11685. }
  11686. }
  11687. }
  11688. }
  11689. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11690. {
  11691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11692. {
  11693. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11694. }
  11695. else
  11696. {
  11697. tempIndex = SetProfileReq.ConnectorId -1;
  11698. }
  11699. for (int index = 0; index < CCS_QUANTITY; index++)
  11700. {
  11701. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11702. {
  11703. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11704. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11705. {
  11706. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11707. {
  11708. isMatchTransactiodId = TRUE;
  11709. break;
  11710. }
  11711. }
  11712. }
  11713. }
  11714. }
  11715. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11716. {
  11717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11718. {
  11719. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11720. }
  11721. else
  11722. {
  11723. tempIndex = SetProfileReq.ConnectorId -1;
  11724. }
  11725. for (int index = 0; index < GB_QUANTITY; index++)
  11726. {
  11727. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11728. {
  11729. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11730. {
  11731. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11732. {
  11733. isMatchTransactiodId = TRUE;
  11734. break;
  11735. }
  11736. }
  11737. }
  11738. }
  11739. }
  11740. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11741. {
  11742. tempIndex = SetProfileReq.ConnectorId -1;
  11743. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11744. {
  11745. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11746. {
  11747. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11748. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11749. {
  11750. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11751. {
  11752. isMatchTransactiodId = TRUE;
  11753. break;
  11754. }
  11755. }
  11756. }
  11757. }
  11758. }
  11759. else
  11760. {
  11761. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11762. {
  11763. tempIndex = 2;
  11764. }
  11765. else
  11766. {
  11767. tempIndex = (SetProfileReq.ConnectorId -1);
  11768. }
  11769. for (int index = 0; index < AC_QUANTITY; index++)
  11770. {
  11771. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11772. {
  11773. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11774. {
  11775. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11776. {
  11777. isMatchTransactiodId = TRUE;
  11778. break;
  11779. }
  11780. }
  11781. }
  11782. }
  11783. }
  11784. //check Transaction active
  11785. if(isMatchTransactiodId == FALSE)
  11786. {
  11787. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11788. goto end;
  11789. }
  11790. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11791. {
  11792. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11793. goto end;
  11794. }
  11795. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11796. fp = fopen(filename, "r");
  11797. if (!fp)
  11798. {
  11799. DEBUG_INFO("%s does not create.\n", filename);
  11800. fp = fopen(filename, "w+");
  11801. }
  11802. else
  11803. {
  11804. //Check Charging Profile Count
  11805. while(fscanf(fp, "%s", dataLine) != EOF)
  11806. {
  11807. //DEBUG_INFO("word=%s\n",word);
  11808. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11809. {
  11810. profileQuantity += 1;
  11811. }
  11812. }
  11813. }
  11814. fclose(fp);
  11815. }
  11816. // Check ChargeProfileMaxStackLevel
  11817. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11818. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11819. {
  11820. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11821. goto end;
  11822. }
  11823. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11824. {
  11825. FILE *fp;
  11826. char dataLine[4096]={0};
  11827. char fnametemp[128]={0};
  11828. int tmpProfileQuantity;
  11829. //Check ChargePointMaxProfile.json exit
  11830. profileQuantity = 0;
  11831. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11832. {
  11833. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11834. //Check Charging Profile Count
  11835. tmpProfileQuantity = 0;
  11836. while(fscanf(fp, "%s", dataLine) != EOF)
  11837. {
  11838. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11839. {
  11840. profileQuantity += 1;
  11841. tmpProfileQuantity += 1;
  11842. }
  11843. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11844. }
  11845. fclose(fp);
  11846. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11847. }
  11848. //Check TxDefaultProfile_%d.json
  11849. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11850. {
  11851. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11852. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11853. if((access(fnametemp,F_OK))!=-1)
  11854. {
  11855. fp = fopen(fnametemp, "r");
  11856. //Check Charging Profile Count
  11857. tmpProfileQuantity = 0;
  11858. while(fscanf(fp, "%s", dataLine) != EOF)
  11859. {
  11860. //DEBUG_INFO("word=%s\n",word);
  11861. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11862. {
  11863. profileQuantity += 1;
  11864. tmpProfileQuantity += 1;
  11865. }
  11866. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11867. }
  11868. fclose(fp);
  11869. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11870. }
  11871. }
  11872. //Check TxProfile_%d.json
  11873. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11874. {
  11875. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11876. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11877. if((access(fnametemp,F_OK))!=-1)
  11878. {
  11879. fp = fopen(fnametemp, "r");
  11880. //Check Charging Profile Count
  11881. tmpProfileQuantity = 0;
  11882. while(fscanf(fp, "%s", dataLine) != EOF)
  11883. {
  11884. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11885. {
  11886. profileQuantity += 1;
  11887. tmpProfileQuantity += 1;
  11888. }
  11889. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11890. }
  11891. fclose(fp);
  11892. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11893. }
  11894. }
  11895. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11896. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11897. {
  11898. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11899. goto end;
  11900. }
  11901. }
  11902. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11903. //**********************************Write to File********************************************************/
  11904. {
  11905. FILE *infile;
  11906. FILE *outfile;
  11907. char dataLine[4096]={0};
  11908. char filename[128]={0};
  11909. int chkChar=0;
  11910. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11911. {
  11912. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11913. {
  11914. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11915. }
  11916. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11917. {
  11918. if(SetProfileReq.ConnectorId==0)
  11919. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11920. else
  11921. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11922. }
  11923. else
  11924. {
  11925. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11926. }
  11927. infile = fopen (filename, "r");
  11928. outfile = fopen (tempfile, "w");
  11929. chkChar = fgetc(infile);
  11930. rewind(infile);
  11931. if(chkChar == EOF)
  11932. {
  11933. // Profile is empty
  11934. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11935. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11936. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11937. fclose(infile);
  11938. fclose(outfile);
  11939. sprintf(rmFileCmd,"rm -f %s",filename);
  11940. system(rmFileCmd);
  11941. rename(tempfile, filename);
  11942. }
  11943. else
  11944. {
  11945. // Profile is not empty
  11946. int ChargingProfileAdded = FALSE;
  11947. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11948. {
  11949. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11950. json_object *tmpChargingProfile;
  11951. tmpChargingProfile = json_tokener_parse(dataLine);
  11952. if(!is_error(SetChargingProfile))
  11953. {
  11954. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11955. {
  11956. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11957. {
  11958. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11959. }
  11960. }
  11961. }
  11962. json_object_put(tmpChargingProfile);
  11963. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11964. {
  11965. if(ChargingProfileAdded == FALSE)
  11966. {
  11967. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11968. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11969. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11970. ChargingProfileAdded = TRUE;
  11971. }
  11972. }
  11973. else
  11974. {
  11975. fprintf(outfile,"%s\n",dataLine);
  11976. if(ChargingProfileAdded == FALSE)
  11977. {
  11978. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11979. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11980. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11981. ChargingProfileAdded = TRUE;
  11982. }
  11983. }
  11984. } // end of while loop
  11985. fclose(infile);
  11986. fclose(outfile);
  11987. sprintf(rmFileCmd,"rm -f %s",filename);
  11988. system(rmFileCmd);
  11989. rename(tempfile, filename);
  11990. }
  11991. }
  11992. sleep(1);
  11993. result = TRUE;
  11994. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11995. }
  11996. end:
  11997. json_object_put(SetChargingProfile);
  11998. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11999. {
  12000. if(SetProfileReq.ConnectorId == 0)
  12001. {
  12002. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12003. {
  12004. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12005. }
  12006. }
  12007. else
  12008. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12009. }
  12010. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12011. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12012. return result;
  12013. }
  12014. int handleTriggerMessageRequest(char *uuid, char *payload)
  12015. {
  12016. mtrace();
  12017. int result = FAIL;
  12018. int connectorIdIsNULL = FALSE;
  12019. int connectorIdInt =0;
  12020. char sstr[40]={0},sstrtemp[100]={ 0 };
  12021. char requestedMessagestr[40]={0};
  12022. char comfirmstr[20]={0};
  12023. int c = 0;
  12024. char *loc;
  12025. DEBUG_INFO("handleTriggerMessageRequest\n");
  12026. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12027. strcpy(sstrtemp, stringtrimspace(payload));
  12028. c = 0;
  12029. loc = strstr(sstrtemp, "requestedMessage");
  12030. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12031. {
  12032. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12033. c++;
  12034. }
  12035. sstr[c] = '\0';
  12036. strcpy(requestedMessagestr, sstr);
  12037. c = 0;
  12038. loc = strstr(sstrtemp, "connectorId");
  12039. if(loc == NULL)
  12040. {
  12041. connectorIdIsNULL = TRUE;
  12042. }
  12043. else
  12044. {
  12045. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12046. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12047. {
  12048. sstr[c] = loc[strlen("connectorId")+2+c];
  12049. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12050. c++;
  12051. }
  12052. sstr[c] = '\0';
  12053. connectorIdInt = atoi(sstr);
  12054. }
  12055. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12056. {
  12057. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12058. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12059. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12060. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12061. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12062. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12063. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12064. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12065. {
  12066. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12067. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12068. return TRUE;
  12069. }
  12070. else
  12071. {
  12072. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12073. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12074. }
  12075. }
  12076. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12077. {
  12078. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12079. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12080. return TRUE;
  12081. }
  12082. //==========================
  12083. // Trigger message
  12084. //==========================
  12085. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12086. {
  12087. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12088. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12089. {
  12090. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12091. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12092. }
  12093. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12094. }
  12095. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12096. {
  12097. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12098. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12099. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12100. }
  12101. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12102. {
  12103. //sendBootNotificationRequest();
  12104. server_sign = FALSE;
  12105. }
  12106. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12107. {
  12108. refreshStartTimer(&clientTime.Heartbeat);
  12109. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12110. }
  12111. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12112. {
  12113. if(connectorIdIsNULL == FALSE)
  12114. {
  12115. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12116. {
  12117. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12118. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12119. }
  12120. }
  12121. else
  12122. {
  12123. for(int idx=0;idx< gunTotalNumber;idx++)
  12124. {
  12125. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12126. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12127. }
  12128. }
  12129. }
  12130. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12131. {
  12132. if(connectorIdIsNULL == FALSE)
  12133. {
  12134. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12135. {
  12136. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12137. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12138. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12139. }
  12140. }
  12141. else
  12142. {
  12143. for(int idx=0;idx< gunTotalNumber;idx++)
  12144. {
  12145. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12146. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12147. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12148. }
  12149. }
  12150. }
  12151. return result;
  12152. }
  12153. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12154. {
  12155. mtrace();
  12156. int result = FAIL;
  12157. int connectorIdInt =0;
  12158. char comfirmstr[20]={0};
  12159. int tempIndex = 0;
  12160. json_object *UnlockConnector;
  12161. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12162. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12163. UnlockConnector = json_tokener_parse(payload);
  12164. if(!is_error(UnlockConnector))
  12165. {
  12166. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12167. {
  12168. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12169. }
  12170. }
  12171. json_object_put(UnlockConnector);
  12172. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12173. if(gunTotalNumber == 0)
  12174. {
  12175. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12176. goto end;
  12177. }
  12178. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12179. {
  12180. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12181. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12182. goto end;
  12183. }
  12184. else
  12185. {
  12186. //check Transaction active
  12187. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12188. {
  12189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12190. {
  12191. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12192. }
  12193. else
  12194. {
  12195. tempIndex = connectorIdInt -1;
  12196. }
  12197. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12198. {
  12199. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12200. {
  12201. //stop Transaction
  12202. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12203. }
  12204. }
  12205. }
  12206. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12207. {
  12208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12209. {
  12210. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12211. }
  12212. else
  12213. {
  12214. tempIndex = connectorIdInt -1;
  12215. }
  12216. for (int index = 0; index < CCS_QUANTITY; index++)
  12217. {
  12218. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12219. {
  12220. //stop Transaction
  12221. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12222. }
  12223. }
  12224. }
  12225. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12226. {
  12227. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12228. {
  12229. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12230. }
  12231. else
  12232. {
  12233. tempIndex = connectorIdInt -1;
  12234. }
  12235. for (int index = 0; index < GB_QUANTITY; index++)
  12236. {
  12237. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12238. {
  12239. //stop Transaction
  12240. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12241. }
  12242. }
  12243. }
  12244. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12245. {
  12246. tempIndex = connectorIdInt -1;
  12247. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12248. {
  12249. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12250. {
  12251. //stop Transaction
  12252. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12253. }
  12254. }
  12255. }
  12256. else
  12257. {
  12258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12259. {
  12260. tempIndex = 2;
  12261. }
  12262. else
  12263. {
  12264. tempIndex = connectorIdInt-1;
  12265. }
  12266. for (int index = 0; index < AC_QUANTITY; index++)
  12267. {
  12268. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12269. {
  12270. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12271. }
  12272. }
  12273. }
  12274. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12275. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12276. result = TRUE;
  12277. return result;
  12278. }
  12279. end:
  12280. //json_object_put(obj); --- remove temporally
  12281. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12282. return result;
  12283. }
  12284. static char UpdateFirmwarepayloadData[300]={0};
  12285. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12286. {
  12287. mtrace();
  12288. int result = FAIL;
  12289. pthread_t t;
  12290. sendUpdateFirmwareConfirmation(uuid);
  12291. memset(UpdateFirmwarepayloadData, 0, 300);
  12292. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12293. if(!interLock.isUpdateFirmwareGoing)
  12294. {
  12295. interLock.isUpdateFirmwareGoing = 1;
  12296. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12297. sleep(1);
  12298. }
  12299. else
  12300. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12301. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12302. return result;
  12303. }
  12304. void *UpdateFirmwareProcess(void *data)
  12305. {
  12306. pthread_detach(pthread_self());
  12307. mtrace();
  12308. int retriesInt =0, retryIntervalInt=0;
  12309. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12310. int port=0;
  12311. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12312. int isSuccess = 0;
  12313. char ftpbuf[512];
  12314. char temp[100];
  12315. char * pch;
  12316. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12317. json_object *UpdateFirmware;
  12318. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12319. if(!is_error(UpdateFirmware))
  12320. {
  12321. // Required data
  12322. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12323. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12324. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12325. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12326. // Optional data
  12327. if(json_object_object_get(UpdateFirmware, "retries"))
  12328. {
  12329. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12330. }
  12331. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12332. {
  12333. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12334. }
  12335. }
  12336. json_object_put(UpdateFirmware);
  12337. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12338. memset(path, 0, ARRAY_SIZE(path));
  12339. // Wait retrieveData
  12340. if(strlen(retrieveDatestr) > 10)
  12341. {
  12342. do
  12343. {
  12344. sleep(1);
  12345. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12346. }
  12347. // Ready to download
  12348. system("rm -f /mnt/*");
  12349. if(strncmp(locationstr,"http", 4) == 0)
  12350. {
  12351. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12352. sprintf(ftppath,"/%s", path);
  12353. DEBUG_INFO("locationstr: %s\n", locationstr);
  12354. DEBUG_INFO("protocol: %s\n",protocol);
  12355. DEBUG_INFO("host: %s\n",host);
  12356. DEBUG_INFO("path: %s\n",path);
  12357. DEBUG_INFO("ftppath: %s\n",ftppath);
  12358. int ftppathlen=strlen(ftppath);
  12359. int i=1;
  12360. char filenametemp[50];
  12361. while(i < ftppathlen)
  12362. {
  12363. int len=ftppathlen-i;
  12364. if(ftppath[len]== 47) // '/' ascll code: 47
  12365. {
  12366. DEBUG_INFO("compare '/' all right\n");
  12367. break;
  12368. }
  12369. i=i+1;
  12370. }
  12371. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12372. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12373. filenametemp[i+1] = 0;
  12374. do
  12375. {
  12376. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12377. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12378. sleep(1);
  12379. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12380. if(!isSuccess)
  12381. {
  12382. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12383. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12384. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12385. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12386. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12387. }
  12388. else
  12389. {
  12390. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12391. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12392. }
  12393. retriesInt--;
  12394. }while((isSuccess == 0)&&(retriesInt >= 0));
  12395. }
  12396. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12397. {
  12398. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12399. memset(temp, 0, ARRAY_SIZE(temp));
  12400. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12401. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12402. int ftppathlen=strlen(ftpbuf);
  12403. int i=1;
  12404. char filenametemp[50];
  12405. while(i < ftppathlen)
  12406. {
  12407. int len=ftppathlen-i;
  12408. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12409. {
  12410. DEBUG_INFO(" compare '/' all right\n");
  12411. break;
  12412. }
  12413. i=i+1;
  12414. }
  12415. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12416. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12417. filenametemp[i+1] = 0;
  12418. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12419. pch=strchr(temp,'@');
  12420. if(pch==NULL)
  12421. {
  12422. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12423. protocol, host, &port, path);
  12424. strcpy(user,"anonymous");
  12425. strcpy(password,"");
  12426. }
  12427. else
  12428. {
  12429. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12430. protocol, user, password, host, &port, path);
  12431. }
  12432. sscanf(host,"%[^/]%s",host1, path1);
  12433. sprintf(ftppath,"%s", path1);
  12434. //DEBUG_INFO("protocol =%s\n",protocol);
  12435. //DEBUG_INFO("user =%s\n",user);
  12436. //DEBUG_INFO("password =%s\n",password);
  12437. //DEBUG_INFO("host1 =%s\n",host1);
  12438. //DEBUG_INFO("port =%d\n",port);
  12439. //DEBUG_INFO("path1 =%s\n",path1);
  12440. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12441. //ftpFile(host, user, password, port, ftppath, fname);
  12442. //download firmware pthred
  12443. if(port == 0)
  12444. {
  12445. port = 21;
  12446. }
  12447. do
  12448. {
  12449. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12450. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12451. sleep(1);
  12452. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12453. if(!isSuccess)
  12454. {
  12455. //BulldogUtil.sleepMs(interval*1000);
  12456. DEBUG_INFO("Update firmware request and download file fail.\n");
  12457. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12458. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12459. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12460. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12461. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12462. }
  12463. else
  12464. {
  12465. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12466. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12467. }
  12468. retriesInt--;
  12469. }while((!isSuccess)&&(retriesInt >= 0));
  12470. }
  12471. else
  12472. {
  12473. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12474. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12475. sleep(1);
  12476. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12477. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12478. }
  12479. // OCPPPH only, must announce CSU upgrade firmware
  12480. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12481. interLock.isUpdateFirmwareGoing = 0;
  12482. pthread_exit(NULL);
  12483. }
  12484. int handleCertificateSignedRequest(char *uuid, char *payload)
  12485. {
  12486. mtrace();
  12487. int result = PASS;
  12488. json_object *CertificateSigned;
  12489. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12490. CertificateSigned = json_tokener_parse(payload);
  12491. if(!is_error(CertificateSigned))
  12492. {
  12493. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12494. }
  12495. json_object_put(CertificateSigned);
  12496. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12497. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12498. fclose(fp);
  12499. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12500. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12501. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12502. sendCertificateSignedConfirmation(uuid);
  12503. return result;
  12504. }
  12505. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12506. {
  12507. mtrace();
  12508. int result = PASS;
  12509. json_object *DeleteCertificate;
  12510. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12511. DeleteCertificate = json_tokener_parse(payload);
  12512. if(!is_error(DeleteCertificate))
  12513. {
  12514. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12515. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12516. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12517. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12518. }
  12519. json_object_put(DeleteCertificate);
  12520. /*
  12521. * TODO: Delete certificateSigned process
  12522. */
  12523. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12524. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12525. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12526. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12527. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12528. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12529. sendDeleteCertificateConfirmation(uuid);
  12530. return result;
  12531. }
  12532. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12533. {
  12534. mtrace();
  12535. int result = PASS;
  12536. json_object *ExtendedTriggerMessage;
  12537. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12538. ExtendedTriggerMessage = json_tokener_parse(payload);
  12539. if(!is_error(ExtendedTriggerMessage))
  12540. {
  12541. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12542. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12543. {
  12544. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12545. }
  12546. else
  12547. {
  12548. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12549. }
  12550. }
  12551. json_object_put(ExtendedTriggerMessage);
  12552. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12553. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12554. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12555. {
  12556. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12557. }
  12558. else
  12559. {
  12560. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12561. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12562. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12563. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12564. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12565. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12566. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12567. {
  12568. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12569. }
  12570. else
  12571. {
  12572. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12573. }
  12574. }
  12575. sendExtendedTriggerMessageConfirmation(uuid);
  12576. //==========================
  12577. // Trigger message
  12578. //==========================
  12579. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12580. {
  12581. //sendBootNotificationRequest();
  12582. server_sign = FALSE;
  12583. }
  12584. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12585. {
  12586. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12587. }
  12588. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12589. {
  12590. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12591. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12592. {
  12593. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12594. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12595. }
  12596. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12597. }
  12598. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12599. {
  12600. refreshStartTimer(&clientTime.Heartbeat);
  12601. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12602. }
  12603. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12604. {
  12605. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12606. {
  12607. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12608. }
  12609. else
  12610. {
  12611. for(int idx=0;idx< gunTotalNumber;idx++)
  12612. {
  12613. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12614. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12615. }
  12616. }
  12617. }
  12618. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12619. {
  12620. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12621. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12622. {
  12623. 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\" &");
  12624. }
  12625. }
  12626. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12627. {
  12628. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12629. {
  12630. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12631. }
  12632. else
  12633. {
  12634. for(int idx=0;idx< gunTotalNumber;idx++)
  12635. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12636. }
  12637. }
  12638. return result;
  12639. }
  12640. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12641. {
  12642. mtrace();
  12643. int result = PASS;
  12644. json_object *GetInstalledCertificateIds;
  12645. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12646. GetInstalledCertificateIds = json_tokener_parse(payload);
  12647. if(!is_error(GetInstalledCertificateIds))
  12648. {
  12649. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12650. }
  12651. json_object_put(GetInstalledCertificateIds);
  12652. /*
  12653. * TODO: Return installed certificate process
  12654. */
  12655. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12656. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12657. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12658. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12659. sendGetInstalledCertificateIdsConfirmation(uuid);
  12660. return result;
  12661. }
  12662. int handleGetLogRequest(char *uuid, char *payload)
  12663. {
  12664. mtrace();
  12665. int result = PASS;
  12666. json_object *GetLog;
  12667. DEBUG_INFO("handleGetLogRequest...\n");
  12668. GetLog = json_tokener_parse(payload);
  12669. if(!is_error(GetLog))
  12670. {
  12671. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12672. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12673. if(json_object_object_get(GetLog, "retries") != NULL)
  12674. {
  12675. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12676. }
  12677. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12678. {
  12679. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12680. }
  12681. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12682. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12683. {
  12684. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12685. }
  12686. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12687. {
  12688. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12689. }
  12690. }
  12691. json_object_put(GetLog);
  12692. /*
  12693. * TODO: Upload log process
  12694. */
  12695. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12696. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12697. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12698. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12699. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12700. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12701. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12702. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12703. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12704. sendGetLogConfirmation(uuid);
  12705. return result;
  12706. }
  12707. int handleInstallCertificateRequest(char *uuid, char *payload)
  12708. {
  12709. mtrace();
  12710. int result = PASS;
  12711. json_object *InstallCertificate;
  12712. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12713. InstallCertificate = json_tokener_parse(payload);
  12714. if(!is_error(InstallCertificate))
  12715. {
  12716. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12717. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12718. /*
  12719. * TODO: Install certificate process
  12720. */
  12721. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12722. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12723. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12724. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12725. sendInstallCertificateConfirmation(uuid);
  12726. }
  12727. json_object_put(InstallCertificate);
  12728. return result;
  12729. }
  12730. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12731. {
  12732. mtrace();
  12733. int result = PASS;
  12734. json_object *SignedUpdateFirmware;
  12735. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12736. SignedUpdateFirmware = json_tokener_parse(payload);
  12737. if(!is_error(SignedUpdateFirmware))
  12738. {
  12739. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12740. {
  12741. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12742. }
  12743. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12744. {
  12745. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12746. }
  12747. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12748. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12749. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12750. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12751. {
  12752. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12753. }
  12754. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12755. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12756. }
  12757. json_object_put(SignedUpdateFirmware);
  12758. /*
  12759. * TODO: Upgrade firmware process
  12760. */
  12761. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12762. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12763. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12764. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12765. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12766. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12767. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12768. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12769. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12770. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12771. sendInstallCertificateConfirmation(uuid);
  12772. return result;
  12773. }
  12774. int handleUnknownRequest(char *uuid, char *payload)
  12775. {
  12776. mtrace();
  12777. int result = PASS;
  12778. DEBUG_INFO("handleUnknownRequest...\n");
  12779. sendUnknownConfirmation(uuid);
  12780. result = PASS;
  12781. return result;
  12782. }
  12783. //==========================================
  12784. // Handle server response routine
  12785. //==========================================
  12786. void handleAuthorizeResponse(char *payload, int gun_index)
  12787. {
  12788. mtrace();
  12789. char expiryDatestr[30]={0};
  12790. char parentIdTagstr[20]={0};
  12791. char statusstr[20]={0};
  12792. int expiryDateISNULL=FALSE;
  12793. int parentIdTagISNULL=FALSE;
  12794. DEBUG_INFO("handleAuthorizeResponse...\n");
  12795. json_object *Authorize;
  12796. Authorize = json_tokener_parse(payload);
  12797. if(!is_error(Authorize))
  12798. {
  12799. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12800. {
  12801. // Required data
  12802. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12803. // Optional data
  12804. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12805. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12806. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12807. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12808. }
  12809. }
  12810. json_object_put(Authorize);
  12811. if(expiryDateISNULL == FALSE)
  12812. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12813. if(parentIdTagISNULL == FALSE)
  12814. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12815. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12816. //Update idTag information to authorization cache if supproted
  12817. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12818. {
  12819. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12820. }
  12821. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12822. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12823. authorizeRetryTimes = 0;
  12824. }
  12825. void handleBootNotificationResponse(char *payload, int gun_index)
  12826. {
  12827. mtrace();
  12828. char statusStr[12]={0};
  12829. char currentTimeStr[30]={0};
  12830. int intervalInt = 0;
  12831. DEBUG_INFO("handleBootNotificationResponse...\n");
  12832. json_object *BootNotification;
  12833. BootNotification = json_tokener_parse(payload);
  12834. if(!is_error(BootNotification))
  12835. {
  12836. // Required data
  12837. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12838. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12839. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12840. }
  12841. json_object_put(BootNotification);
  12842. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12843. BootNotificationInterval = intervalInt;
  12844. HeartBeatWaitTime = intervalInt;
  12845. //write back to ShmOCPP16DataPH->BootNotification
  12846. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12847. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12848. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12849. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12850. {
  12851. if((intervalInt == 0) || (intervalInt >= 10))
  12852. {
  12853. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12854. HeartBeatWaitTime = intervalInt;
  12855. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12856. }
  12857. server_sign = TRUE;
  12858. server_pending =FALSE;
  12859. }
  12860. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12861. {
  12862. server_pending = TRUE;
  12863. }
  12864. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12865. srand(time(NULL));
  12866. refreshStartTimer(&clientTime.Heartbeat);
  12867. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12868. SetOcppConnStatus(TRUE);
  12869. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12870. }
  12871. void handleDataTransferResponse(char *payload, int gun_index)
  12872. {
  12873. json_object *DataTransfer = json_tokener_parse(payload);
  12874. if(!is_error(DataTransfer))
  12875. {
  12876. // Required data
  12877. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  12878. // Optional data
  12879. if(json_object_object_get(DataTransfer, "data") != NULL)
  12880. {
  12881. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12882. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12883. if(!is_error(Data))
  12884. {
  12885. if(json_object_object_get(Data, "msgId") != NULL)
  12886. {
  12887. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  12888. {
  12889. 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")));
  12890. }
  12891. }
  12892. }
  12893. json_object_put(Data);
  12894. }
  12895. }
  12896. json_object_put(DataTransfer);
  12897. }
  12898. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12899. {
  12900. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12901. //struct json_object *obj;
  12902. // obj = json_tokener_parse(payload);
  12903. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12904. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12905. //No fields are defined.
  12906. }
  12907. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12908. {
  12909. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12910. //struct json_object *obj;
  12911. // obj = json_tokener_parse(payload);
  12912. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12913. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12914. //No fields are defined.
  12915. }
  12916. void handleHeartbeatResponse(char *payload, int gun_index)
  12917. {
  12918. mtrace();
  12919. DEBUG_INFO("handleHeartbeatResponse...\n");
  12920. json_object *Heartbeat;
  12921. Heartbeat = json_tokener_parse(payload);
  12922. if(!is_error(Heartbeat))
  12923. {
  12924. // Required data
  12925. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12926. }
  12927. json_object_put(Heartbeat);
  12928. if(FirstHeartBeat == 0)
  12929. {
  12930. FirstHeartBeat = 1;
  12931. DEBUG_INFO("FirstHeartBeat \n");
  12932. }
  12933. HeartBeatWithNOResponse = 0;
  12934. refreshStartTimer(&clientTime.Heartbeat);
  12935. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12936. }
  12937. void handleMeterValuesResponse(char *payload, int gun_index)
  12938. {
  12939. mtrace();
  12940. DEBUG_INFO("handleMeterValuesResponse...\n");
  12941. isQueueSendable = 1;
  12942. }
  12943. void handleStartTransactionResponse(char *payload, int gun_index)
  12944. {
  12945. mtrace();
  12946. //int transactionIdInt = 0;
  12947. FILE *outfile;
  12948. char data[100]={0};
  12949. DEBUG_INFO("handleStartTransactionResponse...\n");
  12950. json_object *StartTransaction;
  12951. StartTransaction = json_tokener_parse(payload);
  12952. if(!is_error(StartTransaction))
  12953. {
  12954. // Required data
  12955. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12956. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12957. // Optional data
  12958. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12959. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12960. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12961. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12962. }
  12963. json_object_put(StartTransaction);
  12964. isQueueSendable = 1;
  12965. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12966. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12967. //-----------Start : write to the Queue TransactionId file -----------------//
  12968. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12969. {}
  12970. else
  12971. {
  12972. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12973. if(log == NULL)
  12974. {
  12975. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12976. return ;
  12977. }
  12978. else
  12979. {
  12980. fclose(log);
  12981. }
  12982. }
  12983. // open file for writing
  12984. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12985. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12986. {
  12987. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12988. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12989. fputs(data, outfile);
  12990. fclose (outfile);
  12991. }
  12992. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12993. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12994. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12995. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12996. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12997. }
  12998. void handleStatusNotificationResponse(char *payload, int gun_index)
  12999. {
  13000. mtrace();
  13001. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13002. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13003. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13004. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13005. }
  13006. void handleStopTransactionnResponse(char *payload, int gun_index)
  13007. {
  13008. mtrace();
  13009. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13010. json_object *StopTransaction;
  13011. StopTransaction = json_tokener_parse(payload);
  13012. if(!is_error(StopTransaction))
  13013. {
  13014. // Optional data
  13015. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13016. {
  13017. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13018. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13019. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13020. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13021. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13022. }
  13023. }
  13024. json_object_put(StopTransaction);
  13025. isQueueSendable = 1;
  13026. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13027. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13028. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13029. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13030. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13031. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13032. }
  13033. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13034. {
  13035. mtrace();
  13036. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13037. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13038. }
  13039. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13040. {
  13041. mtrace();
  13042. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13043. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13044. }
  13045. void handleSignCertificateResponse(char *payload, int gun_index)
  13046. {
  13047. mtrace();
  13048. DEBUG_INFO("handleSignCertificateResponse...\n");
  13049. json_object *SignCertificate;
  13050. SignCertificate = json_tokener_parse(payload);
  13051. if(!is_error(SignCertificate))
  13052. {
  13053. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13054. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13055. }
  13056. json_object_put(SignCertificate);
  13057. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13058. }
  13059. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13060. {
  13061. mtrace();
  13062. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13063. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13064. }
  13065. //==========================================
  13066. // Handle Error routine
  13067. //==========================================
  13068. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13069. {
  13070. mtrace();
  13071. #ifdef SystemLogMessage
  13072. DEBUG_INFO("errorCode: %s\n", errorCode);
  13073. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13074. DEBUG_INFO("errorDetails: %s\n", payload);
  13075. #endif
  13076. }
  13077. //===============================================
  13078. // Common routine
  13079. //===============================================
  13080. int initialConfigurationTable(void)
  13081. {
  13082. //clock_t start_t, end_t, total_t;
  13083. FILE *fp;
  13084. FILE *outfile;
  13085. char str[512]={0};
  13086. char sstr[256]={0};
  13087. int c = 0;
  13088. char *loc;
  13089. int confVersion = 12;
  13090. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13091. //start_t = clock();
  13092. //printf("Starting of the program, start_t = %ld\n", start_t);
  13093. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13094. // Check configuration file size is correct
  13095. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13096. {
  13097. struct stat st;
  13098. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13099. if(st.st_size < 3100)
  13100. {
  13101. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13102. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13103. }
  13104. }
  13105. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13106. {
  13107. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13108. if(outfile == NULL)
  13109. {
  13110. DEBUG_INFO("Error opening file\n");
  13111. return FALSE;
  13112. }
  13113. /*Core Profile*/
  13114. //AllowOfflineTxForUnknownId
  13115. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13116. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13117. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13119. //AuthorizationCacheEnabled
  13120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13124. //AuthorizeRemoteTxRequests
  13125. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13127. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13129. //BlinkRepeat
  13130. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13132. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13134. //ClockAlignedDataInterval
  13135. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13137. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13139. //ConnectionTimeOut
  13140. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13142. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13144. //GetConfigurationMaxKeys
  13145. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13147. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13149. // HeartbeatInterval
  13150. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13152. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13154. // LightIntensity
  13155. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13159. // LocalAuthorizeOffline
  13160. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13162. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13164. // LocalPreAuthorize
  13165. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13166. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13169. // MaxEnergyOnInvalidId
  13170. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13174. // MeterValuesAlignedData
  13175. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13177. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13178. 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" );
  13179. else
  13180. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13182. // MeterValuesAlignedDataMaxLength
  13183. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13185. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13187. else
  13188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13190. // MeterValuesSampledData
  13191. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13194. 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" );
  13195. else
  13196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13198. // MeterValuesSampledDataMaxLength
  13199. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13202. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13203. else
  13204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13206. // MeterValueSampleInterval
  13207. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13209. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13211. // MinimumStatusDuration
  13212. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13214. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13215. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13217. // NumberOfConnectors
  13218. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13221. {
  13222. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13223. }
  13224. else
  13225. {
  13226. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13227. }
  13228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13229. // ResetRetries
  13230. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13231. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13232. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13234. // ConnectorPhaseRotation
  13235. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13236. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13237. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13239. // ConnectorPhaseRotationMaxLength
  13240. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13242. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13244. // StopTransactionOnEVSideDisconnect
  13245. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13246. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13247. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13249. // StopTransactionOnInvalidId
  13250. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13251. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13252. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13254. // StopTxnAlignedData
  13255. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13257. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13259. // StopTxnAlignedDataMaxLength
  13260. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13261. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13262. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13263. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13264. // StopTxnSampledData
  13265. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13266. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13267. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13269. else
  13270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13272. // StopTxnSampledDataMaxLength
  13273. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13276. {
  13277. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13278. }
  13279. else
  13280. {
  13281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13282. }
  13283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13284. // SupportedFeatureProfiles
  13285. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13286. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13287. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13289. // SupportedFeatureProfilesMaxLength
  13290. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13292. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13294. // TransactionMessageAttempts
  13295. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13298. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13300. // TransactionMessageRetryInterval
  13301. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13304. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13306. // UnlockConnectorOnEVSideDisconnect
  13307. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13308. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13309. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13311. // WebSocketPingInterval
  13312. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13313. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13314. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13316. // QueueOffLineMeterValues
  13317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13319. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13321. // AuthorizationKey
  13322. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13324. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13326. // SecurityProfile
  13327. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13329. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13331. // DefaultPrice
  13332. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13334. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13336. // CustomDisplayCostAndPrice
  13337. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13339. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13341. // CustomIdleFeeAfterStop
  13342. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13344. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13346. // SystemUptimeSec
  13347. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13349. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13351. // FreeVend
  13352. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13354. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13356. // OcppServer
  13357. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13358. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13359. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13361. // MaintainServer
  13362. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13363. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13364. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13366. // StatusNotificationPeriodically
  13367. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13369. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13371. // StatusNotificationInterval
  13372. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13373. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13374. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13376. // Configuration Version
  13377. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13379. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13381. //* Local Auth List Management Profile*/
  13382. #if 0
  13383. //For OCTT Test Case
  13384. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13385. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13386. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13387. #endif
  13388. #if 1
  13389. //LocalAuthListEnabled
  13390. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13391. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13392. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13394. #endif
  13395. //LocalAuthListMaxLength
  13396. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13397. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13400. //SendLocalListMaxLength
  13401. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13402. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13405. //ReserveConnectorZeroSupported
  13406. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13407. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13408. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13410. //* Smart Charging Profile */
  13411. //ChargeProfileMaxStackLevel
  13412. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13413. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13414. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13416. // ChargingScheduleAllowedChargingRateUnit
  13417. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13418. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13419. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13420. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13421. // ChargingScheduleMaxPeriods
  13422. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13424. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13425. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13426. // ConnectorSwitch3to1PhaseSupported
  13427. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13428. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13429. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13431. // MaxChargingProfilesInstalled
  13432. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13433. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13434. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13436. fclose(outfile);
  13437. }
  13438. else
  13439. {
  13440. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13441. char keystr[60]={0};
  13442. char readonlystr[10]={0};
  13443. char valuestr[256]={0};
  13444. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13445. if(fp == NULL) {
  13446. DEBUG_INFO("Error opening file");
  13447. return FALSE;
  13448. }
  13449. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13450. {
  13451. //DEBUG_INFO("Get Configuration \n");
  13452. if(strlen(str) > 0)
  13453. {
  13454. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13455. //*************************key*********************************/
  13456. if(strstr(str, "key") != NULL)
  13457. {
  13458. loc = strstr(str, "key");
  13459. c = 0;
  13460. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13461. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13462. {
  13463. sstr[c] = loc[strlen("key")+3+c];
  13464. c++;
  13465. }
  13466. sstr[c] = '\0';
  13467. strcpy(keystr,sstr);
  13468. }
  13469. //*************************readonly*********************************/
  13470. if(strstr(str, "readonly") != NULL)
  13471. {
  13472. loc = strstr(str, "readonly");
  13473. c = 0;
  13474. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13475. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13476. {
  13477. sstr[c] = loc[strlen("readonly")+2+c];
  13478. c++;
  13479. }
  13480. sstr[c] = '\0';
  13481. strcpy(readonlystr,sstr);
  13482. }
  13483. //*************************value*********************************/
  13484. if(strstr(str, "value") != NULL)
  13485. {
  13486. loc = strstr(str, "value");
  13487. c = 0;
  13488. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13489. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13490. {
  13491. sstr[c] = loc[strlen("value")+3+c];
  13492. c++;
  13493. }
  13494. sstr[c] = '\0';
  13495. strcpy(valuestr,sstr);
  13496. }
  13497. // DEBUG_INFO("keystr=%s\n",keystr);
  13498. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13499. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13500. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13501. {
  13502. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13503. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13504. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13505. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13506. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13507. }
  13508. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13509. {
  13510. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13511. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13512. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13513. }
  13514. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13515. {
  13516. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13517. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13518. }
  13519. if(strcmp(keystr, "BlinkRepeat") == 0)
  13520. {
  13521. //Charger.BlinkRepeat = Integer.parseInt(value);
  13522. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13523. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13524. }
  13525. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13526. {
  13527. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13528. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13529. }
  13530. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13531. {
  13532. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13533. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13534. }
  13535. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13536. {
  13537. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13538. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13539. }
  13540. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13541. {
  13542. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13543. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13544. HeartBeatWaitTime = atoi(valuestr);
  13545. }
  13546. if(strcmp(keystr, "LightIntensity") == 0)
  13547. {
  13548. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13549. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13550. }
  13551. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13552. {
  13553. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13554. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13555. }
  13556. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13557. {
  13558. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13559. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13560. }
  13561. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13562. {
  13563. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13564. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13565. }
  13566. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13567. {
  13568. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13569. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13570. }
  13571. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13572. {
  13573. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13574. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13575. }
  13576. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13577. {
  13578. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13579. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13580. }
  13581. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13582. {
  13583. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13584. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13585. }
  13586. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13587. {
  13588. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13589. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13590. }
  13591. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13592. {
  13593. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13594. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13595. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13596. }
  13597. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13598. {
  13599. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13600. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13601. }
  13602. if(strcmp(keystr, "ResetRetries") == 0)
  13603. {
  13604. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13605. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13606. }
  13607. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13608. {
  13609. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13610. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13611. }
  13612. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13613. {
  13614. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13615. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13616. }
  13617. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13618. {
  13619. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13620. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13621. }
  13622. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13623. {
  13624. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13625. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13626. }
  13627. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13628. {
  13629. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13630. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13631. }
  13632. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13633. {
  13634. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13635. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13636. }
  13637. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13638. {
  13639. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13640. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13641. }
  13642. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13643. {
  13644. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13645. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13646. }
  13647. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13648. {
  13649. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13650. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13651. }
  13652. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13653. {
  13654. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13655. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13656. }
  13657. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13658. {
  13659. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13660. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13661. TransactionMessageAttemptsValue = atoi(valuestr);
  13662. }
  13663. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13664. {
  13665. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13666. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13667. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13668. }
  13669. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13670. {
  13671. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13672. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13673. }
  13674. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13675. {
  13676. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13677. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13678. }
  13679. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13680. {
  13681. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13682. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13683. }
  13684. if(strcmp(keystr, "AuthorizationKey") == 0)
  13685. {
  13686. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13687. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13688. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13689. }
  13690. if(strcmp(keystr, "SecurityProfile") == 0)
  13691. {
  13692. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13693. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13694. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13695. }
  13696. if(strcmp(keystr, "DefaultPrice") == 0)
  13697. {
  13698. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13699. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13700. }
  13701. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13702. {
  13703. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13704. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13705. }
  13706. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13707. {
  13708. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13709. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13710. }
  13711. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13712. {
  13713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13714. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13715. }
  13716. if(strcmp(keystr, "FreeVend") == 0)
  13717. {
  13718. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13719. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13720. }
  13721. if(strcmp(keystr, "OcppServer") == 0)
  13722. {
  13723. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13724. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13725. }
  13726. if(strcmp(keystr, "MaintainServer") == 0)
  13727. {
  13728. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13729. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  13730. }
  13731. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  13732. {
  13733. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  13735. }
  13736. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  13737. {
  13738. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13739. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  13740. }
  13741. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13742. {
  13743. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13744. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13745. }
  13746. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13747. {
  13748. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13750. }
  13751. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13752. {
  13753. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13754. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13755. }
  13756. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13757. {
  13758. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13759. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13760. }
  13761. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13762. {
  13763. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13764. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13765. }
  13766. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13767. {
  13768. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13769. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13770. }
  13771. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13772. {
  13773. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13774. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13775. }
  13776. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13777. {
  13778. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13779. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13780. }
  13781. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13782. {
  13783. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13784. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13785. }
  13786. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13787. {
  13788. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13789. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13790. }
  13791. }
  13792. }
  13793. fclose(fp);
  13794. }
  13795. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13796. {
  13797. return PASS;
  13798. }
  13799. else
  13800. {
  13801. return FAIL;
  13802. }
  13803. }
  13804. void StoreConfigurationTable(void)
  13805. {
  13806. FILE *outfile;
  13807. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13808. if(outfile == NULL)
  13809. {
  13810. DEBUG_INFO("Error opening file");
  13811. return ;
  13812. }
  13813. /*Core Profile*/
  13814. //AllowOfflineTxForUnknownId
  13815. /*
  13816. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13817. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13818. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13820. */
  13821. //DEBUG_INFO("data=%s\n",data);
  13822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13823. //AuthorizationCacheEnabled
  13824. /*
  13825. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13827. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13828. */
  13829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13830. //AuthorizeRemoteTxRequests
  13831. /*
  13832. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13833. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13834. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13835. */
  13836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13837. //BlinkRepeat
  13838. /*
  13839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13842. */
  13843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13844. //ClockAlignedDataInterval
  13845. /*
  13846. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13848. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13849. */
  13850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13851. //ConnectionTimeOut
  13852. /*
  13853. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13856. */
  13857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13858. //GetConfigurationMaxKeys
  13859. /*
  13860. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13863. */
  13864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13865. // HeartbeatInterval
  13866. /*
  13867. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13870. */
  13871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13872. // LightIntensity
  13873. /*
  13874. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13877. */
  13878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13879. // LocalAuthorizeOffline
  13880. /*
  13881. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13884. */
  13885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13886. // LocalPreAuthorize
  13887. /*
  13888. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13891. */
  13892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13893. // MaxEnergyOnInvalidId
  13894. /*
  13895. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13898. */
  13899. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13901. // MeterValuesAlignedData
  13902. /*
  13903. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13904. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13905. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13906. */
  13907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13908. // MeterValuesAlignedDataMaxLength
  13909. /*
  13910. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13912. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13913. */
  13914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13915. // MeterValuesSampledData
  13916. /*
  13917. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13919. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13920. */
  13921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13922. // MeterValuesSampledDataMaxLength
  13923. /*
  13924. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13927. */
  13928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13929. // MeterValueSampleInterval
  13930. /*
  13931. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13934. */
  13935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13936. // MinimumStatusDuration
  13937. /*
  13938. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13940. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13941. */
  13942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13943. // NumberOfConnectors
  13944. /*
  13945. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13948. {
  13949. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13950. }
  13951. else
  13952. {
  13953. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13954. }
  13955. */
  13956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13957. // ResetRetries
  13958. /*
  13959. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13962. */
  13963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13964. // ConnectorPhaseRotation
  13965. /*
  13966. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13968. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13969. */
  13970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13971. // ConnectorPhaseRotationMaxLength
  13972. /*
  13973. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13975. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13976. */
  13977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13978. // StopTransactionOnEVSideDisconnect
  13979. /*
  13980. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13983. */
  13984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13985. // StopTransactionOnInvalidId
  13986. /*
  13987. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13989. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13990. */
  13991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13992. // StopTxnAlignedData
  13993. /*
  13994. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13997. */
  13998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13999. // StopTxnAlignedDataMaxLength
  14000. /*
  14001. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14003. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14004. */
  14005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14006. // StopTxnSampledData
  14007. /*
  14008. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14009. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14010. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14011. */
  14012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14013. // StopTxnSampledDataMaxLength
  14014. /*
  14015. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14017. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14018. */
  14019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14020. // SupportedFeatureProfiles
  14021. /*
  14022. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14024. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14025. */
  14026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14027. // SupportedFeatureProfilesMaxLength
  14028. /*
  14029. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14031. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14032. */
  14033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14034. // TransactionMessageAttempts
  14035. /*
  14036. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14039. */
  14040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14041. // TransactionMessageRetryInterval
  14042. /*
  14043. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14045. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14046. */
  14047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14048. // UnlockConnectorOnEVSideDisconnect
  14049. /*
  14050. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14053. */
  14054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14055. // WebSocketPingInterval
  14056. /*
  14057. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14059. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14060. */
  14061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14062. // QueueOffLineMeterValues
  14063. /*
  14064. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14067. */
  14068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14069. // AuthorizationKey
  14070. /*
  14071. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14074. */
  14075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14076. // SecurityProfile
  14077. /*
  14078. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14080. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14081. */
  14082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14083. // DefaultPrice
  14084. /*
  14085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14088. */
  14089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14090. // CustomDisplayCostAndPrice
  14091. /*
  14092. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14095. */
  14096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14097. // CustomIdleFeeAfterStop
  14098. /*
  14099. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14102. */
  14103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14104. // SystemUptimeSec
  14105. /*
  14106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14109. */
  14110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14111. // FreeVend
  14112. /*
  14113. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14116. */
  14117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14118. // OcppServer
  14119. /*
  14120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14123. */
  14124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14125. // MaintainServer
  14126. /*
  14127. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14128. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14130. */
  14131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14132. // StatusNotificationPeriodically
  14133. /*
  14134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14137. */
  14138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14139. // StatusNotificationInterval
  14140. /*
  14141. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14142. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14144. */
  14145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14146. // ConfigurationVersion
  14147. /*
  14148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14151. */
  14152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14153. //* Local Auth List Management Profile*/
  14154. //LocalAuthListEnabled
  14155. /*
  14156. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14158. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14159. */
  14160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14161. //LocalAuthListMaxLength
  14162. /*
  14163. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14166. */
  14167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14168. //SendLocalListMaxLength
  14169. /*
  14170. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14173. */
  14174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14175. //ReserveConnectorZeroSupported
  14176. /*
  14177. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14179. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14180. */
  14181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14182. //* Smart Charging Profile */
  14183. //ChargeProfileMaxStackLevel
  14184. /*
  14185. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14188. */
  14189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14190. // ChargingScheduleAllowedChargingRateUnit
  14191. /*
  14192. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14193. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14194. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14195. */
  14196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14197. // ChargingScheduleMaxPeriods
  14198. /*
  14199. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14201. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14202. */
  14203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14204. // ConnectorSwitch3to1PhaseSupported
  14205. /*
  14206. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14207. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14209. */
  14210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14211. // MaxChargingProfilesInstalled
  14212. /*
  14213. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14214. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14215. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14216. */
  14217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14218. fclose(outfile);
  14219. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14220. }
  14221. void getKeyValue(char *keyReq)
  14222. {
  14223. int isEmpty = FALSE;
  14224. int isKnowKey = FALSE;
  14225. DEBUG_INFO("keyReq = %s\n", keyReq);
  14226. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14227. isEmpty = TRUE;
  14228. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14229. {
  14230. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14231. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14232. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14233. {
  14234. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14235. }
  14236. else
  14237. {
  14238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14239. }
  14240. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14241. isKnowKey = TRUE;
  14242. }
  14243. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14244. {
  14245. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14247. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14248. {
  14249. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14250. }
  14251. else
  14252. {
  14253. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14254. }
  14255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14256. isKnowKey = TRUE;
  14257. }
  14258. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14259. {
  14260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14262. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14263. {
  14264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14265. }
  14266. else
  14267. {
  14268. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14269. }
  14270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14271. isKnowKey = TRUE;
  14272. }
  14273. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14274. {
  14275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14276. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14277. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14278. {
  14279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14280. }
  14281. else
  14282. {
  14283. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14284. }
  14285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14286. isKnowKey = TRUE;
  14287. }
  14288. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14289. {
  14290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14291. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14292. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14293. {
  14294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14295. }
  14296. else
  14297. {
  14298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14299. }
  14300. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14301. isKnowKey = TRUE;
  14302. }
  14303. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14304. {
  14305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14306. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14307. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14308. {
  14309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14310. }
  14311. else
  14312. {
  14313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14314. }
  14315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14316. isKnowKey = TRUE;
  14317. }
  14318. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14319. {
  14320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14321. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14322. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14323. {
  14324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14325. }
  14326. else
  14327. {
  14328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14329. }
  14330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14331. isKnowKey = TRUE;
  14332. }
  14333. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14334. {
  14335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14337. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14338. {
  14339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14340. }
  14341. else
  14342. {
  14343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14344. }
  14345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14346. isKnowKey = TRUE;
  14347. }
  14348. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14349. {
  14350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14352. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14353. {
  14354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14355. }
  14356. else
  14357. {
  14358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14359. }
  14360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14361. isKnowKey = TRUE;
  14362. }
  14363. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14364. {
  14365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14367. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14368. {
  14369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14370. }
  14371. else
  14372. {
  14373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14374. }
  14375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14376. isKnowKey = TRUE;
  14377. }
  14378. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14379. {
  14380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14382. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14383. {
  14384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14385. }
  14386. else
  14387. {
  14388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14389. }
  14390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14391. isKnowKey = TRUE;
  14392. }
  14393. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14394. {
  14395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14397. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14398. {
  14399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14400. }
  14401. else
  14402. {
  14403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14404. }
  14405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14406. isKnowKey = TRUE;
  14407. }
  14408. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14409. {
  14410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14412. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14413. {
  14414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14415. }
  14416. else
  14417. {
  14418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14419. }
  14420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14421. isKnowKey = TRUE;
  14422. }
  14423. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14424. {
  14425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14427. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14428. {
  14429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14430. }
  14431. else
  14432. {
  14433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14434. }
  14435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14436. isKnowKey = TRUE;
  14437. }
  14438. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14439. {
  14440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14442. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14443. {
  14444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14445. }
  14446. else
  14447. {
  14448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14449. }
  14450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14451. isKnowKey = TRUE;
  14452. }
  14453. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14454. {
  14455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14457. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14458. {
  14459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14460. }
  14461. else
  14462. {
  14463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14464. }
  14465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14466. isKnowKey = TRUE;
  14467. }
  14468. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14469. {
  14470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14472. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14473. {
  14474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14475. }
  14476. else
  14477. {
  14478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14479. }
  14480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14481. isKnowKey = TRUE;
  14482. }
  14483. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14484. {
  14485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14487. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14488. {
  14489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14490. }
  14491. else
  14492. {
  14493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14494. }
  14495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14496. isKnowKey = TRUE;
  14497. }
  14498. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14499. {
  14500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14502. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14503. {
  14504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14505. }
  14506. else
  14507. {
  14508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14509. }
  14510. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14512. isKnowKey = TRUE;
  14513. }
  14514. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14515. {
  14516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14518. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14519. {
  14520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14521. }
  14522. else
  14523. {
  14524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14525. }
  14526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14527. isKnowKey = TRUE;
  14528. }
  14529. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14530. {
  14531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14533. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14534. {
  14535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14536. }
  14537. else
  14538. {
  14539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14540. }
  14541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14542. isKnowKey = TRUE;
  14543. }
  14544. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14545. {
  14546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14548. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14549. {
  14550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14551. }
  14552. else
  14553. {
  14554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14555. }
  14556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14557. isKnowKey = TRUE;
  14558. }
  14559. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14560. {
  14561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14563. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14564. {
  14565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14566. }
  14567. else
  14568. {
  14569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14570. }
  14571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14572. isKnowKey = TRUE;
  14573. }
  14574. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14575. {
  14576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14578. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14579. {
  14580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14581. }
  14582. else
  14583. {
  14584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14585. }
  14586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14587. isKnowKey = TRUE;
  14588. }
  14589. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14590. {
  14591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14593. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14594. {
  14595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14596. }
  14597. else
  14598. {
  14599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14600. }
  14601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14602. isKnowKey = TRUE;
  14603. }
  14604. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14605. {
  14606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14608. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14609. {
  14610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14611. }
  14612. else
  14613. {
  14614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14615. }
  14616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14617. isKnowKey = TRUE;
  14618. }
  14619. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14620. {
  14621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14623. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14624. {
  14625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14626. }
  14627. else
  14628. {
  14629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14630. }
  14631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14632. isKnowKey = TRUE;
  14633. }
  14634. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14635. {
  14636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14637. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14638. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14639. {
  14640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14641. }
  14642. else
  14643. {
  14644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14645. }
  14646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14647. isKnowKey = TRUE;
  14648. }
  14649. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14650. {
  14651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14652. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14653. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14654. {
  14655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14656. }
  14657. else
  14658. {
  14659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14660. }
  14661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14662. isKnowKey = TRUE;
  14663. }
  14664. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14665. {
  14666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14667. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14668. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14669. {
  14670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14671. }
  14672. else
  14673. {
  14674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14675. }
  14676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14677. isKnowKey = TRUE;
  14678. }
  14679. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14680. {
  14681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14682. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14683. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14684. {
  14685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14686. }
  14687. else
  14688. {
  14689. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14690. }
  14691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14692. isKnowKey = TRUE;
  14693. }
  14694. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14695. {
  14696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14697. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14698. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14699. {
  14700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14701. }
  14702. else
  14703. {
  14704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14705. }
  14706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14707. isKnowKey = TRUE;
  14708. }
  14709. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14710. {
  14711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14712. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14713. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14714. {
  14715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14716. }
  14717. else
  14718. {
  14719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14720. }
  14721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14722. isKnowKey = TRUE;
  14723. }
  14724. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14725. {
  14726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14727. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14728. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14729. {
  14730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14731. }
  14732. else
  14733. {
  14734. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14735. }
  14736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14737. isKnowKey = TRUE;
  14738. }
  14739. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14740. {
  14741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14742. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14743. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14744. {
  14745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14746. }
  14747. else
  14748. {
  14749. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14750. }
  14751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14752. isKnowKey = TRUE;
  14753. }
  14754. /*
  14755. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14756. {
  14757. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14759. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14760. {
  14761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14762. }
  14763. else
  14764. {
  14765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14766. }
  14767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14768. isKnowKey = TRUE;
  14769. }*/
  14770. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14771. {
  14772. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14774. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14775. {
  14776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14777. }
  14778. else
  14779. {
  14780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14781. }
  14782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14783. isKnowKey = TRUE;
  14784. }
  14785. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14786. {
  14787. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14788. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14789. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14790. {
  14791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14792. }
  14793. else
  14794. {
  14795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14796. }
  14797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14798. isKnowKey = TRUE;
  14799. }
  14800. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14801. {
  14802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14803. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14804. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14805. {
  14806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14807. }
  14808. else
  14809. {
  14810. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14811. }
  14812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14813. isKnowKey = TRUE;
  14814. }
  14815. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14816. {
  14817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14818. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14819. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14820. {
  14821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14822. }
  14823. else
  14824. {
  14825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14826. }
  14827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14828. isKnowKey = TRUE;
  14829. }
  14830. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14831. {
  14832. struct sysinfo s_info;
  14833. int error = sysinfo(&s_info);
  14834. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14836. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14837. {
  14838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14839. }
  14840. else
  14841. {
  14842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14843. }
  14844. if(error != 0)
  14845. {
  14846. DEBUG_WARN("System uptime get error: %d\n", error);
  14847. }
  14848. else
  14849. {
  14850. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14851. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14852. }
  14853. isKnowKey = TRUE;
  14854. }
  14855. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14856. {
  14857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14858. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14859. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14860. {
  14861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14862. }
  14863. else
  14864. {
  14865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14866. }
  14867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14868. isKnowKey = TRUE;
  14869. }
  14870. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  14871. {
  14872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  14873. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  14874. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  14875. {
  14876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  14877. }
  14878. else
  14879. {
  14880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  14881. }
  14882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14883. isKnowKey = TRUE;
  14884. }
  14885. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  14886. {
  14887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  14888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  14889. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  14890. {
  14891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  14892. }
  14893. else
  14894. {
  14895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  14896. }
  14897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14898. isKnowKey = TRUE;
  14899. }
  14900. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  14901. {
  14902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  14903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  14904. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  14905. {
  14906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  14907. }
  14908. else
  14909. {
  14910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  14911. }
  14912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  14913. isKnowKey = TRUE;
  14914. }
  14915. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  14916. {
  14917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  14918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  14919. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  14920. {
  14921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  14922. }
  14923. else
  14924. {
  14925. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  14926. }
  14927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  14928. isKnowKey = TRUE;
  14929. }
  14930. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14931. {
  14932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14934. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14935. {
  14936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14937. }
  14938. else
  14939. {
  14940. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14941. }
  14942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14943. isKnowKey = TRUE;
  14944. }
  14945. #if 1
  14946. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14947. {
  14948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14950. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14951. {
  14952. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14953. }
  14954. else
  14955. {
  14956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14957. }
  14958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14959. isKnowKey = TRUE;
  14960. }
  14961. #endif
  14962. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14963. {
  14964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14965. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14966. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14967. {
  14968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14969. }
  14970. else
  14971. {
  14972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14973. }
  14974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14975. isKnowKey = TRUE;
  14976. }
  14977. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14978. {
  14979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14980. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14981. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14982. {
  14983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14984. }
  14985. else
  14986. {
  14987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14988. }
  14989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14990. isKnowKey = TRUE;
  14991. }
  14992. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14993. {
  14994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14995. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14996. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14997. {
  14998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14999. }
  15000. else
  15001. {
  15002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15003. }
  15004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15005. isKnowKey = TRUE;
  15006. }
  15007. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15008. {
  15009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15011. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15012. {
  15013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15014. }
  15015. else
  15016. {
  15017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15018. }
  15019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15020. isKnowKey = TRUE;
  15021. }
  15022. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15023. {
  15024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15025. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15026. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15027. {
  15028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15029. }
  15030. else
  15031. {
  15032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15033. }
  15034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15035. isKnowKey = TRUE;
  15036. }
  15037. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15038. {
  15039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15040. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15041. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15042. {
  15043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15044. }
  15045. else
  15046. {
  15047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15048. }
  15049. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15050. isKnowKey = TRUE;
  15051. }
  15052. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15053. {
  15054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15055. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15056. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15057. {
  15058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15059. }
  15060. else
  15061. {
  15062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15063. }
  15064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15065. isKnowKey = TRUE;
  15066. }
  15067. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15068. {
  15069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15070. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15071. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15072. {
  15073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15074. }
  15075. else
  15076. {
  15077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15078. }
  15079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15080. isKnowKey = TRUE;
  15081. }
  15082. //=========================================================
  15083. if(!isEmpty && !isKnowKey)
  15084. {
  15085. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15086. strcpy(unknownkey[UnknownKeynum], keyReq);
  15087. UnknownKeynum = UnknownKeynum + 1;
  15088. }
  15089. }
  15090. void processUnkownKey(void)
  15091. {
  15092. DEBUG_INFO("processUnkownKey...\n");
  15093. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15094. for(int index=0; index < UnknownKeynum; index++)
  15095. {
  15096. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15097. {
  15098. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15099. }
  15100. }
  15101. }
  15102. int setKeyValue(char *key, char *value)
  15103. {
  15104. int isSuccess = NotSupported;
  15105. int check_ascii=0;
  15106. char str[501]={0};
  15107. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15108. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15109. {
  15110. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15111. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15112. {
  15113. strcpy(str, (const char*)value);
  15114. for(int i = 0; str[i]; i++){
  15115. str[i] = tolower(str[i]);
  15116. }
  15117. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15118. isSuccess = ConfigurationStatus_Accepted;
  15119. }
  15120. else
  15121. {
  15122. isSuccess = ConfigurationStatus_Rejected;
  15123. }
  15124. }
  15125. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15126. {
  15127. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15128. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15129. {
  15130. strcpy(str, (const char*)value);
  15131. for(int i = 0; str[i]; i++){
  15132. str[i] = tolower(str[i]);
  15133. }
  15134. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15135. isSuccess = ConfigurationStatus_Accepted;
  15136. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15137. }
  15138. else
  15139. {
  15140. isSuccess = ConfigurationStatus_Rejected;
  15141. }
  15142. }
  15143. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15144. {
  15145. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15146. {
  15147. strcpy(str, (const char*)value);
  15148. for(int i = 0; str[i]; i++)
  15149. {
  15150. str[i] = tolower(str[i]);
  15151. }
  15152. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15153. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15154. isSuccess = ConfigurationStatus_Accepted;
  15155. }
  15156. else
  15157. {
  15158. isSuccess = ConfigurationStatus_Rejected;
  15159. }
  15160. }
  15161. if(strcmp(key, "BlinkRepeat") == 0)
  15162. {
  15163. //Charger.BlinkRepeat = Integer.parseInt(value);
  15164. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15165. {
  15166. check_ascii = value[0];
  15167. if( (check_ascii < 48) || (check_ascii > 57) )
  15168. {
  15169. isSuccess = ConfigurationStatus_Rejected;
  15170. }
  15171. else
  15172. {
  15173. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15174. isSuccess = ConfigurationStatus_Accepted;
  15175. }
  15176. }
  15177. else
  15178. {
  15179. isSuccess = ConfigurationStatus_Rejected;
  15180. }
  15181. }
  15182. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15183. {
  15184. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15185. {
  15186. check_ascii = value[0];
  15187. if( (check_ascii < 48) || (check_ascii > 57) )
  15188. {
  15189. isSuccess = ConfigurationStatus_Rejected;
  15190. }
  15191. else
  15192. {
  15193. if((atoi(value) == 0) || (atoi(value) >= 5))
  15194. {
  15195. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15196. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15197. isSuccess = ConfigurationStatus_Accepted;
  15198. }
  15199. else
  15200. isSuccess = ConfigurationStatus_Rejected;
  15201. }
  15202. }
  15203. else
  15204. {
  15205. isSuccess = ConfigurationStatus_Rejected;
  15206. }
  15207. }
  15208. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15209. {
  15210. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15211. {
  15212. check_ascii = value[0];
  15213. if( (check_ascii < 48) || (check_ascii > 57) )
  15214. {
  15215. isSuccess = ConfigurationStatus_Rejected;
  15216. }
  15217. else
  15218. {
  15219. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15220. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15221. isSuccess = ConfigurationStatus_Accepted;
  15222. }
  15223. }
  15224. else
  15225. {
  15226. isSuccess = ConfigurationStatus_Rejected;
  15227. }
  15228. }
  15229. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15230. {
  15231. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15232. {
  15233. check_ascii = value[0];
  15234. if( (check_ascii < 48) || (check_ascii > 57) )
  15235. {
  15236. isSuccess = ConfigurationStatus_Rejected;
  15237. }
  15238. else
  15239. {
  15240. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15241. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15242. isSuccess = ConfigurationStatus_Accepted;
  15243. }
  15244. }
  15245. else
  15246. {
  15247. isSuccess = ConfigurationStatus_Rejected;
  15248. }
  15249. }
  15250. if(strcmp(key, "HeartbeatInterval") == 0)
  15251. {
  15252. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15253. {
  15254. check_ascii = value[0];
  15255. if( (check_ascii < 48) || (check_ascii > 57) )
  15256. {
  15257. isSuccess = ConfigurationStatus_Rejected;
  15258. }
  15259. else
  15260. {
  15261. if((atoi(value) == 0) || (atoi(value) >= 10))
  15262. {
  15263. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15264. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15265. HeartBeatWaitTime = atoi(value);
  15266. isSuccess = ConfigurationStatus_Accepted;
  15267. }
  15268. else
  15269. {
  15270. isSuccess = ConfigurationStatus_Rejected;
  15271. }
  15272. }
  15273. }
  15274. else
  15275. {
  15276. isSuccess = ConfigurationStatus_Rejected;
  15277. }
  15278. }
  15279. if(strcmp(key, "LightIntensity") == 0)
  15280. {
  15281. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15282. {
  15283. check_ascii = value[0];
  15284. if( (check_ascii < 48) || (check_ascii > 57) )
  15285. {
  15286. isSuccess = ConfigurationStatus_Rejected;
  15287. }
  15288. else
  15289. {
  15290. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15291. isSuccess = ConfigurationStatus_Accepted;
  15292. }
  15293. }
  15294. else
  15295. {
  15296. isSuccess = ConfigurationStatus_Rejected;
  15297. }
  15298. }
  15299. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15300. {
  15301. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15302. {
  15303. strcpy(str, (const char*)value);
  15304. for(int i = 0; str[i]; i++)
  15305. {
  15306. str[i] = tolower(str[i]);
  15307. }
  15308. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15309. isSuccess = ConfigurationStatus_Accepted;
  15310. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15311. }
  15312. else
  15313. {
  15314. isSuccess = ConfigurationStatus_Rejected;
  15315. }
  15316. }
  15317. if(strcmp(key, "LocalPreAuthorize") == 0)
  15318. {
  15319. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15320. {
  15321. strcpy(str, (const char*)value);
  15322. for(int i = 0; str[i]; i++)
  15323. {
  15324. str[i] = tolower(str[i]);
  15325. }
  15326. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15327. isSuccess = ConfigurationStatus_Accepted;
  15328. }
  15329. else
  15330. {
  15331. isSuccess = ConfigurationStatus_Rejected;
  15332. }
  15333. }
  15334. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15335. {
  15336. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15337. {
  15338. check_ascii = value[0];
  15339. if( (check_ascii < 48) || (check_ascii > 57) )
  15340. {
  15341. isSuccess = ConfigurationStatus_Rejected;
  15342. }
  15343. else
  15344. {
  15345. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15346. isSuccess = ConfigurationStatus_Accepted;
  15347. }
  15348. }
  15349. else
  15350. {
  15351. isSuccess = ConfigurationStatus_Rejected;
  15352. }
  15353. }
  15354. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15355. {
  15356. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15357. {
  15358. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15359. isSuccess = ConfigurationStatus_Accepted;
  15360. }
  15361. else
  15362. {
  15363. isSuccess = ConfigurationStatus_Rejected;
  15364. }
  15365. }
  15366. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15367. {
  15368. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15369. {
  15370. check_ascii = value[0];
  15371. if( (check_ascii < 48) || (check_ascii > 57) )
  15372. {
  15373. isSuccess = ConfigurationStatus_Rejected;
  15374. }
  15375. else
  15376. {
  15377. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15378. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15379. isSuccess = ConfigurationStatus_Accepted;
  15380. }
  15381. }
  15382. else
  15383. {
  15384. isSuccess = ConfigurationStatus_Rejected;
  15385. }
  15386. }
  15387. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15388. {
  15389. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15390. {
  15391. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15392. isSuccess = ConfigurationStatus_Accepted;
  15393. }
  15394. else
  15395. {
  15396. isSuccess = ConfigurationStatus_Rejected;
  15397. }
  15398. }
  15399. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15400. {
  15401. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15402. {
  15403. check_ascii = value[0];
  15404. if( (check_ascii < 48) || (check_ascii > 57) )
  15405. {
  15406. isSuccess = ConfigurationStatus_Rejected;
  15407. }
  15408. else
  15409. {
  15410. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15411. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15412. isSuccess = ConfigurationStatus_Accepted;
  15413. }
  15414. }
  15415. else
  15416. {
  15417. isSuccess = ConfigurationStatus_Rejected;
  15418. }
  15419. }
  15420. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15421. {
  15422. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15423. {
  15424. check_ascii = value[0];
  15425. if( (check_ascii < 48) || (check_ascii > 57) )
  15426. {
  15427. isSuccess = ConfigurationStatus_Rejected;
  15428. }
  15429. else
  15430. {
  15431. if((atoi(value) == 0) || (atoi(value) >= 3))
  15432. {
  15433. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15434. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15435. isSuccess = ConfigurationStatus_Accepted;
  15436. }
  15437. else
  15438. {
  15439. isSuccess = ConfigurationStatus_Rejected;
  15440. }
  15441. }
  15442. }
  15443. else
  15444. {
  15445. isSuccess = ConfigurationStatus_Rejected;
  15446. }
  15447. }
  15448. if(strcmp(key, "MinimumStatusDuration") == 0)
  15449. {
  15450. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15451. {
  15452. check_ascii = value[0];
  15453. if( (check_ascii < 48) || (check_ascii > 57) )
  15454. {
  15455. isSuccess = ConfigurationStatus_Rejected;
  15456. }
  15457. else
  15458. {
  15459. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15460. {
  15461. isSuccess = ConfigurationStatus_Rejected;
  15462. }
  15463. else
  15464. {
  15465. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15466. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15467. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15468. isSuccess = ConfigurationStatus_Accepted;
  15469. }
  15470. }
  15471. }
  15472. else
  15473. {
  15474. isSuccess = ConfigurationStatus_Rejected;
  15475. }
  15476. }
  15477. if(strcmp(key, "NumberOfConnectors") == 0)
  15478. {
  15479. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15480. {
  15481. check_ascii = value[0];
  15482. if( (check_ascii < 48) || (check_ascii > 57) )
  15483. {
  15484. isSuccess = ConfigurationStatus_Rejected;
  15485. }
  15486. else
  15487. {
  15488. //Charger.ResetRetries = Integer.parseInt(value);
  15489. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15490. isSuccess = ConfigurationStatus_Accepted;
  15491. }
  15492. }
  15493. else
  15494. {
  15495. isSuccess = ConfigurationStatus_Rejected;
  15496. }
  15497. }
  15498. if(strcmp(key, "ResetRetries") == 0)
  15499. {
  15500. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15501. {
  15502. check_ascii = value[0];
  15503. if( (check_ascii < 48) || (check_ascii > 57) )
  15504. {
  15505. isSuccess = ConfigurationStatus_Rejected;
  15506. }
  15507. else
  15508. {
  15509. //Charger.ResetRetries = Integer.parseInt(value);
  15510. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15511. isSuccess = ConfigurationStatus_Accepted;
  15512. }
  15513. }
  15514. else
  15515. {
  15516. isSuccess = ConfigurationStatus_Rejected;
  15517. }
  15518. }
  15519. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15520. {
  15521. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15522. {
  15523. strcpy(str, (const char*)value);
  15524. for(int i = 0; str[i]; i++)
  15525. {
  15526. str[i] = tolower(str[i]);
  15527. }
  15528. if(strcmp(str, "notapplicable")== 0)
  15529. {
  15530. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15531. isSuccess = ConfigurationStatus_Accepted;
  15532. }
  15533. else if(strcmp(str, "unknown")== 0)
  15534. {
  15535. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15536. isSuccess = ConfigurationStatus_Accepted;
  15537. }
  15538. else if(strcmp(str, "rst")== 0)
  15539. {
  15540. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15541. isSuccess = ConfigurationStatus_Accepted;
  15542. }
  15543. else if(strcmp(str, "rts")== 0)
  15544. {
  15545. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15546. isSuccess = ConfigurationStatus_Accepted;
  15547. }
  15548. else if(strcmp(str, "srt")== 0)
  15549. {
  15550. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15551. isSuccess = ConfigurationStatus_Accepted;
  15552. }
  15553. else if(strcmp(str, "str")== 0)
  15554. {
  15555. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15556. isSuccess = ConfigurationStatus_Accepted;
  15557. }
  15558. else if(strcmp(str, "trs")== 0)
  15559. {
  15560. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15561. isSuccess = ConfigurationStatus_Accepted;
  15562. }
  15563. else if(strcmp(str, "tsr")== 0)
  15564. {
  15565. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15566. isSuccess = ConfigurationStatus_Accepted;
  15567. }
  15568. else
  15569. {
  15570. isSuccess = ConfigurationStatus_Rejected;
  15571. }
  15572. }
  15573. else
  15574. {
  15575. isSuccess = ConfigurationStatus_Rejected;
  15576. }
  15577. }
  15578. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15579. {
  15580. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15581. {
  15582. check_ascii = value[0];
  15583. if( (check_ascii < 48) || (check_ascii > 57) )
  15584. {
  15585. isSuccess = ConfigurationStatus_Rejected;
  15586. }
  15587. else
  15588. {
  15589. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15590. isSuccess = ConfigurationStatus_Accepted;
  15591. }
  15592. }
  15593. else
  15594. {
  15595. isSuccess = ConfigurationStatus_Rejected;
  15596. }
  15597. }
  15598. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15599. {
  15600. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15601. {
  15602. strcpy(str, (const char*)value);
  15603. for(int i = 0; str[i]; i++)
  15604. {
  15605. str[i] = tolower(str[i]);
  15606. }
  15607. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15608. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15609. isSuccess = ConfigurationStatus_Accepted;
  15610. }
  15611. else
  15612. {
  15613. isSuccess = ConfigurationStatus_Rejected;
  15614. }
  15615. }
  15616. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15617. {
  15618. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15619. {
  15620. strcpy(str, (const char*)value);
  15621. for(int i = 0; str[i]; i++)
  15622. {
  15623. str[i] = tolower(str[i]);
  15624. }
  15625. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15626. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15627. isSuccess = ConfigurationStatus_Accepted;
  15628. }
  15629. else
  15630. {
  15631. isSuccess = ConfigurationStatus_Rejected;
  15632. }
  15633. }
  15634. if(strcmp(key, "StopTxnAlignedData") == 0)
  15635. {
  15636. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15637. {
  15638. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15639. isSuccess = ConfigurationStatus_Accepted;
  15640. }
  15641. else
  15642. {
  15643. isSuccess = ConfigurationStatus_Rejected;
  15644. }
  15645. }
  15646. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15647. {
  15648. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15649. {
  15650. check_ascii = value[0];
  15651. if( (check_ascii < 48) || (check_ascii > 57) )
  15652. {
  15653. isSuccess = ConfigurationStatus_Rejected;
  15654. }
  15655. else
  15656. {
  15657. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15658. isSuccess = ConfigurationStatus_Accepted;
  15659. }
  15660. }
  15661. else
  15662. {
  15663. isSuccess = ConfigurationStatus_Rejected;
  15664. }
  15665. }
  15666. if(strcmp(key, "StopTxnSampledData") == 0)
  15667. {
  15668. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15669. {
  15670. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15671. isSuccess = ConfigurationStatus_Accepted;
  15672. }
  15673. else
  15674. {
  15675. isSuccess = ConfigurationStatus_Rejected;
  15676. }
  15677. }
  15678. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15679. {
  15680. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15681. {
  15682. check_ascii = value[0];
  15683. if( (check_ascii < 48) || (check_ascii > 57) )
  15684. {
  15685. isSuccess = ConfigurationStatus_Rejected;
  15686. }
  15687. else
  15688. {
  15689. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15690. isSuccess = ConfigurationStatus_Accepted;
  15691. }
  15692. }
  15693. else
  15694. {
  15695. isSuccess = ConfigurationStatus_Rejected;
  15696. }
  15697. }
  15698. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15699. {
  15700. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15701. {
  15702. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15703. isSuccess = ConfigurationStatus_Accepted;
  15704. }
  15705. else
  15706. {
  15707. isSuccess = ConfigurationStatus_Rejected;
  15708. }
  15709. }
  15710. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15711. {
  15712. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15713. {
  15714. check_ascii = value[0];
  15715. if( (check_ascii < 48) || (check_ascii > 57) )
  15716. {
  15717. isSuccess = ConfigurationStatus_Rejected;
  15718. }
  15719. else
  15720. {
  15721. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15722. isSuccess = ConfigurationStatus_Accepted;
  15723. }
  15724. }
  15725. else
  15726. {
  15727. isSuccess = ConfigurationStatus_Rejected;
  15728. }
  15729. }
  15730. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15731. {
  15732. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15733. {
  15734. check_ascii = value[0];
  15735. if( (check_ascii < 48) || (check_ascii > 57) )
  15736. {
  15737. isSuccess = ConfigurationStatus_Rejected;
  15738. }
  15739. else
  15740. {
  15741. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15742. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15743. TransactionMessageAttemptsValue = atoi(value);
  15744. isSuccess = ConfigurationStatus_Accepted;
  15745. }
  15746. }
  15747. else
  15748. {
  15749. isSuccess = ConfigurationStatus_Rejected;
  15750. }
  15751. }
  15752. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15753. {
  15754. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15755. {
  15756. check_ascii = value[0];
  15757. if( (check_ascii < 48) || (check_ascii > 57) )
  15758. {
  15759. isSuccess = ConfigurationStatus_Rejected;
  15760. }
  15761. else
  15762. {
  15763. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15764. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15765. TransactionMessageRetryIntervalValue = atoi(value);
  15766. isSuccess = ConfigurationStatus_Accepted;
  15767. }
  15768. }
  15769. else
  15770. {
  15771. isSuccess = ConfigurationStatus_Rejected;
  15772. }
  15773. }
  15774. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15775. {
  15776. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15777. {
  15778. strcpy(str, (const char*)value);
  15779. for(int i = 0; str[i]; i++)
  15780. {
  15781. str[i] = tolower(str[i]);
  15782. }
  15783. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15784. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15785. isSuccess = ConfigurationStatus_Accepted;
  15786. }
  15787. else
  15788. {
  15789. isSuccess = ConfigurationStatus_Rejected;
  15790. }
  15791. }
  15792. if(strcmp(key, "WebSocketPingInterval") == 0)
  15793. {
  15794. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15795. {
  15796. check_ascii = value[0];
  15797. if( (check_ascii < 48) || (check_ascii > 57) )
  15798. {
  15799. isSuccess = ConfigurationStatus_Rejected;
  15800. }
  15801. else
  15802. {
  15803. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15804. isSuccess = ConfigurationStatus_Accepted;
  15805. if((atoi(value) == 0) || (atoi(value) >= 10))
  15806. {
  15807. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15808. isSuccess = ConfigurationStatus_Accepted;
  15809. }
  15810. else
  15811. isSuccess = ConfigurationStatus_Rejected;
  15812. }
  15813. }
  15814. else
  15815. {
  15816. isSuccess = ConfigurationStatus_Rejected;
  15817. }
  15818. }
  15819. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15820. {
  15821. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15822. {
  15823. strcpy(str, (const char*)value);
  15824. for(int i = 0; str[i]; i++)
  15825. {
  15826. str[i] = tolower(str[i]);
  15827. }
  15828. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15829. isSuccess = ConfigurationStatus_Accepted;
  15830. }
  15831. else
  15832. {
  15833. isSuccess = ConfigurationStatus_Rejected;
  15834. }
  15835. }
  15836. if(strcmp(key, "AuthorizationKey") == 0)
  15837. {
  15838. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15839. {
  15840. strcpy(str, (const char*)value);
  15841. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15842. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15843. isSuccess = ConfigurationStatus_Accepted;
  15844. }
  15845. else
  15846. {
  15847. isSuccess = ConfigurationStatus_Rejected;
  15848. }
  15849. }
  15850. if(strcmp(key, "SecurityProfile") == 0)
  15851. {
  15852. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15853. {
  15854. check_ascii = value[0];
  15855. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15856. {
  15857. isSuccess = ConfigurationStatus_Rejected;
  15858. }
  15859. else if(check_ascii == 0x33)
  15860. {
  15861. isSuccess = NotSupported;
  15862. }
  15863. else
  15864. {
  15865. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15866. {
  15867. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15868. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  15869. isSuccess = ConfigurationStatus_Accepted;
  15870. }
  15871. else
  15872. isSuccess = ConfigurationStatus_Rejected;
  15873. }
  15874. }
  15875. else
  15876. {
  15877. isSuccess = ConfigurationStatus_Rejected;
  15878. }
  15879. }
  15880. if(strcmp(key, "DefaultPrice") == 0)
  15881. {
  15882. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15883. {
  15884. strcpy(str, (const char*)value);
  15885. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15886. isSuccess = ConfigurationStatus_Accepted;
  15887. }
  15888. else
  15889. {
  15890. isSuccess = ConfigurationStatus_Rejected;
  15891. }
  15892. }
  15893. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15894. {
  15895. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15896. {
  15897. strcpy(str, (const char*)value);
  15898. for(int i = 0; str[i]; i++)
  15899. {
  15900. str[i] = tolower(str[i]);
  15901. }
  15902. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15903. isSuccess = ConfigurationStatus_Accepted;
  15904. }
  15905. else
  15906. {
  15907. isSuccess = ConfigurationStatus_Rejected;
  15908. }
  15909. }
  15910. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15911. {
  15912. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15913. {
  15914. strcpy(str, (const char*)value);
  15915. for(int i = 0; str[i]; i++)
  15916. {
  15917. str[i] = tolower(str[i]);
  15918. }
  15919. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15920. isSuccess = ConfigurationStatus_Accepted;
  15921. }
  15922. else
  15923. {
  15924. isSuccess = ConfigurationStatus_Rejected;
  15925. }
  15926. }
  15927. if(strcmp(key, "SystemUptimeSec") == 0)
  15928. {
  15929. isSuccess = NotSupported;
  15930. }
  15931. if(strcmp(key, "FreeVend") == 0)
  15932. {
  15933. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15934. {
  15935. strcpy(str, (const char*)value);
  15936. for(int i = 0; str[i]; i++)
  15937. {
  15938. str[i] = tolower(str[i]);
  15939. }
  15940. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15941. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15942. isSuccess = ConfigurationStatus_Accepted;
  15943. }
  15944. else
  15945. {
  15946. isSuccess = ConfigurationStatus_Rejected;
  15947. }
  15948. }
  15949. if(strcmp(key, "OcppServer") == 0)
  15950. {
  15951. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15952. {
  15953. strcpy(str, (const char*)value);
  15954. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  15955. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  15956. isSuccess = ConfigurationStatus_Accepted;
  15957. }
  15958. else
  15959. {
  15960. isSuccess = ConfigurationStatus_Rejected;
  15961. }
  15962. }
  15963. if(strcmp(key, "MaintainServer") == 0)
  15964. {
  15965. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15966. {
  15967. strcpy(str, (const char*)value);
  15968. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  15969. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  15970. isSuccess = ConfigurationStatus_Accepted;
  15971. }
  15972. else
  15973. {
  15974. isSuccess = ConfigurationStatus_Rejected;
  15975. }
  15976. }
  15977. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  15978. {
  15979. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15980. {
  15981. strcpy(str, (const char*)value);
  15982. for(int i = 0; str[i]; i++)
  15983. {
  15984. str[i] = tolower(str[i]);
  15985. }
  15986. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  15987. isSuccess = ConfigurationStatus_Accepted;
  15988. }
  15989. else
  15990. {
  15991. isSuccess = ConfigurationStatus_Rejected;
  15992. }
  15993. }
  15994. if(strcmp(key, "StatusNotificationInterval") == 0)
  15995. {
  15996. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15997. {
  15998. check_ascii = value[0];
  15999. if( (check_ascii < 48) || (check_ascii > 57) )
  16000. {
  16001. isSuccess = ConfigurationStatus_Rejected;
  16002. }
  16003. else
  16004. {
  16005. if((atoi(value) == 0) || (atoi(value) >= 10))
  16006. {
  16007. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16008. isSuccess = ConfigurationStatus_Accepted;
  16009. }
  16010. else
  16011. isSuccess = ConfigurationStatus_Rejected;
  16012. }
  16013. }
  16014. else
  16015. {
  16016. isSuccess = ConfigurationStatus_Rejected;
  16017. }
  16018. }
  16019. #if 0
  16020. //For OCPP Test Case
  16021. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16022. {
  16023. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16024. {
  16025. strcpy(str, (const char*)value);
  16026. for(int i = 0; str[i]; i++)
  16027. {
  16028. str[i] = tolower(str[i]);
  16029. }
  16030. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16031. isSuccess = ConfigurationStatus_Accepted;
  16032. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16033. }
  16034. else
  16035. {
  16036. isSuccess = ConfigurationStatus_Rejected;
  16037. }
  16038. }
  16039. #endif
  16040. #if 1
  16041. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16042. {
  16043. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16044. {
  16045. strcpy(str, (const char*)value);
  16046. for(int i = 0; str[i]; i++)
  16047. {
  16048. str[i] = tolower(str[i]);
  16049. }
  16050. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16051. isSuccess = ConfigurationStatus_Accepted;
  16052. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16053. }
  16054. else
  16055. {
  16056. isSuccess = ConfigurationStatus_Rejected;
  16057. }
  16058. }
  16059. #endif
  16060. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16061. {
  16062. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16063. {
  16064. check_ascii = value[0];
  16065. if( (check_ascii < 48) || (check_ascii > 57) )
  16066. {
  16067. isSuccess = ConfigurationStatus_Rejected;
  16068. }
  16069. else
  16070. {
  16071. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16072. isSuccess = ConfigurationStatus_Accepted;
  16073. }
  16074. }
  16075. else
  16076. {
  16077. isSuccess = ConfigurationStatus_Rejected;
  16078. }
  16079. }
  16080. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16081. {
  16082. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16083. {
  16084. check_ascii = value[0];
  16085. if( (check_ascii < 48) || (check_ascii > 57) )
  16086. {
  16087. isSuccess = ConfigurationStatus_Rejected;
  16088. }
  16089. else
  16090. {
  16091. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16092. isSuccess = ConfigurationStatus_Accepted;
  16093. }
  16094. }
  16095. else
  16096. {
  16097. isSuccess = ConfigurationStatus_Rejected;
  16098. }
  16099. }
  16100. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16101. {
  16102. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16103. {
  16104. strcpy(str, (const char*)value);
  16105. for(int i = 0; str[i]; i++)
  16106. {
  16107. str[i] = tolower(str[i]);
  16108. }
  16109. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16110. isSuccess = ConfigurationStatus_Accepted;
  16111. }
  16112. else
  16113. {
  16114. isSuccess = ConfigurationStatus_Rejected;
  16115. }
  16116. }
  16117. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16118. {
  16119. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16120. {
  16121. check_ascii = value[0];
  16122. if( (check_ascii < 48) || (check_ascii > 57) )
  16123. {
  16124. isSuccess = ConfigurationStatus_Rejected;
  16125. }
  16126. else
  16127. {
  16128. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16129. isSuccess = ConfigurationStatus_Accepted;
  16130. }
  16131. }
  16132. else
  16133. {
  16134. isSuccess = ConfigurationStatus_Rejected;
  16135. }
  16136. }
  16137. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16138. {
  16139. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16140. {
  16141. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16142. isSuccess = ConfigurationStatus_Accepted;
  16143. }
  16144. else
  16145. {
  16146. isSuccess = ConfigurationStatus_Rejected;
  16147. }
  16148. }
  16149. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16150. {
  16151. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16152. {
  16153. check_ascii = value[0];
  16154. if( (check_ascii < 48) || (check_ascii > 57) )
  16155. {
  16156. isSuccess = ConfigurationStatus_Rejected;
  16157. }
  16158. else
  16159. {
  16160. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16161. isSuccess = ConfigurationStatus_Accepted;
  16162. }
  16163. }
  16164. else
  16165. {
  16166. isSuccess = ConfigurationStatus_Rejected;
  16167. }
  16168. }
  16169. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16170. {
  16171. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16172. {
  16173. strcpy(str, (const char*)value);
  16174. for(int i = 0; str[i]; i++)
  16175. {
  16176. str[i] = tolower(str[i]);
  16177. }
  16178. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16179. isSuccess = ConfigurationStatus_Accepted;
  16180. }
  16181. else
  16182. {
  16183. isSuccess = ConfigurationStatus_Rejected;
  16184. }
  16185. }
  16186. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16187. {
  16188. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16189. {
  16190. check_ascii = value[0];
  16191. if( (check_ascii < 48) || (check_ascii > 57) )
  16192. {
  16193. isSuccess = ConfigurationStatus_Rejected;
  16194. }
  16195. else
  16196. {
  16197. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16198. isSuccess = ConfigurationStatus_Accepted;
  16199. }
  16200. }
  16201. else
  16202. {
  16203. isSuccess = ConfigurationStatus_Rejected;
  16204. }
  16205. }
  16206. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16207. return isSuccess;
  16208. }
  16209. int TransactionMessageAttemptsGet(void)
  16210. {
  16211. return TransactionMessageAttemptsValue;
  16212. }
  16213. int FirstHeartBeatResponse(void)
  16214. {
  16215. return FirstHeartBeat;
  16216. }
  16217. int TransactionMessageRetryIntervalGet(void)
  16218. {
  16219. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16220. }
  16221. int ReadHttpStatus(int sock)
  16222. {
  16223. //char c;
  16224. char buff[1024]="",*ptr=buff+1;
  16225. int bytes_received, status;
  16226. DEBUG_INFO("Begin Response ..\n");
  16227. while((bytes_received = recv(sock, ptr, 1, 0))){
  16228. if(bytes_received==-1){
  16229. perror("ReadHttpStatus");
  16230. exit(1);
  16231. }
  16232. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16233. ptr++;
  16234. }
  16235. *ptr=0;
  16236. ptr=buff+1;
  16237. sscanf(ptr,"%*s %d ", &status);
  16238. DEBUG_INFO("%s\n",ptr);
  16239. DEBUG_INFO("status=%d\n",status);
  16240. DEBUG_INFO("End Response ..\n");
  16241. return (bytes_received>0)?status:0;
  16242. }
  16243. //the only filed that it parsed is 'Content-Length'
  16244. int ParseHeader(int sock)
  16245. {
  16246. //char c;
  16247. char buff[1024]="",*ptr=buff+4;
  16248. int bytes_received;
  16249. DEBUG_INFO("Begin HEADER ..\n");
  16250. while((bytes_received = recv(sock, ptr, 1, 0))){
  16251. if(bytes_received==-1){
  16252. perror("Parse Header");
  16253. exit(1);
  16254. }
  16255. if(
  16256. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16257. (ptr[-1]=='\r') && (*ptr=='\n' )
  16258. ) break;
  16259. ptr++;
  16260. }
  16261. *ptr=0;
  16262. ptr=buff+4;
  16263. //printf("%s",ptr);
  16264. if(bytes_received){
  16265. ptr=strstr(ptr,"Content-Length:");
  16266. if(ptr){
  16267. sscanf(ptr,"%*s %d",&bytes_received);
  16268. }else
  16269. bytes_received=-1; //unknown size
  16270. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16271. }
  16272. DEBUG_INFO("End HEADER ..\n");
  16273. return bytes_received ;
  16274. }
  16275. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16276. {
  16277. int result = TRUE;
  16278. char rmFileCmd[100]={0};
  16279. char FilePath[100]={0};
  16280. char ftpbuf[200];
  16281. int systemresult;
  16282. sprintf(FilePath,"/mnt/%s",filename);
  16283. system("ping 8.8.8.8 &");
  16284. if((access(FilePath,F_OK))!=-1)
  16285. {
  16286. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16287. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16288. system(rmFileCmd);
  16289. }
  16290. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16291. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16292. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16293. systemresult = system(ftpbuf);
  16294. if(systemresult != 0)
  16295. {
  16296. DEBUG_INFO("http DownLoad error!\n");
  16297. result = FALSE;
  16298. }
  16299. system("pkill ping");
  16300. return result;
  16301. }
  16302. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16303. {
  16304. int result = TRUE;
  16305. char rmFileCmd[100]={0};
  16306. char FilePath[100]={0};
  16307. char ftpbuf[200];
  16308. int systemresult;
  16309. sprintf(FilePath,"/mnt/%s",filename);
  16310. system("ping 8.8.8.8 &");
  16311. if((access(FilePath,F_OK))!=-1)
  16312. {
  16313. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16314. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16315. system(rmFileCmd);
  16316. }
  16317. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16318. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16319. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16320. systemresult = system(ftpbuf);
  16321. if(systemresult != 0)
  16322. {
  16323. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16324. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16325. systemresult = system(ftpbuf);
  16326. if(systemresult != 0)
  16327. {
  16328. DEBUG_WARN("wget error!\n");
  16329. result = FALSE;
  16330. }
  16331. }
  16332. system("pkill ping");
  16333. return result;
  16334. }
  16335. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16336. {
  16337. char rmFileCmd[100]={0};
  16338. char FilePath[100]={0};
  16339. char buf[512];
  16340. int systemresult = 0;
  16341. //DEBUG_INFO("filename=%s\n",filename);
  16342. //DEBUG_INFO("url=%s\n",url);
  16343. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16344. if((access(FilePath,F_OK))!=-1)
  16345. {
  16346. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16347. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16348. system(rmFileCmd);
  16349. }
  16350. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16351. if(fp == NULL)
  16352. {
  16353. DEBUG_INFO("log is NULL\n");
  16354. return FALSE;
  16355. }
  16356. else
  16357. {
  16358. fprintf(fp, "%s\n", url);
  16359. fprintf(fp, "%s\n", filename);
  16360. fclose(fp);
  16361. }
  16362. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16363. if(phpFP == NULL)
  16364. {
  16365. DEBUG_INFO("PHP upload fail.\n");
  16366. return FALSE;
  16367. }
  16368. else
  16369. {
  16370. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16371. {
  16372. if(strstr(buf, "result") != NULL)
  16373. {
  16374. sscanf(buf, "result: %d", &systemresult);
  16375. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16376. }
  16377. }
  16378. pclose(phpFP);
  16379. }
  16380. if(systemresult != 1)
  16381. {
  16382. DEBUG_INFO("HTTP upload error!\n");
  16383. return FALSE;
  16384. }
  16385. return TRUE;
  16386. }
  16387. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16388. {
  16389. int result = FALSE;
  16390. char ftpbuf[200];
  16391. int systemresult;
  16392. /*
  16393. // Domaind name transfer to IP address
  16394. struct hostent* server;
  16395. char *IPbuffer;
  16396. server = gethostbyname(location);
  16397. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16398. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16399. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16400. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16401. systemresult = system(ftpbuf);
  16402. if(systemresult != 0)
  16403. {
  16404. DEBUG_INFO("ftpput error!\n");
  16405. }
  16406. else
  16407. {
  16408. result = TRUE;
  16409. DEBUG_INFO("ftpput OK!\n");
  16410. }
  16411. return result;
  16412. }
  16413. int GetOcppServerURL()
  16414. {
  16415. int result = FALSE;
  16416. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16417. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16418. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16419. struct yuarel url;
  16420. char urlStr[512];
  16421. // OCPPPH only
  16422. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16423. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16424. {
  16425. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16426. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16427. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16428. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16429. if(yuarel_parse(&url, urlStr) != -1)
  16430. {
  16431. sprintf(OcppProtocol, "%s", url.scheme);
  16432. sprintf(OcppHost, "%s", url.host);
  16433. if(url.path == NULL)
  16434. OcppTempPath[0] = '\0';
  16435. else
  16436. sprintf(OcppTempPath, "%s", url.path);
  16437. if(url.port == 0)
  16438. {
  16439. if(strcmp(OcppProtocol, "wss") == 0)
  16440. OcppPort = 443;
  16441. else
  16442. OcppPort = 80;
  16443. }
  16444. else
  16445. OcppPort = url.port;
  16446. result = TRUE;
  16447. }
  16448. }
  16449. else
  16450. {
  16451. strcpy(OcppHost,"");
  16452. }
  16453. return result;
  16454. }
  16455. int GetOcppPath()
  16456. {
  16457. int result = FALSE;
  16458. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16459. {
  16460. if(OcppTempPath == NULL)
  16461. {
  16462. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16463. }
  16464. else
  16465. {
  16466. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16467. }
  16468. result = TRUE;
  16469. goto End;
  16470. }
  16471. else
  16472. {
  16473. strcpy(OcppPath,"");
  16474. }
  16475. End:
  16476. return result;
  16477. }
  16478. int GetOcppPort()
  16479. {
  16480. return OcppPort;
  16481. }
  16482. int GetOcppConnStatus(void)
  16483. {
  16484. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16485. }
  16486. void SetOcppConnStatus(uint8_t status)
  16487. {
  16488. ShmOCPP16DataPH->OcppConnStatus = status;
  16489. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16490. }
  16491. int GetHeartBeatWithNOResponse(void)
  16492. {
  16493. return HeartBeatWithNOResponse;
  16494. }
  16495. void SetHeartBeatWithNOResponse(void)
  16496. {
  16497. HeartBeatWithNOResponse = 0;
  16498. }
  16499. void GetStartTransactionIdTag(int gun_index)
  16500. {
  16501. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16502. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16503. }
  16504. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16505. {
  16506. char ch;
  16507. FILE *fptr1;
  16508. int temptransactionId;
  16509. char str[100]={0};
  16510. temptransactionId = 0;
  16511. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16512. {
  16513. DEBUG_INFO("IdTag is empty.\n");
  16514. return temptransactionId;
  16515. }
  16516. /*------ Read the file ----------------*/
  16517. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16518. if (!fptr1)
  16519. {
  16520. DEBUG_INFO("QueueTransactionId file open error.\n");
  16521. //printf(" File not found or unable to open the input file!!\n");
  16522. return temptransactionId;
  16523. }
  16524. ch=fgetc(fptr1);
  16525. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16526. rewind(fptr1);
  16527. if(ch!=EOF)
  16528. {
  16529. // printf("%c",ch);
  16530. while (fgets(str, 100, fptr1) != NULL)
  16531. {
  16532. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16533. if(str[0]=='\0')
  16534. {
  16535. break;
  16536. }
  16537. char *revbuf[8] = {0}; // Variable store string split
  16538. int num = 0;// Quantity after string split
  16539. DEBUG_INFO("Transaction queue data= %s\n", str);
  16540. splitstring(str,",",revbuf,&num); // String split
  16541. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16542. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16543. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16544. DEBUG_INFO("------------------------------\n");
  16545. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16546. {
  16547. if(isStopTransaction)
  16548. {
  16549. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16550. {
  16551. temptransactionId = atoi(revbuf[2]);
  16552. //break;
  16553. }
  16554. }
  16555. else
  16556. {
  16557. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16558. {
  16559. temptransactionId = atoi(revbuf[2]);
  16560. //break;
  16561. }
  16562. }
  16563. }
  16564. }
  16565. }
  16566. else
  16567. DEBUG_INFO("EOF\n");
  16568. fclose(fptr1);
  16569. /*------- End of reading ---------------*/
  16570. return temptransactionId;
  16571. }
  16572. void SetTransactionIdZero(int transactionId)
  16573. {
  16574. char ch;
  16575. FILE *fptr1, *fptr2;
  16576. int temptransactionId = 0;
  16577. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16578. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16579. if (!fptr1)
  16580. {
  16581. //printf(" File not found or unable to open the input file!!\n");
  16582. return ;
  16583. }
  16584. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16585. if (!fptr2)
  16586. {
  16587. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16588. fclose(fptr1);
  16589. return ;
  16590. }
  16591. ch=fgetc(fptr1);
  16592. rewind(fptr1);
  16593. if(ch!=EOF)
  16594. {
  16595. // copy all contents to the temporary file except the specific line
  16596. while (fgets(str, 100, fptr1) != NULL)
  16597. {
  16598. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16599. if(str[0]=='\0')
  16600. {
  16601. break;
  16602. }
  16603. char *revbuf[8] = {0};
  16604. int num = 0;
  16605. strcpy(strtemp, str);
  16606. splitstring(str,",",revbuf,&num);
  16607. if(revbuf[2][0] != '\0')
  16608. {
  16609. temptransactionId = atoi(revbuf[2]);
  16610. if(transactionId != temptransactionId)
  16611. {
  16612. fprintf(fptr2, "%s\n", strtemp);
  16613. }
  16614. }
  16615. }
  16616. }
  16617. fclose(fptr1);
  16618. fclose(fptr2);
  16619. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16620. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16621. /*------ Read the file ----------------*/
  16622. }
  16623. int InternetDisconnect(void)
  16624. {
  16625. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16626. }
  16627. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16628. void storeTempStopTransaction(int gun_index)
  16629. {
  16630. char guid[37]={0};
  16631. int tempIndex = 0;
  16632. char TempStopTransaction[256];
  16633. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16634. DEBUG_INFO("storeTempStopTransaction...\n");
  16635. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16636. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16637. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16638. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16639. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16640. {
  16641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16642. {
  16643. tempIndex = ((gun_index==2) ? 1: 0);
  16644. }
  16645. else
  16646. {
  16647. tempIndex = gun_index;
  16648. }
  16649. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16650. {
  16651. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16652. {
  16653. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16654. }
  16655. }// END OF CHAdeMO_QUANTITY
  16656. }
  16657. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16658. {
  16659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16660. {
  16661. tempIndex = ((gun_index==2) ? 1: 0);
  16662. }
  16663. else
  16664. {
  16665. tempIndex = gun_index;
  16666. }
  16667. for (int index = 0; index < CCS_QUANTITY; index++)
  16668. {
  16669. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16670. {
  16671. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16672. }
  16673. }// END OF CCS_QUANTITY
  16674. }
  16675. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16676. {
  16677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16678. {
  16679. tempIndex = ((gun_index==2) ? 1: 0);
  16680. }
  16681. else
  16682. {
  16683. tempIndex = gun_index;
  16684. }
  16685. for (int index = 0; index < GB_QUANTITY; index++)
  16686. {
  16687. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16688. {
  16689. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16690. }
  16691. }// END OF GB_QUANTITY
  16692. }
  16693. else if(gunType[gun_index] == GUN_TYPE_DO)
  16694. {
  16695. tempIndex = gun_index;
  16696. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16697. {
  16698. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16699. {
  16700. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16701. }
  16702. }
  16703. }
  16704. else
  16705. {
  16706. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16707. {
  16708. tempIndex = 2;
  16709. }
  16710. else
  16711. {
  16712. tempIndex = gun_index;
  16713. }
  16714. for (int index = 0; index < AC_QUANTITY; index++)
  16715. {
  16716. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16717. {
  16718. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16719. }
  16720. }// END OF AC_QUANTITY
  16721. }
  16722. //Stop Transaction Time
  16723. struct timeval tmnow;
  16724. struct tm *tm;
  16725. char buf[28];//, usec_buf[6];
  16726. gettimeofday(&tmnow, NULL);
  16727. time_t t;
  16728. t = time(NULL);
  16729. /*UTC time and date*/
  16730. tm = gmtime(&t);
  16731. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16732. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16733. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16734. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16735. random_uuid(guid);
  16736. /***********************************transactionData******************************************************/
  16737. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16739. //=================================
  16740. //1. Transaction_Begin
  16741. //=================================
  16742. //============================== Energy.Active.Import.Interval ===========================================
  16743. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16744. {
  16745. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16746. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16748. 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*/]);
  16749. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16750. 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))
  16751. {
  16752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16753. }
  16754. else
  16755. {
  16756. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16757. }
  16758. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16759. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16760. }
  16761. //=================================
  16762. //2. Transaction_End
  16763. //=================================
  16764. //2.1====================================== Current.Import L1 ==============================================
  16765. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16766. {
  16767. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16768. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16769. {
  16770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16771. {
  16772. tempIndex = ((gun_index==2) ? 1: 0);
  16773. }
  16774. else
  16775. {
  16776. tempIndex = gun_index;
  16777. }
  16778. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16779. {
  16780. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16781. {
  16782. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16783. }
  16784. }// End of for CHAdeMO_QUANTITY
  16785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16786. }
  16787. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16788. {
  16789. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16790. {
  16791. tempIndex = ((gun_index==2) ? 1: 0);
  16792. }
  16793. else
  16794. {
  16795. tempIndex = gun_index;
  16796. }
  16797. for (int index = 0; index < CCS_QUANTITY; index++)
  16798. {
  16799. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16800. {
  16801. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16802. }
  16803. }// End of for CCS_QUANTITY
  16804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16805. }
  16806. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16807. {
  16808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16809. {
  16810. tempIndex = ((gun_index==2) ? 1: 0);
  16811. }
  16812. else
  16813. {
  16814. tempIndex = gun_index;
  16815. }
  16816. for (int index = 0; index < GB_QUANTITY; index++)
  16817. {
  16818. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16819. {
  16820. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16821. }
  16822. }// End of for GB_QUANTITY
  16823. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16824. }
  16825. else if(gunType[gun_index] == GUN_TYPE_DO)
  16826. {
  16827. tempIndex = gun_index;
  16828. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16829. {
  16830. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16831. {
  16832. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16833. }
  16834. }
  16835. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16836. }
  16837. else
  16838. {
  16839. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16840. {
  16841. tempIndex = 2;
  16842. }
  16843. else
  16844. {
  16845. tempIndex = gun_index;
  16846. }
  16847. for (int index = 0; index < AC_QUANTITY; index++)
  16848. {
  16849. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16850. {
  16851. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16852. }
  16853. }// End of for AC_QUANTITY
  16854. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16855. }
  16856. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16857. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16859. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16860. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16861. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16862. }
  16863. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16864. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16865. {
  16866. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16867. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16868. {
  16869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16870. {
  16871. tempIndex = ((gun_index==2) ? 1: 0);
  16872. }
  16873. else
  16874. {
  16875. tempIndex = gun_index;
  16876. }
  16877. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16878. {
  16879. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16880. {
  16881. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16882. }
  16883. }// END OF CHAdeMO_QUANTITY
  16884. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16885. }
  16886. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16887. {
  16888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16889. {
  16890. tempIndex = ((gun_index==2) ? 1: 0);
  16891. }
  16892. else
  16893. {
  16894. tempIndex = gun_index;
  16895. }
  16896. for (int index = 0; index < CCS_QUANTITY; index++)
  16897. {
  16898. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16899. {
  16900. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16901. }
  16902. }// END OF CCS_QUANTITY
  16903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16904. }
  16905. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16906. {
  16907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16908. {
  16909. tempIndex = ((gun_index==2) ? 1: 0);
  16910. }
  16911. else
  16912. {
  16913. tempIndex = gun_index;
  16914. }
  16915. for (int index = 0; index < GB_QUANTITY; index++)
  16916. {
  16917. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16918. {
  16919. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16920. }
  16921. }// END OF GB_QUANTITY
  16922. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16923. }
  16924. else if(gunType[gun_index] == GUN_TYPE_DO)
  16925. {
  16926. tempIndex = gun_index;
  16927. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16928. {
  16929. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16930. {
  16931. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16932. }
  16933. }
  16934. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16935. }
  16936. else
  16937. {
  16938. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16939. {
  16940. tempIndex = 2;
  16941. }
  16942. else
  16943. {
  16944. tempIndex = gun_index;
  16945. }
  16946. for (int index = 0; index < AC_QUANTITY; index++)
  16947. {
  16948. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16949. {
  16950. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16951. }
  16952. }// END OF AC_QUANTITY
  16953. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16954. }
  16955. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16956. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16957. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16958. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16960. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16961. }
  16962. //2.3====================================== Power.Active.Import =========================================
  16963. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16964. {
  16965. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16966. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16967. {
  16968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16969. {
  16970. tempIndex = ((gun_index==2) ? 1: 0);
  16971. }
  16972. else
  16973. {
  16974. tempIndex = gun_index;
  16975. }
  16976. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16977. {
  16978. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16979. {
  16980. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16981. }
  16982. } // End for CHAdeMO_QUANTITY
  16983. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16984. }
  16985. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16986. {
  16987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16988. {
  16989. tempIndex = ((gun_index==2) ? 1: 0);
  16990. }
  16991. else
  16992. {
  16993. tempIndex = gun_index;
  16994. }
  16995. for (int index = 0; index < CCS_QUANTITY; index++)
  16996. {
  16997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16998. {
  16999. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17000. }
  17001. } // END for CCS_QUANTITY
  17002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17003. }
  17004. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17005. {
  17006. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17007. {
  17008. tempIndex = ((gun_index==2) ? 1: 0);
  17009. }
  17010. else
  17011. {
  17012. tempIndex = gun_index;
  17013. }
  17014. for (int index = 0; index < GB_QUANTITY; index++)
  17015. {
  17016. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17017. {
  17018. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17019. }
  17020. }// END for GB_QUANTITY
  17021. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17022. }
  17023. else if(gunType[gun_index] == GUN_TYPE_DO)
  17024. {
  17025. tempIndex = gun_index;
  17026. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17027. {
  17028. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17029. {
  17030. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17031. }
  17032. }
  17033. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17034. }
  17035. else
  17036. {
  17037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17038. {
  17039. tempIndex = 2;
  17040. }
  17041. else
  17042. {
  17043. tempIndex = gun_index;
  17044. }
  17045. for (int index = 0; index < AC_QUANTITY; index++)
  17046. {
  17047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17048. {
  17049. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17050. }
  17051. } // END for AC_QUANTITY
  17052. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17053. }
  17054. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17057. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17060. }
  17061. //2.4====================================== Voltage L1 ====================================================
  17062. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17063. {
  17064. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17065. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17066. {
  17067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17068. {
  17069. tempIndex = ((gun_index==2) ? 1: 0);
  17070. }
  17071. else
  17072. {
  17073. tempIndex = gun_index;
  17074. }
  17075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17076. {
  17077. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17078. {
  17079. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17080. }
  17081. } // END OF FOR CHAdeMO_QUANTITY
  17082. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17083. }
  17084. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17085. {
  17086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17087. {
  17088. tempIndex = ((gun_index==2) ? 1: 0);
  17089. }
  17090. else
  17091. {
  17092. tempIndex = gun_index;
  17093. }
  17094. for (int index = 0; index < CCS_QUANTITY; index++)
  17095. {
  17096. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17097. {
  17098. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17099. }
  17100. } // END OF FOR CCS_QUANTITY
  17101. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17102. }
  17103. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17104. {
  17105. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17106. {
  17107. tempIndex = ((gun_index==2) ? 1: 0);
  17108. }
  17109. else
  17110. {
  17111. tempIndex = gun_index;
  17112. }
  17113. for (int index = 0; index < GB_QUANTITY; index++)
  17114. {
  17115. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17116. {
  17117. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17118. }
  17119. } // END OF FOR GB_QUANTITY
  17120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17121. }
  17122. else if(gunType[gun_index] == GUN_TYPE_DO)
  17123. {
  17124. tempIndex = gun_index;
  17125. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17126. {
  17127. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17128. {
  17129. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17130. }
  17131. }
  17132. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17133. }
  17134. else
  17135. {
  17136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17137. {
  17138. tempIndex = 2;
  17139. }
  17140. else
  17141. {
  17142. tempIndex = gun_index;
  17143. }
  17144. for (int index = 0; index < AC_QUANTITY; index++)
  17145. {
  17146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17147. {
  17148. 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
  17149. }
  17150. } // END OF FOR AC_QUANTITY
  17151. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17152. }
  17153. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17154. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17156. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17158. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17159. }
  17160. //2.5============================================== End SoC =========================================================
  17161. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17162. {
  17163. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17164. 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))
  17165. {
  17166. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17167. {
  17168. tempIndex = ((gun_index==2) ? 1: 0);
  17169. }
  17170. else
  17171. {
  17172. tempIndex = gun_index;
  17173. }
  17174. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17175. {
  17176. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17177. {
  17178. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17179. {
  17180. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17181. }
  17182. }
  17183. }
  17184. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17185. {
  17186. for (int index = 0; index < CCS_QUANTITY; index++)
  17187. {
  17188. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17189. {
  17190. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17191. }
  17192. }
  17193. }
  17194. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17195. {
  17196. for (int index = 0; index < GB_QUANTITY; index++)
  17197. {
  17198. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17199. {
  17200. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17201. }
  17202. }
  17203. }
  17204. else if(gunType[gun_index] == GUN_TYPE_DO)
  17205. {
  17206. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17207. {
  17208. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17209. {
  17210. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17211. }
  17212. }
  17213. }
  17214. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17215. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17216. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17217. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17220. } // END FOR DC CASE
  17221. }
  17222. //2.6====================================== Current.Import L2 ==============================================
  17223. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17224. {
  17225. // AC 3 phase L2 current
  17226. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17227. {
  17228. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17229. {
  17230. tempIndex = 2;
  17231. }
  17232. else
  17233. {
  17234. tempIndex = gun_index;
  17235. }
  17236. for (int index = 0; index < AC_QUANTITY; index++)
  17237. {
  17238. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17239. {
  17240. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17241. }
  17242. }// End of for AC_QUANTITY
  17243. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17244. }
  17245. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17246. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17247. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17248. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17249. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17250. }
  17251. //2.7====================================== Current.Import L3 ==============================================
  17252. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17253. {
  17254. // AC 3 phase L3 current
  17255. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17256. {
  17257. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17258. {
  17259. tempIndex = 2;
  17260. }
  17261. else
  17262. {
  17263. tempIndex = gun_index;
  17264. }
  17265. for (int index = 0; index < AC_QUANTITY; index++)
  17266. {
  17267. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17268. {
  17269. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17270. }
  17271. }// End of for AC_QUANTITY
  17272. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17273. }
  17274. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17277. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17279. }
  17280. //2.9====================================== Voltage L2 ====================================================
  17281. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17282. {
  17283. // AC 3 phase L2 volatge
  17284. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17285. {
  17286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17287. {
  17288. tempIndex = 2;
  17289. }
  17290. else
  17291. {
  17292. tempIndex = gun_index;
  17293. }
  17294. for (int index = 0; index < AC_QUANTITY; index++)
  17295. {
  17296. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17297. {
  17298. 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
  17299. }
  17300. } // END OF FOR AC_QUANTITY
  17301. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17302. }
  17303. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17304. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17307. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17308. }
  17309. //2.10====================================== Voltage L3 ====================================================
  17310. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17311. {
  17312. // AC 3 phase L3 volatge
  17313. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17314. {
  17315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17316. {
  17317. tempIndex = 2;
  17318. }
  17319. else
  17320. {
  17321. tempIndex = gun_index;
  17322. }
  17323. for (int index = 0; index < AC_QUANTITY; index++)
  17324. {
  17325. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17326. {
  17327. 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
  17328. }
  17329. } // END OF FOR AC_QUANTITY
  17330. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17331. }
  17332. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17333. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17334. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17335. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17336. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17337. }
  17338. //====================== Start SoC ================================
  17339. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17340. {
  17341. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17342. 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))
  17343. {
  17344. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17345. {
  17346. tempIndex = ((gun_index==2) ? 1: 0);
  17347. }
  17348. else
  17349. {
  17350. tempIndex = gun_index;
  17351. }
  17352. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17353. {
  17354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17355. {
  17356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17357. {
  17358. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17359. }
  17360. }
  17361. }
  17362. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17363. {
  17364. for (int index = 0; index < CCS_QUANTITY; index++)
  17365. {
  17366. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17367. {
  17368. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17369. }
  17370. }
  17371. }
  17372. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17373. {
  17374. for (int index = 0; index < GB_QUANTITY; index++)
  17375. {
  17376. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17377. {
  17378. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17379. }
  17380. }
  17381. }
  17382. else if(gunType[gun_index] == GUN_TYPE_DO)
  17383. {
  17384. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17385. {
  17386. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17387. {
  17388. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17389. }
  17390. }
  17391. }
  17392. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17393. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17394. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17395. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17396. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17397. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17398. } // END FOR DC CASE
  17399. }
  17400. //======================================== Message create ==============================================
  17401. json_object *StopTransaction = json_object_new_object();
  17402. json_object *transactionDatas = json_object_new_array();
  17403. json_object *sampledValues = json_object_new_array();
  17404. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17405. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17406. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17407. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17408. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17409. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17410. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17411. {
  17412. json_object *transactionData = json_object_new_object();
  17413. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17414. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17415. {
  17416. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17417. {
  17418. json_object *sampledValue = json_object_new_object();
  17419. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17420. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17421. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17422. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17423. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17424. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17425. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17426. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17427. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17428. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17429. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17430. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17431. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17432. json_object_array_add(sampledValues, sampledValue);
  17433. }
  17434. }
  17435. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17436. json_object_array_add(transactionDatas, transactionData);
  17437. }
  17438. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17439. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17440. ,MESSAGE_TYPE_CALL
  17441. ,guid
  17442. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17443. json_object_put(StopTransaction);
  17444. // Check File "TempStopTransaction" Exist
  17445. if((access(TempStopTransaction,F_OK))!=-1)
  17446. {
  17447. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17448. fclose(fopen(TempStopTransaction, "w"));
  17449. }
  17450. else
  17451. {
  17452. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17453. FILE *log = fopen(TempStopTransaction, "w+");
  17454. if(log == NULL)
  17455. {
  17456. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17457. return ;
  17458. }
  17459. else
  17460. {
  17461. fclose(log);
  17462. }
  17463. }
  17464. //Add TempStopTransaction | Update TempStopTransaction
  17465. // open file for writing
  17466. FILE *outfile;
  17467. outfile = fopen (TempStopTransaction, "a");
  17468. //DEBUG_INFO("data = %s\n", queuedata);
  17469. fputs(queuedata, outfile);
  17470. fputs("\n", outfile);
  17471. fclose (outfile);
  17472. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17473. }
  17474. void checkTempStopTransaction(int gun_index)
  17475. {
  17476. FILE *fptr1;
  17477. char ch;
  17478. char str[QUEUE_MESSAGE_LENGTH]={0};
  17479. char guid[37]={0};
  17480. char tempdata[65]={0};
  17481. char connectorStr[2]={0};
  17482. char TempStopTransaction[256];
  17483. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17484. fptr1 = fopen(TempStopTransaction, "r");
  17485. //TempStopTransaction格式: 槍號,StopTransaction封包
  17486. if (!fptr1)
  17487. {
  17488. //printf(" File not found or unable to open the input file!!\n");
  17489. return ;
  17490. }
  17491. ch=fgetc(fptr1);
  17492. //printf(" Now the content of the file %s is : \n",fname);
  17493. rewind(fptr1);
  17494. if(ch!=EOF)
  17495. {
  17496. // copy all contents to the temporary file except the specific line
  17497. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17498. {
  17499. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17500. if(str[0]=='\0')
  17501. {
  17502. break;
  17503. }
  17504. //TempStopTransaction格式: 槍號,StopTransaction封包
  17505. strncpy(connectorStr, str, 1);
  17506. if(atoi(connectorStr) != (gun_index+1))
  17507. {
  17508. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17509. fclose(fptr1);
  17510. return ;
  17511. }
  17512. //random_uuid(guid);
  17513. strncpy(guid, str+6, 36); //copy guid
  17514. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17515. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17516. {
  17517. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17518. }
  17519. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17520. OCPP_insert_transaction_msg(NO, str);
  17521. memset(str,0,ARRAY_SIZE(str));
  17522. }
  17523. }
  17524. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17525. fclose(fptr1);
  17526. remove(TempStopTransaction); // remove the original file
  17527. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17528. }
  17529. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17530. {
  17531. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17532. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17533. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17534. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17535. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17536. }
  17537. int GetWebSocketPingInterval(void)
  17538. {
  17539. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17540. }
  17541. int GetServerSign(void)
  17542. {
  17543. return server_sign;
  17544. }
  17545. uint8_t GetOcppSecurityProfile()
  17546. {
  17547. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17548. }
  17549. void GetOcppChargerBoxId(uint8_t *data)
  17550. {
  17551. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17552. }
  17553. void GetOcppSecurityPassword(uint8_t *data)
  17554. {
  17555. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17556. }
  17557. void SetOcppVersion(uint8_t *version)
  17558. {
  17559. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17560. DEBUG_INFO("ocpp version: %s\n", version);
  17561. if(strstr((char*)version, "ocpp1.6") != NULL)
  17562. {
  17563. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17564. }
  17565. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17566. {
  17567. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17568. system("pkill OcppBackend");
  17569. }
  17570. }
  17571. void SetServerSign(int value)
  17572. {
  17573. server_sign = value;
  17574. }
  17575. int GetBootNotificationInterval(void)
  17576. {
  17577. return BootNotificationInterval;
  17578. }
  17579. int GetInternetConn(void)
  17580. {
  17581. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17582. }
  17583. int GetBackendConnectionTimeout(void)
  17584. {
  17585. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17586. }
  17587. int isConnectorInitMode(int gun_index)
  17588. {
  17589. int tempIndex = 0;
  17590. int result = TRUE;
  17591. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17592. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17593. {
  17594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17595. {
  17596. tempIndex = ((gun_index==2) ? 1: 0);
  17597. }
  17598. else
  17599. {
  17600. tempIndex = gun_index;
  17601. }
  17602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17603. {
  17604. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17605. {
  17606. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17607. } //end of the same index
  17608. }//end of for CHAdeMO_QUANTITY
  17609. }
  17610. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17611. {
  17612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17613. {
  17614. tempIndex = ((gun_index==2) ? 1: 0);
  17615. }
  17616. else
  17617. {
  17618. tempIndex = gun_index;
  17619. }
  17620. for (int index = 0; index < CCS_QUANTITY; index++)
  17621. {
  17622. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17623. {
  17624. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17625. } //end of the same index
  17626. } // end of for CCS_QUANTITY
  17627. }
  17628. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17629. {
  17630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17631. {
  17632. tempIndex = ((gun_index==2) ? 1: 0);
  17633. }
  17634. else
  17635. {
  17636. tempIndex = gun_index;
  17637. }
  17638. for (int index = 0; index < GB_QUANTITY; index++)
  17639. {
  17640. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17641. {
  17642. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17643. } //end of the same index
  17644. } // end of for GB_QUANTITY
  17645. }
  17646. else if(gunType[gun_index] == GUN_TYPE_DO)
  17647. {
  17648. tempIndex = gun_index;
  17649. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17650. {
  17651. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17652. {
  17653. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17654. } //end of the same index
  17655. }
  17656. }
  17657. else
  17658. {
  17659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17660. {
  17661. tempIndex = 2;
  17662. }
  17663. else
  17664. {
  17665. tempIndex = gun_index;
  17666. }
  17667. for (int index = 0; index < AC_QUANTITY; index++)
  17668. {
  17669. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17670. {
  17671. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17672. }//end of the same index
  17673. }//end of for AC_QUANTITY
  17674. }
  17675. return result;
  17676. }
  17677. void refreshProcDogTimer()
  17678. {
  17679. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17680. }
  17681. void InitialSystemValue(void)
  17682. {
  17683. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17684. locallistVersion=0;
  17685. BootNotificationInterval = 0;
  17686. authorizeRetryTimes = 0;
  17687. GunStatusInterval = 10;
  17688. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17689. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17690. //Hear Beat
  17691. HeartBeatWithNOResponse = 0;
  17692. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17693. FirstHeartBeat = 0;
  17694. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17695. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17696. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17697. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17698. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17699. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17700. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17701. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17702. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17703. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17704. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17705. //Status && ConnectorPlugIn Setting
  17706. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17707. {
  17708. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17709. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17710. }
  17711. for (int index = 0; index < CCS_QUANTITY; index++)
  17712. {
  17713. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17714. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17715. }
  17716. for (int index = 0; index < GB_QUANTITY; index++)
  17717. {
  17718. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17719. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17720. }
  17721. for (int index = 0; index < AC_QUANTITY; index++)
  17722. {
  17723. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17724. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17725. }
  17726. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17727. {
  17728. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17729. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17730. }
  17731. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17732. {
  17733. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17734. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17735. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17736. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17737. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17738. }
  17739. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17740. refreshStartTimer(&clientTime.Heartbeat);
  17741. sleep(1);
  17742. }
  17743. void LWS_Send(char *str)
  17744. {
  17745. //=====================================================
  17746. // Check InternetConn 0: disconnected, 1: connected
  17747. //====================================================
  17748. if(GetOcppConnStatus() == 0)
  17749. {
  17750. DEBUG_INFO("offline now !!!\n");
  17751. return;
  17752. }
  17753. // Only disable isWebsocketSendable operation initiated by charger
  17754. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17755. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17756. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17757. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17758. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17759. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17760. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17761. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17762. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17763. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17764. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17765. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17766. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17767. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17768. {
  17769. isWebsocketSendable = 0;
  17770. }
  17771. pthread_mutex_lock(&lock_send);
  17772. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17773. sprintf((char *)SendBuffer, "%s", str);
  17774. SendBufLen = strlen(str);
  17775. pthread_mutex_unlock(&lock_send);
  17776. lws_callback_on_writable(wsi_client);
  17777. //lws_service(context, 0);
  17778. //sleep(1);
  17779. }
  17780. void LWS_SendNow(char *str)
  17781. {
  17782. //=====================================================
  17783. // Check InternetConn 0: disconnected, 1: connected
  17784. //====================================================
  17785. if(GetOcppConnStatus() == 0)
  17786. {
  17787. DEBUG_INFO("offline now !!!\n");
  17788. return;
  17789. }
  17790. // Only disable isWebsocketSendable operation initiated by charger
  17791. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17792. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17793. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17794. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17795. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17796. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17797. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17798. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17799. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17800. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17801. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17802. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17803. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17804. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17805. {
  17806. isWebsocketSendable = 0;
  17807. }
  17808. pthread_mutex_lock(&lock_send);
  17809. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17810. sprintf((char *)SendBuffer, "%s", str);
  17811. SendBufLen = strlen(str);
  17812. pthread_mutex_unlock(&lock_send);
  17813. lws_callback_on_writable(wsi_client);
  17814. lws_service(context, 0);
  17815. //sleep(1);
  17816. }