MessageHandler.c 844 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct InterLock
  92. {
  93. unsigned char isGetDiagnosticGoing:1;
  94. unsigned char isUpdateFirmwareGoing:1;
  95. }interLock;
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char isOnCharging:1; //bit 4,
  116. unsigned char :3; //bit5~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // TTIA routine
  356. //=========================================
  357. int sendTTIAInfo(uint8_t gun_index)
  358. {
  359. static int sn = 0;
  360. int result = FAIL;
  361. struct hostent *server;
  362. int udp_socket_fd;
  363. struct sockaddr_in dest_addr = {0};
  364. uint8_t tx_buf[80] = {0};
  365. uint8_t logBuf[256]= {0};
  366. uint8_t tx_len, tempIndex, socStart, socEnd;
  367. uint16_t PresentChargedEnergy;
  368. struct tm tmStart, tmEnd;
  369. DEBUG_INFO("sendTTIAInfo...\n");
  370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  371. {
  372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  373. {
  374. tempIndex = ((gun_index==2) ? 1: 0);
  375. }
  376. else
  377. {
  378. tempIndex = gun_index;
  379. }
  380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  381. {
  382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  383. {
  384. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  385. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  386. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  387. }
  388. }
  389. }
  390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  391. {
  392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  393. {
  394. tempIndex = ((gun_index==2) ? 1: 0);
  395. }
  396. else
  397. {
  398. tempIndex = gun_index;
  399. }
  400. for (int index = 0; index < CCS_QUANTITY; index++)
  401. {
  402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  403. {
  404. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  405. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  406. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  407. }
  408. }
  409. }
  410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  411. {
  412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  413. {
  414. tempIndex = ((gun_index==2) ? 1: 0);
  415. }
  416. else
  417. {
  418. tempIndex = gun_index;
  419. }
  420. for (int index = 0; index < GB_QUANTITY; index++)
  421. {
  422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  423. {
  424. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  425. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  426. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  427. }
  428. }
  429. }
  430. else if(gunType[gun_index] == GUN_TYPE_DO)
  431. {
  432. tempIndex = gun_index;
  433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  434. {
  435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  436. {
  437. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  438. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  439. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  440. }
  441. }
  442. }
  443. else
  444. {
  445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  446. {
  447. tempIndex = 2;
  448. }
  449. else
  450. {
  451. tempIndex = gun_index;
  452. }
  453. for (int index = 0; index < AC_QUANTITY; index++)
  454. {
  455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  456. {
  457. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  458. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  459. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  460. }
  461. }// END
  462. }
  463. // Message assembly
  464. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  465. tx_buf[4] = 0x02; // Protocol Version
  466. tx_buf[5] = 0xb0; // Message ID
  467. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  468. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  469. tx_buf[8] = 0x00; // CarID low byte
  470. tx_buf[9] = 0x00; // CarID high byte
  471. tx_buf[10] = 0x00; // ID Storage
  472. tx_buf[11] = 0x00; // Driver lowest byte
  473. tx_buf[12] = 0x00; // Driver 2nd byte
  474. tx_buf[13] = 0x00; // Driver 3rd byte
  475. tx_buf[14] = 0x00; // Driver highest byte
  476. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  477. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  478. tx_buf[17] = 0x00; // Reserve
  479. tx_buf[18] = 60 & 0xff; // Payload length low byte
  480. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  481. // EVSE provider
  482. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  483. // EVSE provider
  484. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  485. // EVSE id
  486. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  487. // Connector id
  488. tx_buf[37] = gun_index;
  489. // EVSE station
  490. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  491. // Vehicle SN
  492. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  493. // Mileage
  494. tx_buf[61] = 0x00; // lowest byte
  495. tx_buf[62] = 0x00; // 2nd byte
  496. tx_buf[63] = 0x00; // highest byte
  497. // Start date time 6 bytes
  498. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%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))
  499. {
  500. struct tm *tmTarget;
  501. struct timeb tbTarget;
  502. tmStart.tm_year -= 1900;
  503. tmStart.tm_mon -= 1;
  504. tmStart.tm_gmtoff = 0;
  505. tbTarget.time = mktime(&tmStart);
  506. tbTarget.timezone = 0;
  507. tbTarget.time += (8*3600);
  508. tmTarget = gmtime(&tbTarget.time);
  509. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  510. tx_buf[65] = (tmTarget->tm_mon+1);
  511. tx_buf[66] = tmTarget->tm_mday;
  512. tx_buf[67] = tmTarget->tm_hour;
  513. tx_buf[68] = tmTarget->tm_min;
  514. tx_buf[69] = tmTarget->tm_sec;
  515. }
  516. // Stop date time 6 bytes
  517. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  518. {
  519. struct tm *tmTarget;
  520. struct timeb tbTarget;
  521. tmEnd.tm_year -= 1900;
  522. tmEnd.tm_mon -= 1;
  523. tmEnd.tm_gmtoff = 0;
  524. tbTarget.time = mktime(&tmEnd);
  525. tbTarget.timezone = 0;
  526. tbTarget.time += (8*3600);
  527. tmTarget = gmtime(&tbTarget.time);
  528. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  529. tx_buf[71] = (tmTarget->tm_mon+1);
  530. tx_buf[72] = tmTarget->tm_mday;
  531. tx_buf[73] = tmTarget->tm_hour;
  532. tx_buf[74] = tmTarget->tm_min;
  533. tx_buf[75] = tmTarget->tm_sec;
  534. }
  535. // Session energy 2 bytes
  536. tx_buf[76] = PresentChargedEnergy & 0xff;
  537. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  538. // Start SOC 1 byte
  539. tx_buf[78] = socStart;
  540. // Stop SOC 1 byte
  541. tx_buf[79] = socEnd;
  542. // Open socket
  543. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  544. if(udp_socket_fd == -1)
  545. {
  546. DEBUG_ERROR("UDP socket create failed!\n");
  547. }
  548. else
  549. {
  550. // Get server DNS entry
  551. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  552. if (server == NULL)
  553. {
  554. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  555. }
  556. else
  557. {
  558. // Build the server's Internet address
  559. bzero((char *) &dest_addr, sizeof(dest_addr));
  560. dest_addr.sin_family = AF_INET;
  561. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  562. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  563. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  564. {
  565. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  566. {
  567. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  568. }
  569. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  570. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  571. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  572. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  573. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  574. DEBUG_TTIA_INFO("---------- Header ----------\n");
  575. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  576. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  577. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  578. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  579. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  580. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  581. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  582. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  583. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  584. DEBUG_TTIA_INFO("Len: 0x3C\n");
  585. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  586. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  587. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  588. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  589. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  590. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  591. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  592. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  593. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  594. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  595. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  596. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  597. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  598. DEBUG_TTIA_INFO("=========================================\n");
  599. sn++;
  600. result = PASS;
  601. }
  602. else
  603. {
  604. DEBUG_ERROR("UDP sent out fail.\n");
  605. }
  606. }
  607. }
  608. return result;
  609. }
  610. //=========================================
  611. // Save configuration
  612. //=========================================
  613. int runShellCmd(const char*cmd)
  614. {
  615. int result = FAIL;
  616. char buf[256];
  617. FILE *fp;
  618. fp = popen(cmd, "r");
  619. if(fp != NULL)
  620. {
  621. while(fgets(buf, sizeof(buf), fp) != NULL)
  622. {
  623. DEBUG_INFO("%s\n", buf);
  624. }
  625. result = PASS;
  626. }
  627. pclose(fp);
  628. return result;
  629. }
  630. int StoreUsrConfigData(struct SysConfigData *UsrData)
  631. {
  632. int result = PASS;
  633. int fd,wrd;
  634. unsigned int i,Chk;
  635. unsigned char *ptr, *BufTmp;
  636. int MtdBlockSize = 0x300000;
  637. Chk=0;
  638. ptr=(unsigned char *)UsrData;
  639. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  640. {
  641. memset(BufTmp,0,MtdBlockSize);
  642. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  643. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  644. Chk+=*(BufTmp+i);
  645. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  646. // Output configuration to file.
  647. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  648. if (fd < 0)
  649. {
  650. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  651. free(BufTmp);
  652. return 0;
  653. }
  654. wrd=write(fd, BufTmp, MtdBlockSize);
  655. close(fd);
  656. if(wrd<MtdBlockSize)
  657. {
  658. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  659. free(BufTmp);
  660. return 0;
  661. }
  662. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  663. DEBUG_INFO("Erase /dev/mtd10.\n");
  664. runShellCmd("flash_erase /dev/mtd10 0 0");
  665. DEBUG_INFO("Write /dev/mtd10.\n");
  666. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  667. DEBUG_INFO("Erase /dev/mtd11.\n");
  668. runShellCmd("flash_erase /dev/mtd11 0 0");
  669. DEBUG_INFO("Write /dev/mtd11.\n");
  670. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  671. system("rm -f /mnt/EvseConfig.bin");
  672. DEBUG_INFO("EvseConfig write to flash OK\n");
  673. }
  674. else
  675. {
  676. DEBUG_ERROR("alloc BlockSize NG\r\n");
  677. result = FAIL;
  678. }
  679. if(BufTmp!=NULL)
  680. free(BufTmp);
  681. return result;
  682. }
  683. //=========================================
  684. // Sqlite3 related function
  685. //=========================================
  686. static int selectSqlCount = 0;
  687. static int callback(void *data, int argc, char **argv, char **azColName){
  688. int i;
  689. //printf("%s: ", (const char*)data);
  690. selectSqlCount = argc;
  691. for(i = 0; i<argc; i++){
  692. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  693. }
  694. //printf("\n");
  695. return 0;
  696. }
  697. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  698. //int i;
  699. //printf("%s:\n", (const char*)data);
  700. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  701. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  702. return 0;
  703. }
  704. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  705. //printf("%s:\n", (const char*)data);
  706. //idTag
  707. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  708. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  709. //parentIdTag
  710. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  711. //expir_date
  712. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  713. //status
  714. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  715. //version
  716. if(columenCount > 5)
  717. idTagQuery.listVersionInt = atoi(columnValue[5]);
  718. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  719. return 0;
  720. }
  721. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  722. {
  723. // localversion = argv[5] ? atoi(argv[5]) : 0;
  724. // printf("localversion=%d\n", localversion);
  725. return 0;
  726. }
  727. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  728. {
  729. for (int i = 0; i < n_columns; i++)
  730. {
  731. DEBUG_INFO("%s\t", col_values[i]);
  732. }
  733. DEBUG_INFO("\n");
  734. return 0;
  735. }
  736. int OCPP_cleanLocalCache()
  737. {
  738. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  739. char *errMsg = 0;
  740. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  741. if (SQLITE_OK != rc)
  742. {
  743. DEBUG_INFO("SQL error: %s\n",errMsg);
  744. return FALSE;
  745. }
  746. return TRUE;
  747. }
  748. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  749. {
  750. int isSuccess = TRUE;
  751. int ret = 0;
  752. //const char* data = "Callback function called";
  753. char sql[300];
  754. char zErrMsg[200];
  755. memset(sql, 0, 300);
  756. memset(zErrMsg, 0, 200);
  757. 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);
  758. //* Execute SQL statement */
  759. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  760. if( ret != SQLITE_OK )
  761. {
  762. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  763. isSuccess = FALSE;
  764. }
  765. return isSuccess;
  766. }
  767. void OCPP_getIdTagFromLocalCache(char idTag[])
  768. {
  769. int rc = 0;
  770. char sql[100];
  771. char zErrMsg[100];
  772. memset(sql, 0, 100);
  773. memset(zErrMsg, 0, 100);
  774. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  775. memset(&idTagQuery, 0, sizeof(idTagQuery));
  776. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  777. /* Execute SQL statement */
  778. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  779. if( rc != SQLITE_OK )
  780. {
  781. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  782. }
  783. }
  784. void OCPP_getListVerion()
  785. {
  786. int rc = 0;
  787. // const char* data = "Callback function called";
  788. char sql[100];
  789. char zErrMsg[100];
  790. memset(sql, 0, 100);
  791. memset(zErrMsg, 0, 100);
  792. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  793. /* Execute SQL statement */
  794. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  795. if( rc != SQLITE_OK )
  796. {
  797. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  798. }
  799. }
  800. void OCPP_get_TableAuthlocalAllData(void)
  801. {
  802. int rc = 0;
  803. char sql[100];
  804. char zErrMsg[100];
  805. memset(sql, 0, 100);
  806. memset(zErrMsg, 0, 100);
  807. sprintf(sql,"select * from ocpp_auth_local ");
  808. /* Execute SQL statement */
  809. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  810. if( rc != SQLITE_OK )
  811. {
  812. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  813. }
  814. //return ver;
  815. }
  816. int OCPP_cleanLocalList()
  817. {
  818. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  819. char *errMsg = 0;
  820. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  821. if (SQLITE_OK != rc)
  822. {
  823. DEBUG_INFO("%s\n",errMsg);
  824. return FALSE;
  825. }
  826. return TRUE;
  827. }
  828. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  829. {
  830. int isSuccess = FALSE;
  831. int ret = 0;
  832. //const char* data = "Callback function called";
  833. char sql[300];
  834. char zErrMsg[200];
  835. memset(sql, 0, 300);
  836. memset(zErrMsg, 0, 200);
  837. 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);
  838. //* Execute SQL statement */
  839. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  840. if( ret != SQLITE_OK )
  841. {
  842. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  843. return isSuccess;
  844. }
  845. memset(sql, 0, 300);
  846. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  847. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  848. if( ret != SQLITE_OK )
  849. {
  850. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  851. return isSuccess;
  852. }
  853. isSuccess = TRUE;
  854. return isSuccess;
  855. }
  856. void OCPP_getIdTagFromLocalList(char idTag[])
  857. {
  858. int rc = 0;
  859. // const char* data = "Callback function called";
  860. char sql[100];
  861. char zErrMsg[100];
  862. memset(sql, 0, 100);
  863. memset(zErrMsg, 0, 100);
  864. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  865. memset(&idTagQuery, 0, sizeof(idTagQuery));
  866. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  867. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  868. /* Execute SQL statement */
  869. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  870. if( rc != SQLITE_OK )
  871. {
  872. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  873. }
  874. //return ver;
  875. }
  876. void OCPP_deleteIdTagFromLocalList(char idTag[])
  877. {
  878. //int ver = 0;
  879. //int isSuccess = FALSE;
  880. int rc = 0;
  881. char sql[100];
  882. char zErrMsg[100];
  883. memset(sql, 0, 100);
  884. memset(zErrMsg, 0, 100);
  885. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  886. //* Execute SQL statement */
  887. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  888. if( rc != SQLITE_OK )
  889. {
  890. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  891. }
  892. }
  893. int getCurrentYear()
  894. {
  895. int result = 0;
  896. time_t CurrentTime;
  897. struct tm *tm;
  898. CurrentTime = time(NULL);
  899. tm=localtime(&CurrentTime);
  900. result = (tm->tm_year + 1900);
  901. return result;
  902. }
  903. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  904. {
  905. int result = PASS;
  906. char* errMsg = NULL;
  907. char sqlStr[8192];
  908. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  909. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  910. {
  911. result = FAIL;
  912. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  913. }
  914. 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));
  915. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  916. {
  917. result = FAIL;
  918. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  919. }
  920. return result;
  921. }
  922. //==========================================
  923. // Check time passed since today
  924. //==========================================
  925. long long DiffTimebWithNow(struct timeb ST)
  926. {
  927. //return milli-second
  928. struct timeb ET;
  929. long long StartTime,StopTime;
  930. ftime(&ET);
  931. StartTime=(long long)ST.time;
  932. StopTime=(long long)ET.time;
  933. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  934. }
  935. int getTimePassSinceToday(uint8_t gun_index)
  936. {
  937. int result = -1;
  938. static time_t lastTime[4];
  939. time_t t;
  940. struct tm *tmStartToday;
  941. struct timeb tbStartToday;
  942. t=time(NULL);
  943. if(difftime(t, lastTime[gun_index])>0)
  944. {
  945. tmStartToday=localtime(&t);
  946. tmStartToday->tm_hour = 0;
  947. tmStartToday->tm_min = 0;
  948. tmStartToday->tm_sec = 0;
  949. tbStartToday.time = mktime(tmStartToday);
  950. tbStartToday.millitm = 0;
  951. result = DiffTimebWithNow(tbStartToday)/1000;
  952. lastTime[gun_index] = t;
  953. }
  954. return result;
  955. }
  956. void getNowDatetime(uint8_t *data)
  957. {
  958. time_t t = time(NULL);
  959. struct tm tm = *localtime(&t);
  960. 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);
  961. }
  962. int syncDateTimeRTC(uint8_t *data)
  963. {
  964. struct ParsingResult
  965. {
  966. int result;
  967. int scanedElement;
  968. int year;
  969. int month;
  970. int mday;
  971. int hour;
  972. int min;
  973. int sec;
  974. int tz_hour;
  975. int tz_min;
  976. float minSec;
  977. }result;
  978. struct tm tmOrg;
  979. struct tm *tmTarget;
  980. struct timeb tbTarget;
  981. char buf[128];
  982. memset(&result, 0x00, sizeof(struct ParsingResult));
  983. result.result = PASS;
  984. if(strstr((char*)data, ".") != NULL)
  985. {
  986. // Original data with mini second
  987. if(strstr((char*)data, "Z") != NULL)
  988. {
  989. // Original data with Z
  990. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  991. &result.year,
  992. &result.month,
  993. &result.mday,
  994. &result.hour,
  995. &result.min,
  996. &result.sec,
  997. &result.minSec);
  998. }
  999. else
  1000. {
  1001. // Original data without Z
  1002. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1003. &result.year,
  1004. &result.month,
  1005. &result.mday,
  1006. &result.hour,
  1007. &result.min,
  1008. &result.sec,
  1009. &result.minSec,
  1010. &result.tz_hour,
  1011. &result.tz_min);
  1012. }
  1013. }
  1014. else
  1015. {
  1016. // Original data without mini second
  1017. if(strstr((char*)data, "Z") != NULL)
  1018. {
  1019. // Original data with Z
  1020. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1021. &result.year,
  1022. &result.month,
  1023. &result.mday,
  1024. &result.hour,
  1025. &result.min,
  1026. &result.sec);
  1027. }
  1028. else
  1029. {
  1030. // Original data without Z
  1031. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1032. &result.year,
  1033. &result.month,
  1034. &result.mday,
  1035. &result.hour,
  1036. &result.min,
  1037. &result.sec,
  1038. &result.tz_hour,
  1039. &result.tz_min);
  1040. }
  1041. }
  1042. tmOrg.tm_year = result.year - 1900;
  1043. tmOrg.tm_mon = result.month - 1;
  1044. tmOrg.tm_mday = result.mday;
  1045. tmOrg.tm_hour = result.hour;
  1046. tmOrg.tm_min = result.min;
  1047. tmOrg.tm_sec = result.sec;
  1048. tmOrg.tm_gmtoff = 0;
  1049. tbTarget.time = mktime(&tmOrg);
  1050. tbTarget.timezone = 0;
  1051. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1052. tmTarget = gmtime(&tbTarget.time);
  1053. 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);
  1054. //DEBUG_INFO(" org date time: %s\n", data);
  1055. //DEBUG_INFO("parse date time: %s\n", buf);
  1056. system(buf);
  1057. system("/sbin/hwclock -w --systohc");
  1058. if(result.scanedElement < 6)
  1059. result.result = FAIL;
  1060. return result.result;
  1061. }
  1062. //==========================================
  1063. // GetCompositeSchedule logic related function
  1064. //==========================================
  1065. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1066. {
  1067. //return milli-second
  1068. unsigned int StartTime,StopTime;
  1069. StartTime=(unsigned int)ST.time;
  1070. StopTime=(unsigned int)ET.time;
  1071. return (StopTime-StartTime);
  1072. }
  1073. int DiffTimebWithNowSec(struct timeb ST)
  1074. {
  1075. //return milli-second
  1076. struct timeb ET;
  1077. unsigned int StartTime,StopTime;
  1078. ftime(&ET);
  1079. StartTime=(unsigned int)ST.time;
  1080. StopTime=(unsigned int)ET.time;
  1081. return (StopTime-StartTime);
  1082. }
  1083. int getStartStop(uint8_t *start, uint8_t *stop)
  1084. {
  1085. int result = -1;
  1086. struct tm tmStart;
  1087. struct timeb tbStart;
  1088. struct tm tmStop;
  1089. struct timeb tbStop;
  1090. 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) &&
  1091. (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))
  1092. {
  1093. //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);
  1094. //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);
  1095. tmStart.tm_year -= 1900;
  1096. tmStart.tm_mon -= 1;
  1097. tbStart.time = mktime(&tmStart);
  1098. tbStart.millitm = 0;
  1099. tmStop.tm_year -= 1900;
  1100. tmStop.tm_mon -= 1;
  1101. tbStop.time = mktime(&tmStop);
  1102. tbStop.millitm = 0;
  1103. result = DiffTimebSec(tbStart, tbStop);
  1104. //DEBUG_INFO("getStartStop(): %d\n", result);
  1105. }
  1106. else
  1107. {
  1108. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1109. }
  1110. return result;
  1111. }
  1112. int isOvertNow(uint8_t *start)
  1113. {
  1114. int result = NO;
  1115. struct ParsingResult
  1116. {
  1117. int result;
  1118. int scanedElement;
  1119. int year;
  1120. int month;
  1121. int mday;
  1122. int hour;
  1123. int min;
  1124. int sec;
  1125. int tz_hour;
  1126. int tz_min;
  1127. float minSec;
  1128. }parsingResult;
  1129. struct tm tmStart;
  1130. struct timeb tbStart;
  1131. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1132. if(strstr((char*)start, ".") != NULL)
  1133. {
  1134. // Original data with mini second
  1135. if(strstr((char*)start, "Z") != NULL)
  1136. {
  1137. // Original data with Z
  1138. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1139. &parsingResult.year,
  1140. &parsingResult.month,
  1141. &parsingResult.mday,
  1142. &parsingResult.hour,
  1143. &parsingResult.min,
  1144. &parsingResult.sec,
  1145. &parsingResult.minSec);
  1146. }
  1147. else
  1148. {
  1149. // Original data without Z
  1150. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1151. &parsingResult.year,
  1152. &parsingResult.month,
  1153. &parsingResult.mday,
  1154. &parsingResult.hour,
  1155. &parsingResult.min,
  1156. &parsingResult.sec,
  1157. &parsingResult.minSec,
  1158. &parsingResult.tz_hour,
  1159. &parsingResult.tz_min);
  1160. }
  1161. }
  1162. else
  1163. {
  1164. // Original data without mini second
  1165. if(strstr((char*)start, "Z") != NULL)
  1166. {
  1167. // Original data with Z
  1168. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1169. &parsingResult.year,
  1170. &parsingResult.month,
  1171. &parsingResult.mday,
  1172. &parsingResult.hour,
  1173. &parsingResult.min,
  1174. &parsingResult.sec);
  1175. }
  1176. else
  1177. {
  1178. // Original data without Z
  1179. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1180. &parsingResult.year,
  1181. &parsingResult.month,
  1182. &parsingResult.mday,
  1183. &parsingResult.hour,
  1184. &parsingResult.min,
  1185. &parsingResult.sec,
  1186. &parsingResult.tz_hour,
  1187. &parsingResult.tz_min);
  1188. }
  1189. }
  1190. if(parsingResult.scanedElement >= 6)
  1191. {
  1192. tmStart.tm_year = parsingResult.year - 1900;
  1193. tmStart.tm_mon = parsingResult.month - 1;
  1194. tmStart.tm_mday = parsingResult.mday;
  1195. tmStart.tm_hour = parsingResult.hour;
  1196. tmStart.tm_min = parsingResult.min;
  1197. tmStart.tm_sec = parsingResult.sec;
  1198. tmStart.tm_gmtoff = 0;
  1199. tbStart.time = mktime(&tmStart);
  1200. tbStart.timezone = 0;
  1201. tbStart.millitm = 0;
  1202. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1203. if(DiffTimebWithNowSec(tbStart) <= 0)
  1204. result = NO;
  1205. else
  1206. result = YES;
  1207. }
  1208. else
  1209. {
  1210. DEBUG_WARN("Start date parsing error.\n");
  1211. }
  1212. return result;
  1213. }
  1214. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1215. {
  1216. int result = -1;
  1217. struct tm tmStart;
  1218. struct timeb tbStart;
  1219. struct tm tmStop;
  1220. struct timeb tbStop;
  1221. 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) &&
  1222. (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))
  1223. {
  1224. tmStart.tm_year -= 1900;
  1225. tmStart.tm_mon -= 1;
  1226. tbStart.time = mktime(&tmStart);
  1227. tbStart.millitm = 0;
  1228. tmStop.tm_year -= 1900;
  1229. tmStop.tm_mon -= 1;
  1230. tbStop.time = mktime(&tmStop);
  1231. tbStop.millitm = 0;
  1232. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1233. }
  1234. return result;
  1235. }
  1236. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1237. {
  1238. FILE *fp;
  1239. char profileFileName[128];
  1240. char *line = NULL;
  1241. size_t len = 0;
  1242. time_t CurrentTime;
  1243. struct tm *tmComposite;
  1244. struct StructChargingProfile maxProfile;
  1245. uint8_t limitMax=0;
  1246. int compositePeriodIdx = 0;
  1247. CurrentTime = time(NULL);
  1248. tmComposite=localtime(&CurrentTime);
  1249. 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);
  1250. if(isUnitA)
  1251. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1252. else
  1253. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1254. compositeProfile->ChargingSchedule.Duration = durationReq;
  1255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1256. {
  1257. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1258. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1259. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1260. }
  1261. compositeProfile->ChargingProfileId = 0;
  1262. compositeProfile->StackLevel = 99 ;
  1263. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1264. maxProfile.ChargingProfileId = -1;
  1265. maxProfile.ChargingSchedule.Duration = -1;
  1266. system("rm -f /tmp/*.json");
  1267. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1268. // Search max profile
  1269. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1270. if((access(profileFileName, F_OK))!=-1)
  1271. {
  1272. fp = fopen(profileFileName, "r");
  1273. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1274. {
  1275. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1276. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1277. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1278. }
  1279. maxProfile.ChargingProfileId = -1;
  1280. maxProfile.StackLevel = -1;
  1281. while(getline(&line, &len, fp) != -1)
  1282. {
  1283. json_object *obj = NULL;
  1284. obj = json_tokener_parse(line);
  1285. if(is_error(obj))
  1286. {
  1287. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1288. }
  1289. else
  1290. {
  1291. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1292. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1293. )
  1294. {
  1295. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1296. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1297. )
  1298. {
  1299. struct tm tmFrom, tmTo;
  1300. struct timeb tbFrom, tbTo;
  1301. 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) &&
  1302. (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))
  1303. {
  1304. tmFrom.tm_year -= 1900;
  1305. tmFrom.tm_mon -= 1;
  1306. tbFrom.time = mktime(&tmFrom);
  1307. tmTo.tm_year -= 1900;
  1308. tmTo.tm_mon -= 1;
  1309. tbTo.time = mktime(&tmTo);
  1310. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1311. {
  1312. if(maxProfile.ChargingProfileId == -1)
  1313. DEBUG_INFO("MaxProfile found.\n");
  1314. else
  1315. DEBUG_INFO("MaxProfile updated.\n");
  1316. // Required item
  1317. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1318. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1319. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1320. if(isUnitA)
  1321. {
  1322. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1323. 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++)
  1324. {
  1325. 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"));
  1326. 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?
  1327. 3:
  1328. 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")));
  1329. 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")));
  1330. }
  1331. }
  1332. else
  1333. {
  1334. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1335. 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++)
  1336. {
  1337. 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"));
  1338. 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?
  1339. 3:
  1340. 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")));
  1341. 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));
  1342. }
  1343. }
  1344. // Optional item
  1345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1346. {
  1347. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1348. }
  1349. else
  1350. {
  1351. sprintf((char*)maxProfile.ValidFrom, " ");
  1352. }
  1353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1354. {
  1355. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1356. }
  1357. else
  1358. {
  1359. sprintf((char*)maxProfile.ValidTo, " ");
  1360. }
  1361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1362. {
  1363. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1364. }
  1365. else
  1366. {
  1367. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1368. }
  1369. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1370. {
  1371. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1372. }
  1373. else
  1374. {
  1375. maxProfile.TransactionId = -1;
  1376. }
  1377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1378. {
  1379. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1380. }
  1381. else
  1382. {
  1383. maxProfile.ChargingSchedule.Duration = 86400;
  1384. }
  1385. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1386. {
  1387. 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")));
  1388. }
  1389. else
  1390. {
  1391. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1392. }
  1393. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1394. {
  1395. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1396. }
  1397. else
  1398. {
  1399. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1400. }
  1401. }
  1402. }
  1403. }
  1404. else
  1405. {
  1406. if(maxProfile.ChargingProfileId == -1)
  1407. DEBUG_INFO("MaxProfile found.\n");
  1408. else
  1409. DEBUG_INFO("MaxProfile updated.\n");
  1410. // Required item
  1411. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1412. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1413. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1414. if(isUnitA)
  1415. {
  1416. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1417. 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++)
  1418. {
  1419. 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"));
  1420. 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?
  1421. 3:
  1422. 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")));
  1423. 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")));
  1424. }
  1425. }
  1426. else
  1427. {
  1428. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1429. 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++)
  1430. {
  1431. 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"));
  1432. 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?
  1433. 3:
  1434. 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")));
  1435. 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));
  1436. }
  1437. }
  1438. // Optional item
  1439. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1440. {
  1441. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1442. }
  1443. else
  1444. {
  1445. sprintf((char*)maxProfile.ValidFrom, " ");
  1446. }
  1447. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1448. {
  1449. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1450. }
  1451. else
  1452. {
  1453. sprintf((char*)maxProfile.ValidTo, " ");
  1454. }
  1455. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1456. {
  1457. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1458. }
  1459. else
  1460. {
  1461. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1462. }
  1463. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1464. {
  1465. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1466. }
  1467. else
  1468. {
  1469. maxProfile.TransactionId = -1;
  1470. }
  1471. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1472. {
  1473. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1474. }
  1475. else
  1476. {
  1477. maxProfile.ChargingSchedule.Duration = 86400;
  1478. }
  1479. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1480. {
  1481. 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")));
  1482. }
  1483. else
  1484. {
  1485. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1486. }
  1487. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1488. {
  1489. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1490. }
  1491. else
  1492. {
  1493. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1494. }
  1495. }
  1496. }
  1497. }
  1498. json_object_put(obj);
  1499. }
  1500. fclose(fp);
  1501. /*
  1502. if(maxProfile.ChargingProfileId !=-1)
  1503. {
  1504. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1505. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1506. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1507. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1508. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1509. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1510. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1511. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1512. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1513. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1514. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1516. {
  1517. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1518. {
  1519. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1520. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1521. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1522. }
  1523. }
  1524. }
  1525. else
  1526. DEBUG_INFO("MaxProfile not found.\n");
  1527. DEBUG_INFO("------------------------------------\n");*/
  1528. }
  1529. if(maxProfile.ChargingProfileId != -1)
  1530. {
  1531. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1532. {
  1533. if(maxProfile.ChargingSchedule.Duration != -1)
  1534. {
  1535. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1536. 0:
  1537. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1538. }
  1539. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1540. {
  1541. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1542. {
  1543. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1544. 0:
  1545. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1546. if(idxPeriod > 0)
  1547. {
  1548. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1549. {
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1551. }
  1552. }
  1553. }
  1554. }
  1555. }
  1556. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1557. {
  1558. if(maxProfile.ChargingSchedule.Duration != -1)
  1559. {
  1560. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1561. }
  1562. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1563. {
  1564. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1565. {
  1566. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1567. if(idxPeriod > 0)
  1568. {
  1569. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1570. {
  1571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1572. }
  1573. }
  1574. }
  1575. }
  1576. }
  1577. else
  1578. {
  1579. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1580. {
  1581. if(maxProfile.ChargingSchedule.Duration != -1)
  1582. {
  1583. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1584. 0:
  1585. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1586. }
  1587. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1588. {
  1589. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1590. {
  1591. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1592. 0:
  1593. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1594. if(idxPeriod > 0)
  1595. {
  1596. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1597. {
  1598. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1599. }
  1600. }
  1601. }
  1602. }
  1603. }
  1604. else
  1605. {
  1606. if(maxProfile.ChargingSchedule.Duration != -1)
  1607. {
  1608. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1609. 0:
  1610. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1611. }
  1612. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1613. {
  1614. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1615. {
  1616. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1617. 0:
  1618. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1619. if(idxPeriod > 0)
  1620. {
  1621. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1622. {
  1623. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1624. }
  1625. }
  1626. }
  1627. }
  1628. }
  1629. }
  1630. /*
  1631. DEBUG_INFO("MaxProfile after align.\n");
  1632. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1633. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1634. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1635. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1636. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1637. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1638. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1639. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1640. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1641. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1642. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1643. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1644. {
  1645. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1646. {
  1647. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1648. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1649. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1650. }
  1651. }
  1652. DEBUG_INFO("------------------------------------\n");*/
  1653. }
  1654. // Find each profile period quantity
  1655. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1656. {
  1657. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1658. limitMax = idx+1;
  1659. }
  1660. if(maxProfile.ChargingProfileId != -1)
  1661. {
  1662. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1663. {
  1664. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1665. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1666. (maxProfile.ChargingSchedule.Duration > 0))
  1667. {
  1668. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1669. {
  1670. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1671. compositePeriodIdx++;
  1672. }
  1673. else
  1674. {
  1675. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1676. }
  1677. }
  1678. }
  1679. }
  1680. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1681. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1682. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1683. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1684. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1685. {
  1686. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1687. {
  1688. compositeProfile->ChargingProfileId = 1;
  1689. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1690. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1691. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1692. }
  1693. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1694. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1695. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1696. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1697. }
  1698. if(line)
  1699. free(line);
  1700. }
  1701. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1702. {
  1703. FILE *fp;
  1704. char profileFileName[128];
  1705. char *line = NULL;
  1706. size_t len = 0;
  1707. time_t CurrentTime;
  1708. struct tm *tmComposite;
  1709. struct StructChargingProfile maxProfile;
  1710. struct StructChargingProfile defaultTxProfile;
  1711. struct StructChargingProfile txProfile;
  1712. struct StructChargingSchedulePeriod tmpPeriod;
  1713. uint8_t limitMax=0;
  1714. uint8_t limitDef=0;
  1715. uint8_t limitTx=0;
  1716. int compositePeriodIdx = 0;
  1717. CurrentTime = time(NULL);
  1718. tmComposite=localtime(&CurrentTime);
  1719. 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);
  1720. if(isUnitA)
  1721. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1722. else
  1723. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1724. compositeProfile->ChargingSchedule.Duration = durationReq;
  1725. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1726. {
  1727. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1728. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1729. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1730. }
  1731. compositeProfile->ChargingProfileId = 0;
  1732. compositeProfile->StackLevel = 99 ;
  1733. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1734. maxProfile.ChargingProfileId = -1;
  1735. defaultTxProfile.ChargingProfileId = -1;
  1736. txProfile.ChargingProfileId = -1;
  1737. maxProfile.ChargingSchedule.Duration = -1;
  1738. defaultTxProfile.ChargingSchedule.Duration = -1;
  1739. txProfile.ChargingSchedule.Duration = -1;
  1740. system("rm -f /tmp/*.json");
  1741. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1742. /*
  1743. * Search valid charging profile
  1744. */
  1745. //DEBUG_INFO("====================================\n");
  1746. // Search tx profile
  1747. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1748. if((access(profileFileName, F_OK))!=-1)
  1749. {
  1750. fp = fopen(profileFileName, "r");
  1751. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1752. {
  1753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1755. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1756. }
  1757. txProfile.ChargingProfileId = -1;
  1758. txProfile.StackLevel = -1;
  1759. while(getline(&line, &len, fp) != -1)
  1760. {
  1761. json_object *obj = NULL;
  1762. obj = json_tokener_parse(line);
  1763. if(is_error(obj))
  1764. {
  1765. DEBUG_ERROR("Parse txProfile from file error.\n");
  1766. }
  1767. else
  1768. {
  1769. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1770. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1771. )
  1772. {
  1773. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1774. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1775. )
  1776. {
  1777. struct tm tmFrom, tmTo;
  1778. struct timeb tbFrom, tbTo;
  1779. 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) &&
  1780. (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))
  1781. {
  1782. tmFrom.tm_year -= 1900;
  1783. tmFrom.tm_mon -= 1;
  1784. tbFrom.time = mktime(&tmFrom);
  1785. tmTo.tm_year -= 1900;
  1786. tmTo.tm_mon -= 1;
  1787. tbTo.time = mktime(&tmTo);
  1788. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1789. {
  1790. if(txProfile.ChargingProfileId == -1)
  1791. DEBUG_INFO("TxProfile found.\n");
  1792. else
  1793. DEBUG_INFO("TxProfile updated.\n");
  1794. // Required item
  1795. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1796. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1797. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1798. if(isUnitA)
  1799. {
  1800. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1801. 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++)
  1802. {
  1803. 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"));
  1804. 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?
  1805. 3:
  1806. 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")));
  1807. 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")));
  1808. }
  1809. }
  1810. else
  1811. {
  1812. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1813. 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++)
  1814. {
  1815. 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"));
  1816. 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?
  1817. 3:
  1818. 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")));
  1819. 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));
  1820. }
  1821. }
  1822. // Optional item
  1823. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1824. {
  1825. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1826. }
  1827. else
  1828. {
  1829. sprintf((char*)txProfile.ValidFrom, " ");
  1830. }
  1831. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1832. {
  1833. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1834. }
  1835. else
  1836. {
  1837. sprintf((char*)txProfile.ValidTo, " ");
  1838. }
  1839. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1840. {
  1841. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1842. }
  1843. else
  1844. {
  1845. sprintf((char*)txProfile.RecurrencyKind, " ");
  1846. }
  1847. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1848. {
  1849. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1850. }
  1851. else
  1852. {
  1853. txProfile.TransactionId = -1;
  1854. }
  1855. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1856. {
  1857. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1858. }
  1859. else
  1860. {
  1861. txProfile.ChargingSchedule.Duration = 86400;
  1862. }
  1863. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1864. {
  1865. 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")));
  1866. }
  1867. else
  1868. {
  1869. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1870. }
  1871. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1872. {
  1873. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1874. }
  1875. else
  1876. {
  1877. txProfile.ChargingSchedule.MinChargingRate = -1;
  1878. }
  1879. }
  1880. }
  1881. }
  1882. else
  1883. {
  1884. if(txProfile.ChargingProfileId == -1)
  1885. DEBUG_INFO("TxProfile found.\n");
  1886. else
  1887. DEBUG_INFO("TxProfile updated.\n");
  1888. // Required item
  1889. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1890. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1891. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1892. if(isUnitA)
  1893. {
  1894. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1895. 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++)
  1896. {
  1897. 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"));
  1898. 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?
  1899. 3:
  1900. 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")));
  1901. 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")));
  1902. }
  1903. }
  1904. else
  1905. {
  1906. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1907. 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++)
  1908. {
  1909. 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"));
  1910. 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?
  1911. 3:
  1912. 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")));
  1913. 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));
  1914. }
  1915. }
  1916. // Optional item
  1917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1918. {
  1919. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1920. }
  1921. else
  1922. {
  1923. sprintf((char*)txProfile.ValidFrom, " ");
  1924. }
  1925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1926. {
  1927. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1928. }
  1929. else
  1930. {
  1931. sprintf((char*)txProfile.ValidTo, " ");
  1932. }
  1933. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1934. {
  1935. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1936. }
  1937. else
  1938. {
  1939. sprintf((char*)txProfile.RecurrencyKind, " ");
  1940. }
  1941. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1942. {
  1943. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1944. }
  1945. else
  1946. {
  1947. txProfile.TransactionId = -1;
  1948. }
  1949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1950. {
  1951. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1952. }
  1953. else
  1954. {
  1955. txProfile.ChargingSchedule.Duration = 86400;
  1956. }
  1957. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1958. {
  1959. 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")));
  1960. }
  1961. else
  1962. {
  1963. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1964. }
  1965. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1966. {
  1967. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1968. }
  1969. else
  1970. {
  1971. txProfile.ChargingSchedule.MinChargingRate = -1;
  1972. }
  1973. }
  1974. }
  1975. }
  1976. json_object_put(obj);
  1977. }
  1978. fclose(fp);
  1979. /*
  1980. if(txProfile.ChargingProfileId != -1)
  1981. {
  1982. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1983. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1984. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1985. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1986. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1987. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1988. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1989. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1990. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1991. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1992. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1993. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1994. {
  1995. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1996. {
  1997. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1998. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1999. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2000. }
  2001. }
  2002. }
  2003. else
  2004. DEBUG_INFO("TxProfile not found.\n");*/
  2005. }
  2006. // Search default tx profile
  2007. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2008. if((access(profileFileName, F_OK))==-1)
  2009. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2010. if((access(profileFileName, F_OK))!=-1)
  2011. {
  2012. fp = fopen(profileFileName, "r");
  2013. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2014. {
  2015. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2016. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2017. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2018. }
  2019. defaultTxProfile.ChargingProfileId = -1;
  2020. defaultTxProfile.StackLevel = -1;
  2021. while(getline(&line, &len, fp) != -1)
  2022. {
  2023. json_object *obj = NULL;
  2024. obj = json_tokener_parse(line);
  2025. if(is_error(obj))
  2026. {
  2027. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2028. }
  2029. else
  2030. {
  2031. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2032. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2033. )
  2034. {
  2035. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2036. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2037. )
  2038. {
  2039. struct tm tmFrom, tmTo;
  2040. struct timeb tbFrom, tbTo;
  2041. 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) &&
  2042. (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))
  2043. {
  2044. tmFrom.tm_year -= 1900;
  2045. tmFrom.tm_mon -= 1;
  2046. tbFrom.time = mktime(&tmFrom);
  2047. tmTo.tm_year -= 1900;
  2048. tmTo.tm_mon -= 1;
  2049. tbTo.time = mktime(&tmTo);
  2050. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2051. {
  2052. if(defaultTxProfile.ChargingProfileId == -1)
  2053. DEBUG_INFO("TxDefaultProfile found.\n");
  2054. else
  2055. DEBUG_INFO("TxDefaultProfile updated.\n");
  2056. // Required item
  2057. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2058. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2059. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2060. if(isUnitA)
  2061. {
  2062. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2063. 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++)
  2064. {
  2065. 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"));
  2066. 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?
  2067. 3:
  2068. 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")));
  2069. 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")));
  2070. }
  2071. }
  2072. else
  2073. {
  2074. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2075. 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++)
  2076. {
  2077. 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"));
  2078. 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?
  2079. 3:
  2080. 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")));
  2081. 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));
  2082. }
  2083. }
  2084. // Optional item
  2085. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2086. {
  2087. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2088. }
  2089. else
  2090. {
  2091. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2092. }
  2093. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2094. {
  2095. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2096. }
  2097. else
  2098. {
  2099. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2100. }
  2101. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2102. {
  2103. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2104. }
  2105. else
  2106. {
  2107. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2108. }
  2109. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2110. {
  2111. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2112. }
  2113. else
  2114. {
  2115. defaultTxProfile.TransactionId = -1;
  2116. }
  2117. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2118. {
  2119. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2120. }
  2121. else
  2122. {
  2123. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2124. }
  2125. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2126. {
  2127. 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")));
  2128. }
  2129. else
  2130. {
  2131. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2132. }
  2133. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2134. {
  2135. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2136. }
  2137. else
  2138. {
  2139. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2140. }
  2141. }
  2142. }
  2143. }
  2144. else
  2145. {
  2146. if(defaultTxProfile.ChargingProfileId == -1)
  2147. DEBUG_INFO("TxDefaultProfile found.\n");
  2148. else
  2149. DEBUG_INFO("TxDefaultProfile updated.\n");
  2150. // Required item
  2151. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2152. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2153. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2154. if(isUnitA)
  2155. {
  2156. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2157. 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++)
  2158. {
  2159. 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"));
  2160. 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?
  2161. 3:
  2162. 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")));
  2163. 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")));
  2164. }
  2165. }
  2166. else
  2167. {
  2168. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2169. 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++)
  2170. {
  2171. 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"));
  2172. 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?
  2173. 3:
  2174. 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")));
  2175. 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));
  2176. }
  2177. }
  2178. // Optional item
  2179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2180. {
  2181. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2182. }
  2183. else
  2184. {
  2185. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2186. }
  2187. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2188. {
  2189. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2190. }
  2191. else
  2192. {
  2193. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2194. }
  2195. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2196. {
  2197. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2198. }
  2199. else
  2200. {
  2201. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2202. }
  2203. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2204. {
  2205. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2206. }
  2207. else
  2208. {
  2209. defaultTxProfile.TransactionId = -1;
  2210. }
  2211. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2212. {
  2213. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2214. }
  2215. else
  2216. {
  2217. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2218. }
  2219. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2220. {
  2221. 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")));
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2226. }
  2227. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2228. {
  2229. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2230. }
  2231. else
  2232. {
  2233. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2234. }
  2235. }
  2236. }
  2237. }
  2238. json_object_put(obj);
  2239. }
  2240. fclose(fp);
  2241. /*
  2242. if(defaultTxProfile.ChargingProfileId != -1)
  2243. {
  2244. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2245. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2246. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2247. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2248. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2249. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2250. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2251. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2252. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2253. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2254. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2256. {
  2257. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2258. {
  2259. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2260. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2261. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2262. }
  2263. }
  2264. }
  2265. else
  2266. DEBUG_INFO("TxDefaultProfile not found.\n");
  2267. DEBUG_INFO("------------------------------------\n");*/
  2268. }
  2269. // Search max profile
  2270. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2271. if((access(profileFileName, F_OK))!=-1)
  2272. {
  2273. fp = fopen(profileFileName, "r");
  2274. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2275. {
  2276. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2277. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2278. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2279. }
  2280. maxProfile.ChargingProfileId = -1;
  2281. maxProfile.StackLevel = -1;
  2282. while(getline(&line, &len, fp) != -1)
  2283. {
  2284. json_object *obj = NULL;
  2285. obj = json_tokener_parse(line);
  2286. if(is_error(obj))
  2287. {
  2288. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2289. }
  2290. else
  2291. {
  2292. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2293. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2294. )
  2295. {
  2296. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2297. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2298. )
  2299. {
  2300. struct tm tmFrom, tmTo;
  2301. struct timeb tbFrom, tbTo;
  2302. 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) &&
  2303. (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))
  2304. {
  2305. tmFrom.tm_year -= 1900;
  2306. tmFrom.tm_mon -= 1;
  2307. tbFrom.time = mktime(&tmFrom);
  2308. tmTo.tm_year -= 1900;
  2309. tmTo.tm_mon -= 1;
  2310. tbTo.time = mktime(&tmTo);
  2311. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2312. {
  2313. if(maxProfile.ChargingProfileId == -1)
  2314. DEBUG_INFO("MaxProfile found.\n");
  2315. else
  2316. DEBUG_INFO("MaxProfile updated.\n");
  2317. // Required item
  2318. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2319. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2320. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2321. if(isUnitA)
  2322. {
  2323. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2324. 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++)
  2325. {
  2326. 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"));
  2327. 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?
  2328. 3:
  2329. 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")));
  2330. 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")));
  2331. }
  2332. }
  2333. else
  2334. {
  2335. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2336. 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++)
  2337. {
  2338. 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"));
  2339. 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?
  2340. 3:
  2341. 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")));
  2342. 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));
  2343. }
  2344. }
  2345. // Optional item
  2346. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2347. {
  2348. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2349. }
  2350. else
  2351. {
  2352. sprintf((char*)maxProfile.ValidFrom, " ");
  2353. }
  2354. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2355. {
  2356. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2357. }
  2358. else
  2359. {
  2360. sprintf((char*)maxProfile.ValidTo, " ");
  2361. }
  2362. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2363. {
  2364. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2365. }
  2366. else
  2367. {
  2368. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2369. }
  2370. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2371. {
  2372. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2373. }
  2374. else
  2375. {
  2376. maxProfile.TransactionId = -1;
  2377. }
  2378. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2379. {
  2380. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2381. }
  2382. else
  2383. {
  2384. maxProfile.ChargingSchedule.Duration = 86400;
  2385. }
  2386. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2387. {
  2388. 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")));
  2389. }
  2390. else
  2391. {
  2392. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2393. }
  2394. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2395. {
  2396. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2397. }
  2398. else
  2399. {
  2400. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2401. }
  2402. }
  2403. }
  2404. }
  2405. else
  2406. {
  2407. if(maxProfile.ChargingProfileId == -1)
  2408. DEBUG_INFO("MaxProfile found.\n");
  2409. else
  2410. DEBUG_INFO("MaxProfile updated.\n");
  2411. // Required item
  2412. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2413. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2414. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2415. if(isUnitA)
  2416. {
  2417. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2418. 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++)
  2419. {
  2420. 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"));
  2421. 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?
  2422. 3:
  2423. 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")));
  2424. 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")));
  2425. }
  2426. }
  2427. else
  2428. {
  2429. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2430. 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++)
  2431. {
  2432. 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"));
  2433. 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?
  2434. 3:
  2435. 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")));
  2436. 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));
  2437. }
  2438. }
  2439. // Optional item
  2440. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2441. {
  2442. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2443. }
  2444. else
  2445. {
  2446. sprintf((char*)maxProfile.ValidFrom, " ");
  2447. }
  2448. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2449. {
  2450. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2451. }
  2452. else
  2453. {
  2454. sprintf((char*)maxProfile.ValidTo, " ");
  2455. }
  2456. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2457. {
  2458. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2459. }
  2460. else
  2461. {
  2462. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2463. }
  2464. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2465. {
  2466. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2467. }
  2468. else
  2469. {
  2470. maxProfile.TransactionId = -1;
  2471. }
  2472. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2473. {
  2474. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2475. }
  2476. else
  2477. {
  2478. maxProfile.ChargingSchedule.Duration = 86400;
  2479. }
  2480. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2481. {
  2482. 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")));
  2483. }
  2484. else
  2485. {
  2486. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2487. }
  2488. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2489. {
  2490. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2491. }
  2492. else
  2493. {
  2494. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2495. }
  2496. }
  2497. }
  2498. }
  2499. json_object_put(obj);
  2500. }
  2501. fclose(fp);
  2502. /*
  2503. if(maxProfile.ChargingProfileId !=-1)
  2504. {
  2505. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2506. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2507. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2508. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2509. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2510. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2511. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2512. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2513. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2514. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2515. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2516. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2517. {
  2518. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2519. {
  2520. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2521. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2522. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2523. }
  2524. }
  2525. }
  2526. else
  2527. DEBUG_INFO("MaxProfile not found.\n");
  2528. DEBUG_INFO("------------------------------------\n");*/
  2529. }
  2530. /*
  2531. * Align found profile start schedule & periods
  2532. */
  2533. //DEBUG_INFO("====================================\n");
  2534. /*
  2535. // For local test usage, force modify found profile start schedule info
  2536. 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);
  2537. 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);
  2538. 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);
  2539. */
  2540. if(txProfile.ChargingProfileId != -1)
  2541. {
  2542. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2543. {
  2544. if(txProfile.ChargingSchedule.Duration != -1)
  2545. {
  2546. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2547. 0:
  2548. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2549. }
  2550. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2551. {
  2552. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2553. {
  2554. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2555. 0:
  2556. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2557. if(idxPeriod > 0)
  2558. {
  2559. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2560. {
  2561. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2562. }
  2563. }
  2564. }
  2565. }
  2566. }
  2567. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2568. {
  2569. if(txProfile.ChargingSchedule.Duration != -1)
  2570. {
  2571. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2572. 0:
  2573. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2574. }
  2575. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2576. {
  2577. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2578. {
  2579. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2580. 0:
  2581. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2582. if(idxPeriod > 0)
  2583. {
  2584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2585. {
  2586. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2587. }
  2588. }
  2589. }
  2590. }
  2591. }
  2592. else
  2593. {
  2594. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2595. {
  2596. if(txProfile.ChargingSchedule.Duration != -1)
  2597. {
  2598. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2599. 0:
  2600. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2601. }
  2602. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2603. {
  2604. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2605. {
  2606. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2607. 0:
  2608. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2609. if(idxPeriod > 0)
  2610. {
  2611. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2612. {
  2613. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2614. }
  2615. }
  2616. }
  2617. }
  2618. }
  2619. else
  2620. {
  2621. if(txProfile.ChargingSchedule.Duration != -1)
  2622. {
  2623. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2624. 0:
  2625. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2626. }
  2627. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2628. {
  2629. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2630. {
  2631. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2632. 0:
  2633. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2634. if(idxPeriod > 0)
  2635. {
  2636. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2637. {
  2638. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. }
  2645. /*
  2646. DEBUG_INFO("txProfile after align.\n");
  2647. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2648. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2649. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2650. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2651. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2652. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2653. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2654. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2655. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2656. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2657. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2658. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2659. {
  2660. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2661. {
  2662. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2663. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2664. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2665. }
  2666. }*/
  2667. }
  2668. if(defaultTxProfile.ChargingProfileId != -1)
  2669. {
  2670. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2671. {
  2672. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2673. {
  2674. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2675. 0:
  2676. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2677. }
  2678. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2679. {
  2680. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2681. {
  2682. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2683. 0:
  2684. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2685. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2686. {
  2687. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2688. }
  2689. if(idxPeriod > 0)
  2690. {
  2691. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2692. {
  2693. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2694. }
  2695. }
  2696. }
  2697. }
  2698. }
  2699. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2700. {
  2701. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2702. {
  2703. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2704. 0:
  2705. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2706. }
  2707. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2708. {
  2709. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2710. {
  2711. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2712. 0:
  2713. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2714. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2715. {
  2716. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2717. }
  2718. if(idxPeriod > 0)
  2719. {
  2720. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2721. {
  2722. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2723. }
  2724. }
  2725. }
  2726. }
  2727. }
  2728. else
  2729. {
  2730. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2731. {
  2732. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2733. {
  2734. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2735. 0:
  2736. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2737. }
  2738. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2739. {
  2740. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2741. {
  2742. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2743. 0:
  2744. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2745. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2746. {
  2747. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2748. }
  2749. if(idxPeriod > 0)
  2750. {
  2751. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2752. {
  2753. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2754. }
  2755. }
  2756. }
  2757. }
  2758. }
  2759. else
  2760. {
  2761. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2762. {
  2763. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2764. 0:
  2765. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2766. }
  2767. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2768. {
  2769. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2770. {
  2771. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2772. 0:
  2773. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2774. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2775. {
  2776. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2777. }
  2778. if(idxPeriod > 0)
  2779. {
  2780. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2781. {
  2782. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2783. }
  2784. }
  2785. }
  2786. }
  2787. }
  2788. }
  2789. /*
  2790. DEBUG_INFO("defaultTxProfile after align.\n");
  2791. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2792. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2793. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2794. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2795. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2796. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2797. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2798. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2799. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2800. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2801. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2802. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2803. {
  2804. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2805. {
  2806. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2807. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2808. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2809. }
  2810. }
  2811. DEBUG_INFO("------------------------------------\n");*/
  2812. }
  2813. if(maxProfile.ChargingProfileId != -1)
  2814. {
  2815. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2816. {
  2817. if(maxProfile.ChargingSchedule.Duration != -1)
  2818. {
  2819. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2820. 0:
  2821. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2822. }
  2823. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2824. {
  2825. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2826. {
  2827. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2828. 0:
  2829. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2830. if(idxPeriod > 0)
  2831. {
  2832. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2833. {
  2834. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2835. }
  2836. }
  2837. }
  2838. }
  2839. }
  2840. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2841. {
  2842. if(maxProfile.ChargingSchedule.Duration != -1)
  2843. {
  2844. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2845. 0:
  2846. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2847. }
  2848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2849. {
  2850. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2851. {
  2852. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2853. 0:
  2854. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2855. if(idxPeriod > 0)
  2856. {
  2857. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2858. {
  2859. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2860. }
  2861. }
  2862. }
  2863. }
  2864. }
  2865. else
  2866. {
  2867. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2868. {
  2869. if(maxProfile.ChargingSchedule.Duration != -1)
  2870. {
  2871. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2872. 0:
  2873. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2874. }
  2875. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2876. {
  2877. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2878. {
  2879. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2880. 0:
  2881. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2882. if(idxPeriod > 0)
  2883. {
  2884. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2885. {
  2886. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2887. }
  2888. }
  2889. }
  2890. }
  2891. }
  2892. else
  2893. {
  2894. if(maxProfile.ChargingSchedule.Duration != -1)
  2895. {
  2896. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2897. 0:
  2898. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2899. }
  2900. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2901. {
  2902. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2903. {
  2904. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2905. 0:
  2906. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2907. if(idxPeriod > 0)
  2908. {
  2909. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2910. {
  2911. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. }
  2918. /*
  2919. DEBUG_INFO("MaxProfile after align.\n");
  2920. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2921. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2922. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2923. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2924. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2925. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2926. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2927. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2928. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2929. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2930. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2931. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2932. {
  2933. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2934. {
  2935. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2936. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2937. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2938. }
  2939. }
  2940. DEBUG_INFO("------------------------------------\n");*/
  2941. }
  2942. /*
  2943. * Merge to conposite schedule
  2944. */
  2945. //DEBUG_INFO("====================================\n");
  2946. // Find each profile period quantity
  2947. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2948. {
  2949. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2950. limitMax = idx+1;
  2951. }
  2952. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2953. {
  2954. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2955. limitDef = idx+1;
  2956. }
  2957. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2958. {
  2959. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2960. limitTx = idx+1;
  2961. }
  2962. // TxProfile found, composite schedule based on it
  2963. if(txProfile.ChargingProfileId != -1)
  2964. {
  2965. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2966. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2967. {
  2968. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2969. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2970. (txProfile.ChargingSchedule.Duration > 0))
  2971. {
  2972. if(maxProfile.ChargingProfileId != -1)
  2973. {
  2974. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2975. {
  2976. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2977. {
  2978. if((maxProfile.ChargingSchedule.Duration > 0))
  2979. {
  2980. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2981. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2982. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2983. }
  2984. else
  2985. {
  2986. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2987. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2988. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2989. }
  2990. }
  2991. if(idxMaxPeriod == (limitMax-1))
  2992. {
  2993. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2994. {
  2995. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2996. {
  2997. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2998. compositePeriodIdx++;
  2999. }
  3000. else
  3001. {
  3002. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3003. }
  3004. }
  3005. }
  3006. }
  3007. }
  3008. else
  3009. {
  3010. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3011. {
  3012. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3013. compositePeriodIdx++;
  3014. }
  3015. else
  3016. {
  3017. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3018. }
  3019. }
  3020. }
  3021. if(idxTxPeriod == (limitTx-1))
  3022. {
  3023. if(defaultTxProfile.ChargingProfileId != -1)
  3024. {
  3025. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3026. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3027. {
  3028. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3029. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3030. (defaultTxProfile.ChargingSchedule.Duration>0))
  3031. {
  3032. if(maxProfile.ChargingProfileId != -1)
  3033. {
  3034. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3035. {
  3036. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3037. {
  3038. if((maxProfile.ChargingSchedule.Duration > 0))
  3039. {
  3040. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3041. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3042. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3043. }
  3044. else
  3045. {
  3046. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3047. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3048. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3049. }
  3050. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3051. {
  3052. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3053. {
  3054. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3055. compositePeriodIdx++;
  3056. }
  3057. else
  3058. {
  3059. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3060. }
  3061. }
  3062. // Delete duplicate period
  3063. if(compositePeriodIdx > 1)
  3064. {
  3065. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3066. {
  3067. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3068. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3069. compositePeriodIdx -= 1;
  3070. }
  3071. }
  3072. }
  3073. else
  3074. {
  3075. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3076. {
  3077. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3078. compositePeriodIdx++;
  3079. }
  3080. else
  3081. {
  3082. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3083. }
  3084. break;
  3085. }
  3086. }
  3087. }
  3088. else
  3089. {
  3090. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3091. {
  3092. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3093. compositePeriodIdx++;
  3094. }
  3095. else
  3096. {
  3097. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3098. }
  3099. }
  3100. }
  3101. }
  3102. }
  3103. }
  3104. }
  3105. }
  3106. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3107. else if(defaultTxProfile.ChargingProfileId != -1)
  3108. {
  3109. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3110. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3111. {
  3112. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3113. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3114. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3115. {
  3116. if(maxProfile.ChargingProfileId != -1)
  3117. {
  3118. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3119. {
  3120. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3121. {
  3122. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3123. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3124. if((maxProfile.ChargingSchedule.Duration > 0))
  3125. {
  3126. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3127. }
  3128. else
  3129. {
  3130. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3131. }
  3132. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3133. {
  3134. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3135. {
  3136. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3137. compositePeriodIdx++;
  3138. }
  3139. else
  3140. {
  3141. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3142. }
  3143. }
  3144. // Delete duplicate period
  3145. if(compositePeriodIdx > 1)
  3146. {
  3147. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3148. {
  3149. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3150. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3151. compositePeriodIdx -= 1;
  3152. }
  3153. }
  3154. }
  3155. else
  3156. {
  3157. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3158. {
  3159. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3160. compositePeriodIdx++;
  3161. }
  3162. else
  3163. {
  3164. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3165. }
  3166. break;
  3167. }
  3168. }
  3169. }
  3170. else
  3171. {
  3172. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3173. {
  3174. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3175. compositePeriodIdx++;
  3176. }
  3177. else
  3178. {
  3179. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3180. }
  3181. }
  3182. }
  3183. }
  3184. }
  3185. // Fill other period by MaxProfile
  3186. if(maxProfile.ChargingProfileId != -1)
  3187. {
  3188. if(compositePeriodIdx==0)
  3189. {
  3190. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3191. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3192. {
  3193. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3194. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3195. (maxProfile.ChargingSchedule.Duration > 0))
  3196. {
  3197. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3198. {
  3199. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3200. compositePeriodIdx++;
  3201. }
  3202. else
  3203. {
  3204. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3205. }
  3206. }
  3207. }
  3208. }
  3209. else
  3210. {
  3211. int lastCompositePeriodIdx = compositePeriodIdx;
  3212. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3213. {
  3214. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3215. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3216. (maxProfile.ChargingSchedule.Duration > 0))
  3217. {
  3218. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3219. {
  3220. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3221. {
  3222. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3223. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3224. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3225. }
  3226. else
  3227. {
  3228. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3229. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3230. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3231. }
  3232. }
  3233. if(tmpPeriod.Limit != -1)
  3234. {
  3235. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3236. {
  3237. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3238. {
  3239. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3240. compositePeriodIdx++;
  3241. }
  3242. else
  3243. {
  3244. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3245. }
  3246. }
  3247. // Delete duplicate period
  3248. if(compositePeriodIdx > 1)
  3249. {
  3250. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3251. {
  3252. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3253. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3254. compositePeriodIdx -= 1;
  3255. }
  3256. }
  3257. }
  3258. }
  3259. }
  3260. }
  3261. }
  3262. compositeProfile->ChargingSchedule.Duration = durationReq;
  3263. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3264. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3265. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3266. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3268. {
  3269. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3270. {
  3271. compositeProfile->ChargingProfileId = 1;
  3272. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3273. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3274. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3275. }
  3276. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3277. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3278. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3279. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3280. }
  3281. if(line)
  3282. free(line);
  3283. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3284. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3285. }
  3286. //==========================================
  3287. // Init all share memory
  3288. //==========================================
  3289. int InitShareMemory()
  3290. {
  3291. int result = PASS;
  3292. int MeterSMId;
  3293. //creat ShmSysConfigAndInfo
  3294. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3295. {
  3296. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3297. result = FAIL;
  3298. }
  3299. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3300. {
  3301. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3302. result = FAIL;
  3303. }
  3304. else
  3305. {}
  3306. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3307. {
  3308. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3309. result = FAIL;
  3310. }
  3311. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3312. {
  3313. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3314. result = FAIL;
  3315. }
  3316. else
  3317. {}
  3318. //creat ShmPsuData
  3319. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3320. {
  3321. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3322. result = FAIL;
  3323. }
  3324. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3325. {
  3326. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3327. result = FAIL;
  3328. }
  3329. else
  3330. {}
  3331. //creat ShmOCPP16Data
  3332. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3333. {
  3334. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3335. result = FAIL;
  3336. }
  3337. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3338. {
  3339. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3340. result = FAIL;
  3341. }
  3342. else
  3343. {}
  3344. /****************************** For Initial Settings************************************************/
  3345. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3346. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3347. // allocate Configuration memory address
  3348. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3349. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3350. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3351. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3352. //offline MeterValue Interval
  3353. TempMeterValueInterval = 0;
  3354. return result;
  3355. }
  3356. int ProcessShareMemory()
  3357. {
  3358. if(InitShareMemory() == FAIL)
  3359. {
  3360. DEBUG_ERROR("InitShareMemory NG\n");
  3361. if(ShmStatusCodeData!=NULL)
  3362. {
  3363. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3364. }
  3365. sleep(5);
  3366. return FAIL;
  3367. }
  3368. return PASS;
  3369. }
  3370. void CheckSystemValue(void)
  3371. {
  3372. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3373. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3374. char filenmae[100]={0};
  3375. char str[100]={0};
  3376. int tempIndex = 0;
  3377. //===============================
  3378. // send Heartbeat
  3379. //===============================
  3380. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3381. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3382. {
  3383. clientTime.Heartbeat=time((time_t*)NULL);
  3384. if(server_sign == TRUE)
  3385. {
  3386. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3387. }
  3388. else
  3389. {
  3390. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3391. }
  3392. }
  3393. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3394. {
  3395. //parameter for test
  3396. sendHeartbeatRequest(0);
  3397. //==============================================
  3398. // Reset Waiting Time
  3399. //==============================================
  3400. HeartBeatWithNOResponse += 1;
  3401. }
  3402. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3403. {
  3404. //==========================================
  3405. // csu trigger DataTransferReq
  3406. //==========================================
  3407. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3408. {
  3409. sendDataTransferRequest(gun_index);
  3410. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3411. }
  3412. //===============================
  3413. // CSU Trigger Authorize Request
  3414. //===============================
  3415. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3416. {
  3417. sendAuthorizeRequest(0);
  3418. authorizeRetryTimes = authorizeRetryTimes + 1;
  3419. if(authorizeRetryTimes < 3)
  3420. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3421. }
  3422. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3423. {
  3424. authorizeRetryTimes = 0;
  3425. SetOcppConnStatus(FALSE);
  3426. server_sign = FALSE;
  3427. }
  3428. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  3429. {
  3430. sendAuthorizeRequest(0);
  3431. }
  3432. //==============================================
  3433. // Charger start transaction
  3434. //==============================================
  3435. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3436. {
  3437. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3438. sendStartTransactionRequest(gun_index);
  3439. clientTime.StartTransaction = time((time_t*)NULL);
  3440. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3441. storeTempStopTransaction(gun_index);
  3442. }
  3443. //==============================================
  3444. // Charger stop transaction
  3445. //==============================================
  3446. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3447. {
  3448. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3449. sendStopTransactionRequest(gun_index);
  3450. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3451. clientTime.StopTransaction = time((time_t*)NULL);
  3452. }
  3453. //==============================================
  3454. // Charger status report
  3455. //==============================================
  3456. //--- Check Mode Change ---//
  3457. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3458. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3459. {
  3460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3461. {
  3462. tempIndex = ((gun_index==2) ? 1: 0);
  3463. }
  3464. else
  3465. {
  3466. tempIndex = gun_index;
  3467. }
  3468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3469. {
  3470. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3471. {
  3472. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3473. {
  3474. // Sent unplug message for California pricing logic
  3475. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3476. {
  3477. uint8_t ts[20];
  3478. getNowDatetime(ts);
  3479. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3480. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3481. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3482. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3483. }
  3484. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3485. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3486. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3487. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3488. {
  3489. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3490. if((access(filenmae,F_OK))!=-1)
  3491. {
  3492. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3493. sprintf(str,"rm -f %s",filenmae);
  3494. system(str);
  3495. }
  3496. }
  3497. }
  3498. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3499. #if 1 // for TempStopTransaction
  3500. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3501. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3502. {
  3503. checkTempStopTransaction(gun_index);
  3504. }
  3505. #endif
  3506. }
  3507. }
  3508. }
  3509. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3510. {
  3511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3512. {
  3513. tempIndex = ((gun_index==2) ? 1: 0);
  3514. }
  3515. else
  3516. {
  3517. tempIndex = gun_index;
  3518. }
  3519. for (int index = 0; index < CCS_QUANTITY; index++)
  3520. {
  3521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3522. {
  3523. 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]*/ )
  3524. {
  3525. // Sent unplug message for California pricing logic
  3526. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3527. {
  3528. uint8_t ts[20];
  3529. getNowDatetime(ts);
  3530. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3531. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3532. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3533. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3534. }
  3535. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3536. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3537. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3538. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3539. {
  3540. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3541. if((access(filenmae,F_OK))!=-1)
  3542. {
  3543. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3544. sprintf(str,"rm -f %s",filenmae);
  3545. system(str);
  3546. }
  3547. }
  3548. }
  3549. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3550. #if 1 // for TempStopTransaction
  3551. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3552. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3553. {
  3554. checkTempStopTransaction(gun_index);
  3555. }
  3556. #endif
  3557. }
  3558. }
  3559. }
  3560. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3561. {
  3562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3563. {
  3564. tempIndex = ((gun_index==2) ? 1: 0);
  3565. }
  3566. else
  3567. {
  3568. tempIndex = gun_index;
  3569. }
  3570. for (int index = 0; index < GB_QUANTITY; index++)
  3571. {
  3572. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3573. {
  3574. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3575. {
  3576. // Sent unplug message for California pricing logic
  3577. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3578. {
  3579. uint8_t ts[20];
  3580. getNowDatetime(ts);
  3581. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3582. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3583. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3584. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3585. }
  3586. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3587. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3588. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3589. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3590. {
  3591. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3592. if((access(filenmae,F_OK))!=-1)
  3593. {
  3594. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3595. sprintf(str,"rm -f %s",filenmae);
  3596. system(str);
  3597. }
  3598. }
  3599. }
  3600. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3601. #if 1 // for TempStopTransaction
  3602. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3603. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3604. {
  3605. checkTempStopTransaction(gun_index);
  3606. }
  3607. #endif
  3608. }
  3609. }
  3610. }
  3611. else if(gunType[gun_index] == GUN_TYPE_DO)
  3612. {
  3613. tempIndex = gun_index;
  3614. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3615. {
  3616. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3617. {
  3618. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3619. {
  3620. // Sent unplug message for California pricing logic
  3621. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3622. {
  3623. uint8_t ts[20];
  3624. getNowDatetime(ts);
  3625. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3626. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3627. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3628. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3629. }
  3630. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3631. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3632. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3633. 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
  3634. {
  3635. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3636. if((access(filenmae,F_OK))!=-1)
  3637. {
  3638. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3639. sprintf(str,"rm -f %s",filenmae);
  3640. system(str);
  3641. }
  3642. }
  3643. }
  3644. 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);
  3645. #if 1 // for TempStopTransaction
  3646. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3647. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3648. {
  3649. checkTempStopTransaction(gun_index);
  3650. }
  3651. #endif
  3652. }
  3653. }
  3654. }
  3655. else
  3656. {
  3657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3658. {
  3659. tempIndex = 2;
  3660. }
  3661. else
  3662. {
  3663. tempIndex = gun_index;
  3664. }
  3665. for (int index = 0; index < AC_QUANTITY; index++)
  3666. {
  3667. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3668. {
  3669. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3670. {
  3671. // Sent unplug message for California pricing logic
  3672. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3673. {
  3674. uint8_t ts[20];
  3675. getNowDatetime(ts);
  3676. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3677. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3678. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3679. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3680. }
  3681. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3682. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3683. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3684. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3685. {
  3686. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3687. if((access(filenmae,F_OK))!=-1)
  3688. {
  3689. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3690. sprintf(str,"rm -f %s",filenmae);
  3691. system(str);
  3692. }
  3693. }
  3694. }
  3695. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3696. #if 1 // for TempStopTransaction
  3697. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3698. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3699. {
  3700. checkTempStopTransaction(gun_index);
  3701. }
  3702. #endif
  3703. }
  3704. }// END
  3705. }
  3706. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3707. (
  3708. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3709. )
  3710. )
  3711. {
  3712. if(SystemInitial > 0)
  3713. SystemInitial -= 1;
  3714. sendStatusNotificationRequest(gun_index);
  3715. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3716. }
  3717. //==============================================
  3718. // CSU Trigger Smart Charging Profilw
  3719. //==============================================
  3720. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3721. {
  3722. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3723. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3724. }
  3725. //==============================================
  3726. // Meter report
  3727. //==============================================
  3728. // Trigger MeterValue
  3729. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3730. {
  3731. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3732. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3733. }
  3734. // ClockAlign MeterValue
  3735. 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))
  3736. {
  3737. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3738. {
  3739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3740. {
  3741. tempIndex = ((gun_index==2) ? 1: 0);
  3742. }
  3743. else
  3744. {
  3745. tempIndex = gun_index;
  3746. }
  3747. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3748. {
  3749. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3750. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3751. {
  3752. reqClockAlignMeter[gun_index] = 1;
  3753. }
  3754. }// End for CHAdeMO
  3755. }
  3756. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3757. {
  3758. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3759. {
  3760. tempIndex = ((gun_index==2) ? 1: 0);
  3761. }
  3762. else
  3763. {
  3764. tempIndex = gun_index;
  3765. }
  3766. for (int index = 0; index < CCS_QUANTITY; index++)
  3767. {
  3768. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3769. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3770. {
  3771. reqClockAlignMeter[gun_index] = 1;
  3772. }
  3773. } // End for CCS
  3774. }
  3775. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3776. {
  3777. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3778. {
  3779. tempIndex = ((gun_index==2) ? 1: 0);
  3780. }
  3781. else
  3782. {
  3783. tempIndex = gun_index;
  3784. }
  3785. for (int index = 0; index < GB_QUANTITY; index++)
  3786. {
  3787. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3788. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3789. {
  3790. reqClockAlignMeter[gun_index] = 1;
  3791. }
  3792. }// End for GB
  3793. }
  3794. else if(gunType[gun_index] == GUN_TYPE_DO)
  3795. {
  3796. tempIndex = gun_index;
  3797. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3798. {
  3799. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3800. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3801. {
  3802. reqClockAlignMeter[gun_index] = 1;
  3803. }
  3804. }
  3805. }
  3806. else
  3807. {
  3808. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3809. {
  3810. tempIndex = 2;
  3811. }
  3812. else
  3813. {
  3814. tempIndex = gun_index;
  3815. }
  3816. for (int index = 0; index < AC_QUANTITY; index++)
  3817. {
  3818. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3819. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3820. {
  3821. reqClockAlignMeter[gun_index] = 1;
  3822. }
  3823. }//End for AC
  3824. }
  3825. if(reqClockAlignMeter[gun_index] == 1)
  3826. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3827. }
  3828. // Sample period MeterValue
  3829. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  3830. {
  3831. //check Transaction active
  3832. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3833. {
  3834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3835. {
  3836. tempIndex = ((gun_index==2) ? 1: 0);
  3837. }
  3838. else
  3839. {
  3840. tempIndex = gun_index;
  3841. }
  3842. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3843. {
  3844. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3845. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3846. {
  3847. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3848. {
  3849. reqSampleMeter[gun_index] = 1;
  3850. }
  3851. }
  3852. }// End for CHAdeMO
  3853. }
  3854. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3855. {
  3856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3857. {
  3858. tempIndex = ((gun_index==2) ? 1: 0);
  3859. }
  3860. else
  3861. {
  3862. tempIndex = gun_index;
  3863. }
  3864. for (int index = 0; index < CCS_QUANTITY; index++)
  3865. {
  3866. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3867. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3868. {
  3869. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3870. {
  3871. reqSampleMeter[gun_index] = 1;
  3872. }
  3873. }
  3874. } // End for CCS
  3875. }
  3876. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3877. {
  3878. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3879. {
  3880. tempIndex = ((gun_index==2) ? 1: 0);
  3881. }
  3882. else
  3883. {
  3884. tempIndex = gun_index;
  3885. }
  3886. for (int index = 0; index < GB_QUANTITY; index++)
  3887. {
  3888. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3889. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3890. {
  3891. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3892. {
  3893. reqSampleMeter[gun_index] = 1;
  3894. }
  3895. }
  3896. }// End for GB
  3897. }
  3898. else if(gunType[gun_index] == GUN_TYPE_DO)
  3899. {
  3900. tempIndex = gun_index;
  3901. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3902. {
  3903. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3904. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3905. {
  3906. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3907. {
  3908. reqSampleMeter[gun_index] = 1;
  3909. }
  3910. }
  3911. }
  3912. }
  3913. else
  3914. {
  3915. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3916. {
  3917. tempIndex = 2;
  3918. }
  3919. else
  3920. {
  3921. tempIndex = gun_index;
  3922. }
  3923. for (int index = 0; index < AC_QUANTITY; index++)
  3924. {
  3925. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3926. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3927. {
  3928. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3929. {
  3930. reqSampleMeter[gun_index] = 1;
  3931. }
  3932. }
  3933. }//End for AC
  3934. }
  3935. if(reqSampleMeter[gun_index] == 1)
  3936. {
  3937. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3938. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3939. storeTempStopTransaction(gun_index);
  3940. }
  3941. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3942. }
  3943. //==============================================
  3944. // Check Connector reserved
  3945. //==============================================
  3946. //===============================
  3947. // Check if Reserve is expired
  3948. //===============================
  3949. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  3950. {
  3951. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  3952. {
  3953. DEBUG_INFO("reserve expired.\n");
  3954. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3955. }
  3956. }//END OF Check if Reserve is expired
  3957. //==========================================
  3958. // csu trigger FirmwareStatusNotificationReq
  3959. //==========================================
  3960. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3961. {
  3962. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3963. }
  3964. //==========================================
  3965. // csu trigger DiagnosticsStatusNotificationReq
  3966. //==========================================
  3967. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3968. {
  3969. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3970. }
  3971. //==========================================
  3972. // csu trigger CancelReservationConf
  3973. //==========================================
  3974. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3975. {
  3976. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3977. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3978. }
  3979. //==========================================
  3980. // csu trigger ChangeAvailabilityConf
  3981. //==========================================
  3982. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3983. {
  3984. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3985. }
  3986. //==========================================
  3987. // csu trigger UnlockConnectorConf
  3988. //==========================================
  3989. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3990. {
  3991. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3992. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3993. }
  3994. //==========================================
  3995. // csu trigger ReserveNowConf
  3996. //==========================================
  3997. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3998. {
  3999. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4000. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4001. }
  4002. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4003. {
  4004. sendSignCertificateRequest();
  4005. }
  4006. }
  4007. }
  4008. //==========================================
  4009. // send request routine
  4010. //==========================================
  4011. int sendAuthorizeRequest(int gun_index)
  4012. {
  4013. mtrace();
  4014. int result = FAIL;
  4015. char message[100]={0};
  4016. char guid[37];
  4017. char tempdata[65]={0};
  4018. DEBUG_INFO("sendAuthorizeRequest...\n");
  4019. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4020. //Local Authorize
  4021. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4022. {
  4023. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4024. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4025. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4026. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4027. result = PASS;
  4028. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4029. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4030. authorizeRetryTimes = 0;
  4031. return result;
  4032. }
  4033. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  4034. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4035. {
  4036. // Query from cache
  4037. DEBUG_INFO("Authorize from cache.\n");
  4038. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4039. // Query from list
  4040. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4041. {
  4042. DEBUG_INFO("Authorize from list.\n");
  4043. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4044. }
  4045. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4046. {
  4047. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4048. {
  4049. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4050. }
  4051. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4052. {
  4053. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4054. }
  4055. if(!GetOcppConnStatus())
  4056. {
  4057. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4058. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4059. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4060. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4061. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4062. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4063. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4064. authorizeRetryTimes = 0;
  4065. return result;
  4066. }
  4067. }
  4068. else
  4069. {
  4070. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4071. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4072. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4073. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4074. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4075. else
  4076. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4077. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4078. result = PASS;
  4079. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4080. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4081. authorizeRetryTimes = 0;
  4082. return result;
  4083. }
  4084. }
  4085. //initialize struct Authorize
  4086. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4087. //get data from shared memory
  4088. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4089. random_uuid(guid);
  4090. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4091. LWS_Send(message);
  4092. sprintf(tempdata, "Authorize,%d", gun_index);
  4093. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4094. {
  4095. result = PASS;
  4096. DEBUG_INFO("Authorize mapItem pass\n");
  4097. }
  4098. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4099. return result;
  4100. }
  4101. int sendBootNotificationRequest(void)
  4102. {
  4103. mtrace();
  4104. int result = FAIL;
  4105. char message[500]={0}, payload[700]={0};
  4106. char guid[37]={0};
  4107. char tempdata[65]={0};
  4108. // Fill BootNotification fields
  4109. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4110. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4111. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4112. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4113. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4114. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4115. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4116. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4117. ShmOCPP16Data->ChargeBoxId
  4118. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4119. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4120. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4121. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4122. ,ShmOCPP16Data->BootNotification.CpIccid
  4123. ,ShmOCPP16Data->BootNotification.CpImsi);
  4124. random_uuid(guid);
  4125. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4126. LWS_Send(message);
  4127. sprintf(tempdata, "BootNotification,0");
  4128. 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*/)
  4129. {
  4130. result = PASS;
  4131. }
  4132. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4133. strcpy(queuedata,message);
  4134. return result;
  4135. }
  4136. int sendDataTransferRequest(int gun_index)
  4137. {
  4138. mtrace();
  4139. char message[1000]={0};
  4140. char guid[37]={0};
  4141. char tempdata[65]={0};
  4142. int result = FAIL;
  4143. random_uuid(guid);
  4144. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4145. MESSAGE_TYPE_CALL,
  4146. guid,
  4147. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4148. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4149. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4150. LWS_Send(message);
  4151. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4152. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4153. {
  4154. result = PASS;
  4155. DEBUG_INFO("DataTransfer mapItem pass\n");
  4156. }
  4157. return result;
  4158. }
  4159. int sendDiagnosticsStatusNotificationRequest(char *status)
  4160. {
  4161. mtrace();
  4162. int result = FAIL;
  4163. char message[110]={0};
  4164. char guid[37]={0};
  4165. char tempdata[65]={0};
  4166. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4167. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4168. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4169. random_uuid(guid);
  4170. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4171. LWS_SendNow(message);
  4172. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4173. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4174. {
  4175. result = PASS;
  4176. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4177. }
  4178. //#ifdef SystemLogMessage
  4179. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4180. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4181. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4182. //#endif
  4183. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4184. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4185. //record status
  4186. if(strcmp(status,"Idle")==0)
  4187. {
  4188. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4189. }
  4190. else if(strcmp(status,"Uploaded")==0)
  4191. {
  4192. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4193. }
  4194. else if(strcmp(status,"UploadFailed")==0)
  4195. {
  4196. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4197. }
  4198. else if(strcmp(status,"Uploading")==0)
  4199. {
  4200. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4201. }
  4202. return result;
  4203. }
  4204. int sendFirmwareStatusNotificationRequest(char *status)
  4205. {
  4206. mtrace();
  4207. int result = FAIL;
  4208. char message[110]={0};
  4209. char guid[37]={0};
  4210. char tempdata[65]={0};
  4211. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4212. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4213. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4214. random_uuid(guid);
  4215. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4216. LWS_SendNow(message);
  4217. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4218. 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*/)
  4219. {
  4220. result = PASS;
  4221. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4222. }
  4223. //#ifdef SystemLogMessage
  4224. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4225. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4226. //#endif
  4227. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4228. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4229. //record status
  4230. if(strcmp(status,"Downloaded")==0)
  4231. {
  4232. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4233. }
  4234. else if(strcmp(status,"DownloadFailed")==0)
  4235. {
  4236. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4237. }
  4238. else if(strcmp(status,"Downloading")==0)
  4239. {
  4240. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4241. }
  4242. else if(strcmp(status,"Idle")==0)
  4243. {
  4244. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4245. }
  4246. else if(strcmp(status,"InstallationFailed")==0)
  4247. {
  4248. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4249. }
  4250. else if(strcmp(status,"Installing")==0)
  4251. {
  4252. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4253. }
  4254. else if(strcmp(status,"Installed")==0)
  4255. {
  4256. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4257. }
  4258. return result;
  4259. }
  4260. int sendHeartbeatRequest(int gun_index)
  4261. {
  4262. mtrace();
  4263. int result = FAIL;
  4264. char message[80]={0};
  4265. char guid[37]={0};
  4266. char tempdata[65]={0};
  4267. random_uuid(guid);
  4268. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4269. , MESSAGE_TYPE_CALL
  4270. , guid );
  4271. LWS_Send(message);
  4272. sprintf(tempdata, "Heartbeat,%d", 0);
  4273. 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*/)
  4274. {
  4275. result = PASS;
  4276. }
  4277. return result;
  4278. }
  4279. int sendStartTransactionRequest(int gun_index)
  4280. {
  4281. mtrace();
  4282. int result = FAIL;
  4283. char message[250]={0};
  4284. char guid[37]={0};
  4285. struct timeval tmnow;
  4286. struct tm *tm;
  4287. char buf[28];//, usec_buf[6];
  4288. char tempdata[65]={0};
  4289. int tempIndex = 0;
  4290. DEBUG_INFO("sendStartTransactionRequest...\n");
  4291. gettimeofday(&tmnow, NULL);
  4292. time_t t;
  4293. t = time(NULL);
  4294. /*UTC time and date*/
  4295. tm = gmtime(&t);
  4296. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4297. #if 0 // remove temporally
  4298. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4299. strcat(buf,".");
  4300. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4301. strcat(buf,usec_buf);
  4302. #endif
  4303. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4304. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4305. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4306. // clear StartTransaction Response
  4307. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4308. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4309. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4310. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4311. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4312. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4313. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4314. {
  4315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4316. {
  4317. tempIndex = ((gun_index==2) ? 1: 0);
  4318. }
  4319. else
  4320. {
  4321. tempIndex = gun_index;
  4322. }
  4323. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4324. {
  4325. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4326. {
  4327. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4328. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4329. }
  4330. }
  4331. }
  4332. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4333. {
  4334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4335. {
  4336. tempIndex = ((gun_index==2) ? 1: 0);
  4337. }
  4338. else
  4339. {
  4340. tempIndex = gun_index;
  4341. }
  4342. for (int index = 0; index < CCS_QUANTITY; index++)
  4343. {
  4344. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4345. {
  4346. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4347. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4348. }
  4349. }
  4350. }
  4351. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4352. {
  4353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4354. {
  4355. tempIndex = ((gun_index==2) ? 1: 0);
  4356. }
  4357. else
  4358. {
  4359. tempIndex = gun_index;
  4360. }
  4361. for (int index = 0; index < GB_QUANTITY; index++)
  4362. {
  4363. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4364. {
  4365. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4366. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4367. }
  4368. }
  4369. }
  4370. else if(gunType[gun_index] == GUN_TYPE_DO)
  4371. {
  4372. tempIndex = gun_index;
  4373. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4374. {
  4375. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4376. {
  4377. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4378. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4379. }
  4380. }
  4381. }
  4382. else
  4383. {
  4384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4385. {
  4386. tempIndex = 2;
  4387. }
  4388. else
  4389. {
  4390. tempIndex = gun_index;
  4391. }
  4392. for (int index = 0; index < AC_QUANTITY; index++)
  4393. {
  4394. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4395. {
  4396. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4397. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4398. }
  4399. }
  4400. }
  4401. random_uuid(guid);
  4402. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4403. {
  4404. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4405. , gun_index +1
  4406. , MESSAGE_TYPE_CALL
  4407. , guid
  4408. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4409. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4410. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4411. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4412. }
  4413. else
  4414. {
  4415. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4416. , gun_index +1
  4417. , MESSAGE_TYPE_CALL
  4418. , guid
  4419. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4420. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4421. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4422. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4423. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4424. }
  4425. #if 1
  4426. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4427. 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*/)
  4428. {
  4429. result = PASS;
  4430. }
  4431. #endif
  4432. strcpy(queuedata, message);
  4433. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4434. OCPP_insert_transaction_msg(YES, queuedata);
  4435. return result;
  4436. }
  4437. int sendStatusNotificationRequest(int gun_index)
  4438. {
  4439. mtrace();
  4440. int result = FAIL;
  4441. char message[600]={0};
  4442. char guid[37];
  4443. int currentStatus = 0;
  4444. struct timeval tmnow;
  4445. struct tm *tm;
  4446. char buf[28];//, usec_buf[6];
  4447. char tempdata[65]={0};
  4448. int tempIndex = 0;
  4449. uint8_t isStateChanged = TRUE;
  4450. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4451. gettimeofday(&tmnow, NULL);
  4452. time_t t;
  4453. t = time(NULL);
  4454. /*UTC time and date*/
  4455. tm = gmtime(&t);
  4456. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4457. #if 0 // remove temporally
  4458. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4459. strcat(buf,".");
  4460. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4461. strcat(buf,usec_buf);
  4462. #endif
  4463. //printf("%s",buf);
  4464. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4465. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4466. // it's option
  4467. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4468. /*
  4469. enum _SYSTEM_STATUS
  4470. {
  4471. S_BOOTING = 0,
  4472. S_IDLE, = 1
  4473. S_AUTHORIZING, =2
  4474. S_REASSIGN_CHECK, =3
  4475. S_REASSIGN, =4
  4476. S_PRECHARGE, =5
  4477. S_PREPARING_FOR_EV, =6
  4478. S_PREPARING_FOR_EVSE, =7
  4479. S_CHARGING, =8
  4480. S_TERMINATING, =9
  4481. S_COMPLETE, =10
  4482. S_ALARM, =11
  4483. S_FAULT =12
  4484. }
  4485. */
  4486. //check Transaction active
  4487. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4488. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4489. {
  4490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4491. {
  4492. tempIndex = ((gun_index==2) ? 1: 0);
  4493. }
  4494. else
  4495. {
  4496. tempIndex = gun_index;
  4497. }
  4498. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4499. {
  4500. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4501. {
  4502. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4503. {
  4504. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4505. {
  4506. currentStatus = Preparing; //OCPP Status: Preparing
  4507. }
  4508. else
  4509. {
  4510. currentStatus = Available; //OCPP Status: Available
  4511. }
  4512. }
  4513. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4514. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4515. ) //S_PRECHARGE
  4516. {
  4517. currentStatus = Preparing; //OCPP Status: Preparing
  4518. }
  4519. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4520. {
  4521. currentStatus = Charging; //OCPP Status: Charging
  4522. }
  4523. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4524. {
  4525. currentStatus = Finishing; //OCPP Status: Finishing
  4526. }
  4527. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4528. {
  4529. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4530. }
  4531. 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
  4532. {
  4533. currentStatus = Unavailable; //OCPP Status: Unavailable
  4534. }
  4535. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4536. {
  4537. currentStatus = Faulted; //OCPP Status: Faulted
  4538. }
  4539. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4540. {
  4541. currentStatus = Reserved; //OCPP Status: Reserved
  4542. }
  4543. } //end of the same index
  4544. }//end of for CHAdeMO_QUANTITY
  4545. }
  4546. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4547. {
  4548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4549. {
  4550. tempIndex = ((gun_index==2) ? 1: 0);
  4551. }
  4552. else
  4553. {
  4554. tempIndex = gun_index;
  4555. }
  4556. for (int index = 0; index < CCS_QUANTITY; index++)
  4557. {
  4558. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4559. {
  4560. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4561. {
  4562. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4563. {
  4564. currentStatus = Preparing; //OCPP Status: Preparing
  4565. }
  4566. else
  4567. {
  4568. currentStatus = Available; //OCPP Status: Available
  4569. }
  4570. }
  4571. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4572. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4573. ) //S_PRECHARGE
  4574. {
  4575. currentStatus = Preparing; //OCPP Status: Preparing
  4576. }
  4577. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4578. {
  4579. currentStatus = Charging; //OCPP Status: Charging
  4580. }
  4581. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4582. {
  4583. currentStatus = Finishing; //OCPP Status: Finishing
  4584. }
  4585. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4586. {
  4587. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4588. }
  4589. 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
  4590. {
  4591. currentStatus = Unavailable; //OCPP Status : Unavailable
  4592. }
  4593. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4594. {
  4595. currentStatus = Faulted; //OCPP Status: Faulted
  4596. }
  4597. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4598. {
  4599. currentStatus = Reserved; //OCPP Status: Reserved
  4600. }
  4601. } //end of the same index
  4602. } // end of for CCS_QUANTITY
  4603. }
  4604. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4605. {
  4606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4607. {
  4608. tempIndex = ((gun_index==2) ? 1: 0);
  4609. }
  4610. else
  4611. {
  4612. tempIndex = gun_index;
  4613. }
  4614. for (int index = 0; index < GB_QUANTITY; index++)
  4615. {
  4616. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4617. {
  4618. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4619. {
  4620. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4621. {
  4622. currentStatus = Preparing; //OCPP Status: Preparing
  4623. }
  4624. else
  4625. {
  4626. currentStatus = Available; //OCPP Status: Available
  4627. }
  4628. }
  4629. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4630. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4631. ) //S_PRECHARGE
  4632. {
  4633. currentStatus = Preparing; //OCPP Status: Preparing
  4634. }
  4635. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4636. {
  4637. currentStatus = Charging; //OCPP Status: Charging
  4638. }
  4639. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4640. {
  4641. currentStatus = Finishing; //OCPP Status: Finishing
  4642. }
  4643. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4644. {
  4645. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4646. }
  4647. 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
  4648. {
  4649. currentStatus = Unavailable; //OCPP Status: Unavailable
  4650. }
  4651. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4652. {
  4653. currentStatus = Faulted; //OCPP Status: Faulted
  4654. }
  4655. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4656. {
  4657. currentStatus = Reserved; //OCPP Status: Reserved
  4658. }
  4659. } //end of the same index
  4660. } // end of for GB_QUANTITY
  4661. }
  4662. else if(gunType[gun_index] == GUN_TYPE_DO)
  4663. {
  4664. tempIndex = gun_index;
  4665. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4666. {
  4667. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4668. {
  4669. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4670. {
  4671. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4672. {
  4673. currentStatus = Preparing; //OCPP Status: Preparing
  4674. }
  4675. else
  4676. {
  4677. currentStatus = Available; //OCPP Status: Available
  4678. }
  4679. }
  4680. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4681. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4682. ) //S_PRECHARGE
  4683. {
  4684. currentStatus = Preparing; //OCPP Status: Preparing
  4685. }
  4686. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4687. {
  4688. currentStatus = Charging; //OCPP Status: Charging
  4689. }
  4690. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4691. {
  4692. currentStatus = Finishing; //OCPP Status: Finishing
  4693. }
  4694. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4695. {
  4696. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4697. }
  4698. 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
  4699. {
  4700. currentStatus = Unavailable; //OCPP Status: Unavailable
  4701. }
  4702. 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
  4703. {
  4704. currentStatus = Faulted; //OCPP Status: Faulted
  4705. }
  4706. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4707. {
  4708. currentStatus = Reserved; //OCPP Status: Reserved
  4709. }
  4710. } //end of the same index
  4711. }
  4712. }
  4713. else
  4714. {
  4715. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4716. {
  4717. tempIndex = 2;
  4718. }
  4719. else
  4720. {
  4721. tempIndex = gun_index;
  4722. }
  4723. for (int index = 0; index < AC_QUANTITY; index++)
  4724. {
  4725. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4726. {
  4727. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4728. {
  4729. 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))
  4730. {
  4731. currentStatus = Preparing; //OCPP Status: Preparing
  4732. }
  4733. else
  4734. {
  4735. currentStatus = Available; //OCPP Status: Available
  4736. }
  4737. }
  4738. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4739. {
  4740. currentStatus = Preparing; //OCPP Status: Preparing
  4741. }
  4742. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4743. {
  4744. currentStatus = Charging; //OCPP Status: Charging
  4745. }
  4746. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4747. {
  4748. currentStatus = Finishing; //OCPP Status: Finishing
  4749. }
  4750. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4751. {
  4752. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4753. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4754. else
  4755. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4756. }
  4757. 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
  4758. {
  4759. currentStatus = Unavailable; //OCPP Status: Unavailable
  4760. }
  4761. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4762. {
  4763. currentStatus = Faulted; //OCPP Status: Faulted
  4764. }
  4765. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4766. {
  4767. currentStatus = Reserved; //OCPP Status: Reserved
  4768. }
  4769. }//end of the same index
  4770. }//end of for AC_QUANTITY
  4771. }
  4772. //it's option
  4773. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4774. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4775. {
  4776. isStateChanged = FALSE;
  4777. }
  4778. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4779. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4780. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4781. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4782. random_uuid(guid);
  4783. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4784. , MESSAGE_TYPE_CALL
  4785. , guid
  4786. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4787. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4788. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4789. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4790. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4791. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4792. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4793. if((server_sign == TRUE) && isStateChanged)
  4794. {
  4795. LWS_Send(message);
  4796. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4797. 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*/)
  4798. {
  4799. //DEBUG_ERROR("statusNotification mapitem pass");
  4800. result = PASS;
  4801. }
  4802. }
  4803. else
  4804. {
  4805. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4806. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4807. result = PASS;
  4808. }
  4809. return result;
  4810. }
  4811. int sendStopTransactionRequest(int gun_index)
  4812. {
  4813. mtrace();
  4814. int result = FAIL;
  4815. //char message[1500]={0};
  4816. char guid[37]={0};
  4817. char tempdata[65]={0};
  4818. int tempIndex = 0;
  4819. char TempStopTransaction[256];
  4820. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4821. //int idx_sample=0;
  4822. DEBUG_INFO("sendStopTransactionRequest \n");
  4823. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4824. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4825. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4826. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4827. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4828. {
  4829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4830. {
  4831. tempIndex = ((gun_index==2) ? 1: 0);
  4832. }
  4833. else
  4834. {
  4835. tempIndex = gun_index;
  4836. }
  4837. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4838. {
  4839. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4840. {
  4841. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4842. }
  4843. }// END OF CHAdeMO_QUANTITY
  4844. }
  4845. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4846. {
  4847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4848. {
  4849. tempIndex = ((gun_index==2) ? 1: 0);
  4850. }
  4851. else
  4852. {
  4853. tempIndex = gun_index;
  4854. }
  4855. for (int index = 0; index < CCS_QUANTITY; index++)
  4856. {
  4857. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4858. {
  4859. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4860. }
  4861. }// END OF CCS_QUANTITY
  4862. }
  4863. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4864. {
  4865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4866. {
  4867. tempIndex = ((gun_index==2) ? 1: 0);
  4868. }
  4869. else
  4870. {
  4871. tempIndex = gun_index;
  4872. }
  4873. for (int index = 0; index < GB_QUANTITY; index++)
  4874. {
  4875. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4876. {
  4877. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4878. }
  4879. }// END OF GB_QUANTITY
  4880. }
  4881. else if(gunType[gun_index] == GUN_TYPE_DO)
  4882. {
  4883. tempIndex = gun_index;
  4884. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4885. {
  4886. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4887. {
  4888. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4889. }
  4890. }// END OF GB_QUANTITY
  4891. }
  4892. else
  4893. {
  4894. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4895. {
  4896. tempIndex = 2;
  4897. }
  4898. else
  4899. {
  4900. tempIndex = gun_index;
  4901. }
  4902. for (int index = 0; index < AC_QUANTITY; index++)
  4903. {
  4904. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4905. {
  4906. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4907. }
  4908. }// END OF AC_QUANTITY
  4909. }
  4910. //====================================== Stop Transaction Time =====================================================
  4911. struct timeval tmnow;
  4912. struct tm *tm;
  4913. char buf[28];//, usec_buf[6];
  4914. gettimeofday(&tmnow, NULL);
  4915. time_t t;
  4916. t = time(NULL);
  4917. /*UTC time and date*/
  4918. tm = gmtime(&t);
  4919. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4921. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4922. random_uuid(guid);
  4923. /***********************************transactionData******************************************************/
  4924. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4926. //=================================
  4927. // Transaction_Begin
  4928. //=================================
  4929. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4930. {
  4931. //============================================ Energy.Active.Import.Interval ================================
  4932. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4934. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  4936. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4937. 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))
  4938. {
  4939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4940. }
  4941. else
  4942. {
  4943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4944. }
  4945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4947. }
  4948. //=================================
  4949. // Transaction_End
  4950. //=================================
  4951. // ================================= Current.Import L1 ===============================================
  4952. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4953. {
  4954. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4955. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4956. {
  4957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4958. {
  4959. tempIndex = ((gun_index==2) ? 1: 0);
  4960. }
  4961. else
  4962. {
  4963. tempIndex = gun_index;
  4964. }
  4965. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4966. {
  4967. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4968. {
  4969. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4970. }
  4971. }// End of for CHAdeMO_QUANTITY
  4972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4973. }
  4974. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4975. {
  4976. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4977. {
  4978. tempIndex = ((gun_index==2) ? 1: 0);
  4979. }
  4980. else
  4981. {
  4982. tempIndex = gun_index;
  4983. }
  4984. for (int index = 0; index < CCS_QUANTITY; index++)
  4985. {
  4986. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4987. {
  4988. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4989. }
  4990. }// End of for CCS_QUANTITY
  4991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4992. }
  4993. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4994. {
  4995. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4996. {
  4997. tempIndex = ((gun_index==2) ? 1: 0);
  4998. }
  4999. else
  5000. {
  5001. tempIndex = gun_index;
  5002. }
  5003. for (int index = 0; index < GB_QUANTITY; index++)
  5004. {
  5005. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5006. {
  5007. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5008. }
  5009. }// End of for GB_QUANTITY
  5010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5011. }
  5012. else if(gunType[gun_index] == GUN_TYPE_DO)
  5013. {
  5014. tempIndex = gun_index;
  5015. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5016. {
  5017. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5018. {
  5019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5020. }
  5021. }
  5022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5023. }
  5024. else
  5025. {
  5026. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5027. {
  5028. tempIndex = 2;
  5029. }
  5030. else
  5031. {
  5032. tempIndex = gun_index;
  5033. }
  5034. for (int index = 0; index < AC_QUANTITY; index++)
  5035. {
  5036. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5037. {
  5038. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5039. }
  5040. }// End of for AC_QUANTITY
  5041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5042. }
  5043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5048. }
  5049. // ================================= Energy.Active.Import.Interval ==============================================
  5050. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5051. {
  5052. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5053. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5054. {
  5055. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5056. {
  5057. tempIndex = ((gun_index==2) ? 1: 0);
  5058. }
  5059. else
  5060. {
  5061. tempIndex = gun_index;
  5062. }
  5063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5064. {
  5065. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5066. {
  5067. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5068. }
  5069. }// END OF CHAdeMO_QUANTITY
  5070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5071. }
  5072. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5073. {
  5074. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5075. {
  5076. tempIndex = ((gun_index==2) ? 1: 0);
  5077. }
  5078. else
  5079. {
  5080. tempIndex = gun_index;
  5081. }
  5082. for (int index = 0; index < CCS_QUANTITY; index++)
  5083. {
  5084. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5085. {
  5086. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5087. }
  5088. }// END OF CCS_QUANTITY
  5089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5090. }
  5091. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5092. {
  5093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5094. {
  5095. tempIndex = ((gun_index==2) ? 1: 0);
  5096. }
  5097. else
  5098. {
  5099. tempIndex = gun_index;
  5100. }
  5101. for (int index = 0; index < GB_QUANTITY; index++)
  5102. {
  5103. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5104. {
  5105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5106. }
  5107. }// END OF GB_QUANTITY
  5108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5109. }
  5110. else if(gunType[gun_index] == GUN_TYPE_DO)
  5111. {
  5112. tempIndex = gun_index;
  5113. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5114. {
  5115. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5116. {
  5117. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5118. }
  5119. }
  5120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5121. }
  5122. else
  5123. {
  5124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5125. {
  5126. tempIndex = 2;
  5127. }
  5128. else
  5129. {
  5130. tempIndex = gun_index;
  5131. }
  5132. for (int index = 0; index < AC_QUANTITY; index++)
  5133. {
  5134. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5135. {
  5136. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5137. }
  5138. }// END OF AC_QUANTITY
  5139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5140. }
  5141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5146. }
  5147. //=================================== Power.Active.Import ==================================================
  5148. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5149. {
  5150. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5151. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5152. {
  5153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5154. {
  5155. tempIndex = ((gun_index==2) ? 1: 0);
  5156. }
  5157. else
  5158. {
  5159. tempIndex = gun_index;
  5160. }
  5161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5162. {
  5163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5164. {
  5165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5166. }
  5167. } // End for CHAdeMO_QUANTITY
  5168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5169. }
  5170. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5171. {
  5172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5173. {
  5174. tempIndex = ((gun_index==2) ? 1: 0);
  5175. }
  5176. else
  5177. {
  5178. tempIndex = gun_index;
  5179. }
  5180. for (int index = 0; index < CCS_QUANTITY; index++)
  5181. {
  5182. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5183. {
  5184. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5185. }
  5186. } // END for CCS_QUANTITY
  5187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5188. }
  5189. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5190. {
  5191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5192. {
  5193. tempIndex = ((gun_index==2) ? 1: 0);
  5194. }
  5195. else
  5196. {
  5197. tempIndex = gun_index;
  5198. }
  5199. for (int index = 0; index < GB_QUANTITY; index++)
  5200. {
  5201. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5202. {
  5203. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5204. }
  5205. }// END for GB_QUANTITY
  5206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5207. }
  5208. else if(gunType[gun_index] == GUN_TYPE_DO)
  5209. {
  5210. tempIndex = gun_index;
  5211. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5212. {
  5213. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5214. {
  5215. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5216. }
  5217. }
  5218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5219. }
  5220. else
  5221. {
  5222. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5223. {
  5224. tempIndex = 2;
  5225. }
  5226. else
  5227. {
  5228. tempIndex = gun_index;
  5229. }
  5230. for (int index = 0; index < AC_QUANTITY; index++)
  5231. {
  5232. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5233. {
  5234. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5235. }
  5236. } // END for AC_QUANTITY
  5237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5238. }
  5239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5244. }
  5245. //============================ Voltage L1 ====================================
  5246. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5247. {
  5248. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5249. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5250. {
  5251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5252. {
  5253. tempIndex = ((gun_index==2) ? 1: 0);
  5254. }
  5255. else
  5256. {
  5257. tempIndex = gun_index;
  5258. }
  5259. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5260. {
  5261. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5262. {
  5263. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5264. }
  5265. } // END OF FOR CHAdeMO_QUANTITY
  5266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5267. }
  5268. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5269. {
  5270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5271. {
  5272. tempIndex = ((gun_index==2) ? 1: 0);
  5273. }
  5274. else
  5275. {
  5276. tempIndex = gun_index;
  5277. }
  5278. for (int index = 0; index < CCS_QUANTITY; index++)
  5279. {
  5280. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5281. {
  5282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5283. }
  5284. } // END OF FOR CCS_QUANTITY
  5285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5286. }
  5287. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5288. {
  5289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5290. {
  5291. tempIndex = ((gun_index==2) ? 1: 0);
  5292. }
  5293. else
  5294. {
  5295. tempIndex = gun_index;
  5296. }
  5297. for (int index = 0; index < GB_QUANTITY; index++)
  5298. {
  5299. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5300. {
  5301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5302. }
  5303. } // END OF FOR GB_QUANTITY
  5304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5305. }
  5306. else if(gunType[gun_index] == GUN_TYPE_DO)
  5307. {
  5308. tempIndex = gun_index;
  5309. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5310. {
  5311. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5312. {
  5313. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5314. }
  5315. }
  5316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5317. }
  5318. else
  5319. {
  5320. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5321. {
  5322. tempIndex = 2;
  5323. }
  5324. else
  5325. {
  5326. tempIndex = gun_index;
  5327. }
  5328. for (int index = 0; index < AC_QUANTITY; index++)
  5329. {
  5330. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5331. {
  5332. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5333. }
  5334. } // END OF FOR AC_QUANTITY
  5335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5336. }
  5337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5342. }
  5343. //====================== End SoC ================================
  5344. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5345. {
  5346. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5347. 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))
  5348. {
  5349. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5350. {
  5351. tempIndex = ((gun_index==2) ? 1: 0);
  5352. }
  5353. else
  5354. {
  5355. tempIndex = gun_index;
  5356. }
  5357. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5358. {
  5359. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5360. {
  5361. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5362. {
  5363. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5364. }
  5365. }
  5366. }
  5367. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5368. {
  5369. for (int index = 0; index < CCS_QUANTITY; index++)
  5370. {
  5371. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5372. {
  5373. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5374. }
  5375. }
  5376. }
  5377. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5378. {
  5379. for (int index = 0; index < GB_QUANTITY; index++)
  5380. {
  5381. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5382. {
  5383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5384. }
  5385. }
  5386. }
  5387. else if(gunType[gun_index] == GUN_TYPE_DO)
  5388. {
  5389. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5390. {
  5391. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5392. {
  5393. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5394. }
  5395. }
  5396. }
  5397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5403. } // END FOR DC CASE
  5404. }
  5405. // ================================= Current.Import L2 ===============================================
  5406. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5407. {
  5408. // AC 3 phse L2 current
  5409. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5410. {
  5411. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5412. {
  5413. tempIndex = 2;
  5414. }
  5415. else
  5416. {
  5417. tempIndex = gun_index;
  5418. }
  5419. for (int index = 0; index < AC_QUANTITY; index++)
  5420. {
  5421. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5422. {
  5423. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5424. }
  5425. }// End of for AC_QUANTITY
  5426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5427. }
  5428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5433. }
  5434. // ================================= Current.Import L3 ===============================================
  5435. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5436. {
  5437. // AC 3 phse L3 current
  5438. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5439. {
  5440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5441. {
  5442. tempIndex = 2;
  5443. }
  5444. else
  5445. {
  5446. tempIndex = gun_index;
  5447. }
  5448. for (int index = 0; index < AC_QUANTITY; index++)
  5449. {
  5450. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5451. {
  5452. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5453. }
  5454. }// End of for AC_QUANTITY
  5455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5456. }
  5457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5462. }
  5463. //============================ Voltage L2 ====================================
  5464. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5465. {
  5466. // AC 3 phse L2 voltage
  5467. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5468. {
  5469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5470. {
  5471. tempIndex = 2;
  5472. }
  5473. else
  5474. {
  5475. tempIndex = gun_index;
  5476. }
  5477. for (int index = 0; index < AC_QUANTITY; index++)
  5478. {
  5479. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5480. {
  5481. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5482. }
  5483. } // END OF FOR AC_QUANTITY
  5484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5485. }
  5486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5491. }
  5492. //============================ Voltage L3 ====================================
  5493. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5494. {
  5495. // AC 3 phse L3 voltage
  5496. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5497. {
  5498. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5499. {
  5500. tempIndex = 2;
  5501. }
  5502. else
  5503. {
  5504. tempIndex = gun_index;
  5505. }
  5506. for (int index = 0; index < AC_QUANTITY; index++)
  5507. {
  5508. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5509. {
  5510. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5511. }
  5512. } // END OF FOR AC_QUANTITY
  5513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5514. }
  5515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5520. }
  5521. //====================== Start SoC ================================
  5522. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5523. {
  5524. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5525. 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))
  5526. {
  5527. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5528. {
  5529. tempIndex = ((gun_index==2) ? 1: 0);
  5530. }
  5531. else
  5532. {
  5533. tempIndex = gun_index;
  5534. }
  5535. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5536. {
  5537. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5538. {
  5539. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5540. {
  5541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5542. }
  5543. }
  5544. }
  5545. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5546. {
  5547. for (int index = 0; index < CCS_QUANTITY; index++)
  5548. {
  5549. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5550. {
  5551. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5552. }
  5553. }
  5554. }
  5555. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5556. {
  5557. for (int index = 0; index < GB_QUANTITY; index++)
  5558. {
  5559. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5560. {
  5561. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5562. }
  5563. }
  5564. }
  5565. else if(gunType[gun_index] == GUN_TYPE_DO)
  5566. {
  5567. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5568. {
  5569. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5570. {
  5571. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5572. }
  5573. }
  5574. }
  5575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5581. } // END FOR DC CASE
  5582. }
  5583. //================================================ Message create ====================================================
  5584. json_object *StopTransaction = json_object_new_object();
  5585. json_object *transactionDatas = json_object_new_array();
  5586. json_object *sampledValues = json_object_new_array();
  5587. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5588. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5589. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5590. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5591. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5592. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5593. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5594. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5595. {
  5596. json_object *transactionData = json_object_new_object();
  5597. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5598. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5599. {
  5600. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5601. {
  5602. json_object *sampledValue = json_object_new_object();
  5603. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5604. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5605. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5606. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5607. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5608. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5609. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5610. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5611. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5612. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5613. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5614. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5615. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5616. json_object_array_add(sampledValues, sampledValue);
  5617. }
  5618. }
  5619. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5620. json_object_array_add(transactionDatas, transactionData);
  5621. }
  5622. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5623. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5624. ,MESSAGE_TYPE_CALL
  5625. ,guid
  5626. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5627. json_object_put(StopTransaction);
  5628. #if 1 // for TempStopTransaction
  5629. //Delete TempStopTransaction
  5630. if((access(TempStopTransaction,F_OK))!=-1)
  5631. {
  5632. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5633. }
  5634. #endif
  5635. #if 1
  5636. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5637. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5638. {
  5639. result = PASS;
  5640. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5641. }
  5642. #endif
  5643. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5644. OCPP_insert_transaction_msg(NO, queuedata);
  5645. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5646. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5647. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5648. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5649. {
  5650. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5651. }
  5652. //for test
  5653. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5654. return result;
  5655. }
  5656. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5657. {
  5658. mtrace();
  5659. int result = FAIL;
  5660. char guid[37]={0};
  5661. char tempdata[65]={0};
  5662. int tempIndex = 0;
  5663. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5664. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5665. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5666. //set value
  5667. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5668. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  5669. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5670. -1);
  5671. random_uuid(guid);
  5672. //UTC Date time
  5673. struct timeval tmnow;
  5674. struct tm *tm;
  5675. char buf[28];//, usec_buf[6];
  5676. gettimeofday(&tmnow, NULL);
  5677. time_t t;
  5678. t = time(NULL);
  5679. /*UTC time and date*/
  5680. tm = gmtime(&t);
  5681. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5683. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5684. //********************************(1)Current.Import L1************************************************/
  5685. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5686. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5687. (dataType == ReadingContext_Trigger))
  5688. {
  5689. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5690. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5691. {
  5692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5693. {
  5694. tempIndex = ((gun_index==2) ? 1: 0);
  5695. }
  5696. else
  5697. {
  5698. tempIndex = gun_index;
  5699. }
  5700. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5701. {
  5702. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5703. {
  5704. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5705. }
  5706. }
  5707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5708. }
  5709. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5710. {
  5711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5712. {
  5713. tempIndex = ((gun_index==2) ? 1: 0);
  5714. }
  5715. else
  5716. {
  5717. tempIndex = gun_index;
  5718. }
  5719. for (int index = 0; index < CCS_QUANTITY; index++)
  5720. {
  5721. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5722. {
  5723. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5724. }
  5725. }
  5726. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5727. }
  5728. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5729. {
  5730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5731. {
  5732. tempIndex = ((gun_index==2) ? 1: 0);
  5733. }
  5734. else
  5735. {
  5736. tempIndex = gun_index;
  5737. }
  5738. for (int index = 0; index < GB_QUANTITY; index++)
  5739. {
  5740. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5741. {
  5742. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5743. }
  5744. }
  5745. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5746. }
  5747. else if(gunType[gun_index] == GUN_TYPE_DO)
  5748. {
  5749. tempIndex = gun_index;
  5750. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5751. {
  5752. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5753. {
  5754. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5755. }
  5756. }
  5757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5758. }
  5759. else
  5760. {
  5761. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5762. {
  5763. tempIndex = 2;
  5764. }
  5765. else
  5766. {
  5767. tempIndex = gun_index;
  5768. }
  5769. for (int index = 0; index < AC_QUANTITY; index++)
  5770. {
  5771. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5772. {
  5773. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5774. }
  5775. }
  5776. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5777. }
  5778. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5779. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5780. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5781. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5782. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5783. }
  5784. //********************************(2)Energy.Active.Import.Register ************************************************/
  5785. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5786. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5787. (dataType == ReadingContext_Trigger))
  5788. {
  5789. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5790. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5791. {
  5792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5793. {
  5794. tempIndex = ((gun_index==2) ? 1: 0);
  5795. }
  5796. else
  5797. {
  5798. tempIndex = gun_index;
  5799. }
  5800. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5801. {
  5802. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5803. {
  5804. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5805. }
  5806. }
  5807. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5808. }
  5809. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5810. {
  5811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5812. {
  5813. tempIndex = ((gun_index==2) ? 1: 0);
  5814. }
  5815. else
  5816. {
  5817. tempIndex = gun_index;
  5818. }
  5819. for (int index = 0; index < CCS_QUANTITY; index++)
  5820. {
  5821. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5822. {
  5823. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5824. }
  5825. }
  5826. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5827. }
  5828. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5829. {
  5830. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5831. {
  5832. tempIndex = ((gun_index==2) ? 1: 0);
  5833. }
  5834. else
  5835. {
  5836. tempIndex = gun_index;
  5837. }
  5838. for (int index = 0; index < GB_QUANTITY; index++)
  5839. {
  5840. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5841. {
  5842. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5843. }
  5844. }
  5845. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5846. }
  5847. else if(gunType[gun_index] == GUN_TYPE_DO)
  5848. {
  5849. tempIndex = gun_index;
  5850. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5851. {
  5852. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5853. {
  5854. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5855. }
  5856. }
  5857. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5858. }
  5859. else
  5860. {
  5861. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5862. {
  5863. tempIndex = 2;
  5864. }
  5865. else
  5866. {
  5867. tempIndex = gun_index;
  5868. }
  5869. for (int index = 0; index < AC_QUANTITY; index++)
  5870. {
  5871. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5872. {
  5873. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5874. }
  5875. }
  5876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5877. }
  5878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5879. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5880. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5881. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5882. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5883. }
  5884. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5885. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5886. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5887. (dataType == ReadingContext_Trigger))
  5888. {
  5889. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5890. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5891. {
  5892. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5893. {
  5894. tempIndex = ((gun_index==2) ? 1: 0);
  5895. }
  5896. else
  5897. {
  5898. tempIndex = gun_index;
  5899. }
  5900. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5901. {
  5902. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5903. {
  5904. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5905. }
  5906. } // END OF FOR CHAdeMO_QUANTITY
  5907. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5908. }
  5909. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5910. {
  5911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5912. {
  5913. tempIndex = ((gun_index==2) ? 1: 0);
  5914. }
  5915. else
  5916. {
  5917. tempIndex = gun_index;
  5918. }
  5919. for (int index = 0; index < CCS_QUANTITY; index++)
  5920. {
  5921. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5922. {
  5923. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5924. }
  5925. } // END OF CCS_QUANTITY
  5926. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5927. }
  5928. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5929. {
  5930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5931. {
  5932. tempIndex = ((gun_index==2) ? 1: 0);
  5933. }
  5934. else
  5935. {
  5936. tempIndex = gun_index;
  5937. }
  5938. for (int index = 0; index < GB_QUANTITY; index++)
  5939. {
  5940. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5941. {
  5942. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5943. }
  5944. } // END OF GB_QUANTITY
  5945. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5946. }
  5947. else if(gunType[gun_index] == GUN_TYPE_DO)
  5948. {
  5949. tempIndex = gun_index;
  5950. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5951. {
  5952. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5953. {
  5954. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5955. }
  5956. }
  5957. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5958. }
  5959. else
  5960. {
  5961. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5962. {
  5963. tempIndex = 2;
  5964. }
  5965. else
  5966. {
  5967. tempIndex = gun_index;
  5968. }
  5969. for (int index = 0; index < AC_QUANTITY; index++)
  5970. {
  5971. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5972. {
  5973. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5974. }
  5975. }
  5976. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5977. }
  5978. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5979. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5980. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5982. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5983. }
  5984. //********************************(4)Power.Active.Import************************************************/
  5985. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5986. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5987. (dataType == ReadingContext_Trigger))
  5988. {
  5989. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5990. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5991. {
  5992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5993. {
  5994. tempIndex = ((gun_index==2) ? 1: 0);
  5995. }
  5996. else
  5997. {
  5998. tempIndex = gun_index;
  5999. }
  6000. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6001. {
  6002. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6003. {
  6004. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6005. }
  6006. } // END OF FOR
  6007. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6008. }
  6009. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6010. {
  6011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6012. {
  6013. tempIndex = ((gun_index==2) ? 1: 0);
  6014. }
  6015. else
  6016. {
  6017. tempIndex = gun_index;
  6018. }
  6019. for (int index = 0; index < CCS_QUANTITY; index++)
  6020. {
  6021. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6022. {
  6023. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6024. }
  6025. }
  6026. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6027. }
  6028. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6029. {
  6030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6031. {
  6032. tempIndex = ((gun_index==2) ? 1: 0);
  6033. }
  6034. else
  6035. {
  6036. tempIndex = gun_index;
  6037. }
  6038. for (int index = 0; index < GB_QUANTITY; index++)
  6039. {
  6040. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6041. {
  6042. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6043. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6044. }
  6045. }
  6046. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6047. }
  6048. else if(gunType[gun_index] == GUN_TYPE_DO)
  6049. {
  6050. tempIndex = gun_index;
  6051. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6052. {
  6053. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6054. {
  6055. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6056. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6057. }
  6058. }
  6059. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6060. }
  6061. else
  6062. {
  6063. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6064. {
  6065. tempIndex = 2;
  6066. }
  6067. else
  6068. {
  6069. tempIndex = gun_index;
  6070. }
  6071. for (int index = 0; index < AC_QUANTITY; index++)
  6072. {
  6073. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6074. {
  6075. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6076. }
  6077. }
  6078. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6079. }
  6080. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6081. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6082. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6083. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6084. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6085. }
  6086. //***********************************************(5)VOLTAGE L1******************************************************/
  6087. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6088. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6089. (dataType == ReadingContext_Trigger))
  6090. {
  6091. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6092. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6093. {
  6094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6095. {
  6096. tempIndex = ((gun_index==2) ? 1: 0);
  6097. }
  6098. else
  6099. {
  6100. tempIndex = gun_index;
  6101. }
  6102. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6103. {
  6104. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6105. {
  6106. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6107. }
  6108. }
  6109. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6110. }
  6111. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6112. {
  6113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6114. {
  6115. tempIndex = ((gun_index==2) ? 1: 0);
  6116. }
  6117. else
  6118. {
  6119. tempIndex = gun_index;
  6120. }
  6121. for (int index = 0; index < CCS_QUANTITY; index++)
  6122. {
  6123. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6124. {
  6125. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6126. }
  6127. }
  6128. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6129. }
  6130. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6131. {
  6132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6133. {
  6134. tempIndex = ((gun_index==2) ? 1: 0);
  6135. }
  6136. else
  6137. {
  6138. tempIndex = gun_index;
  6139. }
  6140. for (int index = 0; index < GB_QUANTITY; index++)
  6141. {
  6142. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6143. {
  6144. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6145. }
  6146. }
  6147. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6148. }
  6149. else if(gunType[gun_index] == GUN_TYPE_DO)
  6150. {
  6151. tempIndex = gun_index;
  6152. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6153. {
  6154. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6155. {
  6156. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6157. }
  6158. }
  6159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6160. }
  6161. else
  6162. {
  6163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6164. {
  6165. tempIndex = 2;
  6166. }
  6167. else
  6168. {
  6169. tempIndex = gun_index;
  6170. }
  6171. for (int index = 0; index < AC_QUANTITY; index++)
  6172. {
  6173. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6174. {
  6175. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6176. }
  6177. }
  6178. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6179. }
  6180. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6185. }
  6186. //***********************************************(6)SOC******************************************************/
  6187. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6188. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6189. (dataType == ReadingContext_Trigger))
  6190. {
  6191. 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))
  6192. {
  6193. //idx_sample=5;
  6194. //sampledValue = NULL;
  6195. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6196. {
  6197. tempIndex = ((gun_index==2) ? 1: 0);
  6198. }
  6199. else
  6200. {
  6201. tempIndex = gun_index;
  6202. }
  6203. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6204. {
  6205. //tempIndex = ((gun_index==2) ? 1: 0);
  6206. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6207. {
  6208. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6209. {
  6210. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6211. }
  6212. }
  6213. }
  6214. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6215. {
  6216. //tempIndex = ((gun_index==2) ? 1: 0);
  6217. for (int index = 0; index < CCS_QUANTITY; index++)
  6218. {
  6219. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6220. {
  6221. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6222. }
  6223. }
  6224. }
  6225. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6226. {
  6227. //tempIndex = ((gun_index==2) ? 1: 0);
  6228. for (int index = 0; index < GB_QUANTITY; index++)
  6229. {
  6230. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6231. {
  6232. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6233. }
  6234. }
  6235. }
  6236. else if(gunType[gun_index] == GUN_TYPE_DO)
  6237. {
  6238. //tempIndex = ((gun_index==2) ? 1: 0);
  6239. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6240. {
  6241. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6242. {
  6243. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6244. }
  6245. }
  6246. }
  6247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6251. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6253. }
  6254. }
  6255. //********************************(7)Current.Import L2************************************************/
  6256. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6257. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6258. (dataType == ReadingContext_Trigger))
  6259. {
  6260. // Only for AC 3 phase
  6261. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6262. {
  6263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6264. {
  6265. tempIndex = 2;
  6266. }
  6267. else
  6268. {
  6269. tempIndex = gun_index;
  6270. }
  6271. for (int index = 0; index < AC_QUANTITY; index++)
  6272. {
  6273. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6274. {
  6275. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6276. }
  6277. }
  6278. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6279. }
  6280. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6281. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6284. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6285. }
  6286. //********************************(8)Current.Import L3************************************************/
  6287. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6288. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6289. (dataType == ReadingContext_Trigger))
  6290. {
  6291. // Only for AC 3 phase
  6292. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6293. {
  6294. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6295. {
  6296. tempIndex = 2;
  6297. }
  6298. else
  6299. {
  6300. tempIndex = gun_index;
  6301. }
  6302. for (int index = 0; index < AC_QUANTITY; index++)
  6303. {
  6304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6305. {
  6306. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6307. }
  6308. }
  6309. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6310. }
  6311. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6314. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6315. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6316. }
  6317. //***********************************************(9)VOLTAGE L2******************************************************/
  6318. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6319. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6320. (dataType == ReadingContext_Trigger))
  6321. {
  6322. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6323. {
  6324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6325. {
  6326. tempIndex = 2;
  6327. }
  6328. else
  6329. {
  6330. tempIndex = gun_index;
  6331. }
  6332. for (int index = 0; index < AC_QUANTITY; index++)
  6333. {
  6334. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6335. {
  6336. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6337. }
  6338. }
  6339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6340. }
  6341. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6342. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6343. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6344. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6345. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6346. }
  6347. //***********************************************(10)VOLTAGE L3******************************************************/
  6348. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6349. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6350. (dataType == ReadingContext_Trigger))
  6351. {
  6352. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6353. {
  6354. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6355. {
  6356. tempIndex = 2;
  6357. }
  6358. else
  6359. {
  6360. tempIndex = gun_index;
  6361. }
  6362. for (int index = 0; index < AC_QUANTITY; index++)
  6363. {
  6364. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6365. {
  6366. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6367. }
  6368. }
  6369. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6370. }
  6371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6372. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6374. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6375. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6376. }
  6377. //***********************************************(11)Current.Offered******************************************************/
  6378. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6379. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6380. (dataType == ReadingContext_Trigger))
  6381. {
  6382. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6383. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6384. {
  6385. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6386. {
  6387. tempIndex = ((gun_index==2) ? 1: 0);
  6388. }
  6389. else
  6390. {
  6391. tempIndex = gun_index;
  6392. }
  6393. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6394. {
  6395. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6396. {
  6397. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6398. }
  6399. } // END OF FOR CHAdeMO_QUANTITY
  6400. }
  6401. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6402. {
  6403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6404. {
  6405. tempIndex = ((gun_index==2) ? 1: 0);
  6406. }
  6407. else
  6408. {
  6409. tempIndex = gun_index;
  6410. }
  6411. for (int index = 0; index < CCS_QUANTITY; index++)
  6412. {
  6413. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6414. {
  6415. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6416. }
  6417. } // END OF CCS_QUANTITY
  6418. }
  6419. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6420. {
  6421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6422. {
  6423. tempIndex = ((gun_index==2) ? 1: 0);
  6424. }
  6425. else
  6426. {
  6427. tempIndex = gun_index;
  6428. }
  6429. for (int index = 0; index < GB_QUANTITY; index++)
  6430. {
  6431. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6432. {
  6433. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6434. }
  6435. } // END OF GB_QUANTITY
  6436. }
  6437. else if(gunType[gun_index] == GUN_TYPE_DO)
  6438. {
  6439. tempIndex = gun_index;
  6440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6441. {
  6442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6443. {
  6444. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  6445. }
  6446. }
  6447. }
  6448. else
  6449. {
  6450. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6451. {
  6452. tempIndex = 2;
  6453. }
  6454. else
  6455. {
  6456. tempIndex = gun_index;
  6457. }
  6458. for (int index = 0; index < AC_QUANTITY; index++)
  6459. {
  6460. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6461. {
  6462. uint16_t currentOffer;
  6463. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6464. {
  6465. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6466. }
  6467. else
  6468. {
  6469. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6470. }
  6471. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6472. }
  6473. }
  6474. }
  6475. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6476. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6479. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6480. }
  6481. //***********************************************(12)Power.Offered******************************************************/
  6482. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6483. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6484. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6485. {
  6486. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6487. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6488. {
  6489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6490. {
  6491. tempIndex = ((gun_index==2) ? 1: 0);
  6492. }
  6493. else
  6494. {
  6495. tempIndex = gun_index;
  6496. }
  6497. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6498. {
  6499. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6500. {
  6501. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  6502. }
  6503. } // END OF FOR CHAdeMO_QUANTITY
  6504. }
  6505. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6506. {
  6507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6508. {
  6509. tempIndex = ((gun_index==2) ? 1: 0);
  6510. }
  6511. else
  6512. {
  6513. tempIndex = gun_index;
  6514. }
  6515. for (int index = 0; index < CCS_QUANTITY; index++)
  6516. {
  6517. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6518. {
  6519. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  6520. }
  6521. } // END OF CCS_QUANTITY
  6522. }
  6523. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6524. {
  6525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6526. {
  6527. tempIndex = ((gun_index==2) ? 1: 0);
  6528. }
  6529. else
  6530. {
  6531. tempIndex = gun_index;
  6532. }
  6533. for (int index = 0; index < GB_QUANTITY; index++)
  6534. {
  6535. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6536. {
  6537. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  6538. }
  6539. } // END OF GB_QUANTITY
  6540. }
  6541. else if(gunType[gun_index] == GUN_TYPE_DO)
  6542. {
  6543. tempIndex = gun_index;
  6544. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6545. {
  6546. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6547. {
  6548. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  6549. }
  6550. }
  6551. }
  6552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6554. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6555. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6556. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6557. }
  6558. // Message create ====================================================================================================
  6559. if(TRUE)
  6560. {
  6561. json_object *MeterValueReq = json_object_new_object();
  6562. json_object *MeterValues = json_object_new_array();
  6563. json_object *sampledValues = json_object_new_array();
  6564. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6565. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6566. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6567. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6568. {
  6569. json_object *MeterValue = json_object_new_object();
  6570. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6571. {
  6572. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6573. {
  6574. json_object *sampledValue = json_object_new_object();
  6575. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6576. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6577. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6578. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6579. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6580. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6581. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6582. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6583. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6584. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6585. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6586. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6587. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6588. json_object_array_add(sampledValues, sampledValue);
  6589. }
  6590. }
  6591. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6592. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6593. json_object_array_add(MeterValues, MeterValue);
  6594. }
  6595. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6596. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6597. ,gun_index + 1
  6598. ,MESSAGE_TYPE_CALL
  6599. ,guid
  6600. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6601. json_object_put(MeterValueReq);
  6602. }
  6603. // Put request guid to hash map
  6604. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6605. 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*/)
  6606. {
  6607. result = PASS;
  6608. //DEBUG_INFO("MeterValues mapitem pass\n");
  6609. }
  6610. if((dataType != ReadingContext_Trigger) &&
  6611. (dataType != ReadingContext_Sample_Clock) &&
  6612. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6613. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6614. else
  6615. {
  6616. if(FirstHeartBeat)
  6617. LWS_Send(queuedata +2);
  6618. }
  6619. return result;
  6620. }
  6621. int sendLogStatusNotificationRequest(char *status)
  6622. {
  6623. mtrace();
  6624. int result = PASS;
  6625. char message[4096]={0};
  6626. char guid[37]={0};
  6627. char tempdata[128]={0};
  6628. json_object *LogStatusNotification = json_object_new_object();
  6629. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6630. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6631. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6632. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6633. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6634. random_uuid(guid);
  6635. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6636. json_object_put(LogStatusNotification);
  6637. LWS_Send(message);
  6638. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6639. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6640. {
  6641. result = PASS;
  6642. }
  6643. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6644. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6645. return result;
  6646. }
  6647. int sendSecurityEventNotificationRequest()
  6648. {
  6649. mtrace();
  6650. int result = PASS;
  6651. char message[4096]={0};
  6652. char guid[37]={0};
  6653. char tempdata[128]={0};
  6654. json_object *SecurityEventNotification = json_object_new_object();
  6655. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6656. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6657. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6658. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6659. random_uuid(guid);
  6660. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6661. json_object_put(SecurityEventNotification);
  6662. LWS_Send(message);
  6663. sprintf(tempdata, "SecurityEventNotification,0");
  6664. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6665. {
  6666. result = PASS;
  6667. }
  6668. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6669. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6670. return result;
  6671. }
  6672. int sendSignCertificateRequest()
  6673. {
  6674. mtrace();
  6675. int result = PASS;
  6676. char message[4096]={0};
  6677. char guid[37]={0};
  6678. char tempdata[128]={0};
  6679. json_object *SignCertificate = json_object_new_object();
  6680. DEBUG_INFO("sendSignCertificateRequest...\n");
  6681. // Read csr file content
  6682. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6683. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6684. char *line = NULL;
  6685. size_t len = 0;
  6686. while(getline(&line, &len, fp) != -1)
  6687. {
  6688. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6689. {
  6690. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6691. }
  6692. }
  6693. fclose(fp);
  6694. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6695. random_uuid(guid);
  6696. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6697. json_object_put(SignCertificate);
  6698. LWS_Send(message);
  6699. sprintf(tempdata, "SignCertificate,0");
  6700. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6701. {
  6702. result = PASS;
  6703. }
  6704. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6705. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6706. return result;
  6707. }
  6708. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6709. {
  6710. mtrace();
  6711. int result = PASS;
  6712. char message[110]={0};
  6713. char guid[37]={0};
  6714. char tempdata[65]={0};
  6715. json_object *FirmwareStatusNotification = json_object_new_object();
  6716. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6717. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6718. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6719. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6720. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6721. random_uuid(guid);
  6722. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6723. json_object_put(FirmwareStatusNotification);
  6724. LWS_Send(message);
  6725. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6726. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6727. {
  6728. result = PASS;
  6729. }
  6730. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6731. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6732. return result;
  6733. }
  6734. //==========================================
  6735. // send confirm routine
  6736. //==========================================
  6737. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6738. {
  6739. mtrace();
  6740. int result = FAIL;
  6741. char message[100]={0};
  6742. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6743. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6744. LWS_Send(message);
  6745. result = TRUE;
  6746. return result;
  6747. }
  6748. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6749. {
  6750. mtrace();
  6751. int result = FAIL;
  6752. char message[100]={0};
  6753. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6754. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6755. LWS_Send(message);
  6756. result = TRUE;
  6757. return result;
  6758. }
  6759. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6760. {
  6761. mtrace();
  6762. int result = FAIL;
  6763. char message[100]={0};
  6764. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6765. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6766. LWS_Send(message);
  6767. result = TRUE;
  6768. return result;
  6769. }
  6770. int sendClearCacheConfirmation(char *uuid,char *payload)
  6771. {
  6772. mtrace();
  6773. int result = FAIL;
  6774. char message[500]={0};
  6775. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6776. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6777. LWS_Send(message);
  6778. return result;
  6779. }
  6780. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6781. {
  6782. mtrace();
  6783. int result = FAIL;
  6784. char message[500]={0};
  6785. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6786. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6787. LWS_Send(message);
  6788. return result;
  6789. }
  6790. int sendDataTransferConfirmation(char *uuid,char *payload)
  6791. {
  6792. mtrace();
  6793. char statusStr[20]={0};
  6794. char dataStr[10]={0};
  6795. char sstr[20]={0};
  6796. int c = 0;
  6797. char *loc;
  6798. int result = FAIL;
  6799. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6800. /**********************status**************************/
  6801. loc = strstr(payload, "status");
  6802. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6803. c = 0;
  6804. while (loc[3+strlen("status")+c] != '\"')
  6805. {
  6806. sstr[c] = loc[3+strlen("status")+c];
  6807. c++;
  6808. }
  6809. sstr[c] = '\0';
  6810. strcpy(statusStr, sstr);
  6811. /**********************data**************************/
  6812. loc = strstr(payload, "data");
  6813. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6814. c = 0;
  6815. while (loc[3+strlen("data")+c] != '\"')
  6816. {
  6817. sstr[c] = loc[3+strlen("data")+c];
  6818. c++;
  6819. }
  6820. sstr[c] = '\0';
  6821. strcpy(dataStr, sstr);
  6822. return result;
  6823. }
  6824. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6825. {
  6826. mtrace();
  6827. int result = FAIL;
  6828. char message[1000]={0};
  6829. int CompositeScheduleIndex = 0;
  6830. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6831. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6832. if(nPeriod == 0)
  6833. {
  6834. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6835. {
  6836. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6837. ,MESSAGE_TYPE_CALLRESULT
  6838. ,uuid
  6839. ,payload
  6840. ,connectorIdInt);
  6841. }
  6842. else
  6843. {
  6844. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6845. ,MESSAGE_TYPE_CALLRESULT
  6846. ,uuid
  6847. ,payload
  6848. ,connectorIdInt
  6849. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6850. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6851. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6852. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6853. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6854. }
  6855. }
  6856. else
  6857. {
  6858. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6859. ,MESSAGE_TYPE_CALLRESULT
  6860. ,uuid
  6861. ,payload
  6862. ,connectorIdInt
  6863. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6864. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6865. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6866. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6867. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6868. {
  6869. if (idx_sample == 0)
  6870. {
  6871. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6872. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6873. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6874. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6875. }
  6876. else
  6877. {
  6878. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6879. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6880. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6881. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6882. }
  6883. }
  6884. sprintf(message + strlen(message), "]}}]");
  6885. }
  6886. LWS_Send(message);
  6887. result = TRUE;
  6888. return result;
  6889. }
  6890. int sendGetConfigurationConfirmation(char *uuid)
  6891. {
  6892. mtrace();
  6893. int result = FAIL;
  6894. int MaxKeySupported = 0;
  6895. int sentConfigurationNumber= 0;
  6896. int sentunConfigurationNumber= 0;
  6897. char message[1024*10]={0};
  6898. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6899. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6900. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6901. ,MESSAGE_TYPE_CALLRESULT
  6902. ,uuid );
  6903. //configuration key
  6904. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6905. {
  6906. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6907. {
  6908. if (sentConfigurationNumber == 0)
  6909. {
  6910. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6911. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6912. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6913. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6914. }
  6915. else
  6916. {
  6917. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6918. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6919. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6920. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6921. }
  6922. sentConfigurationNumber = sentConfigurationNumber + 1;
  6923. }
  6924. }
  6925. sprintf(message + strlen(message), "]");
  6926. if(UnknownKeynum != 0)
  6927. {
  6928. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6929. //unkown key
  6930. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6931. {
  6932. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6933. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6934. if(sentunConfigurationNumber == 0)
  6935. {
  6936. sprintf(message + strlen(message), "\"%s\""
  6937. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6938. }
  6939. else
  6940. {
  6941. sprintf(message + strlen(message), ",\"%s\""
  6942. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6943. }
  6944. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6945. }
  6946. sprintf(message + strlen(message), "]");
  6947. }
  6948. sprintf(message + strlen(message), "}]");
  6949. LWS_Send(message);
  6950. return result;
  6951. }
  6952. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6953. {
  6954. mtrace();
  6955. int result = FAIL;
  6956. char message[400]={0};
  6957. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6958. if(strcmp(payload,"")==0)
  6959. {
  6960. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6961. }
  6962. else
  6963. {
  6964. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6965. }
  6966. LWS_Send(message);
  6967. result = TRUE;
  6968. return result;
  6969. }
  6970. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6971. {
  6972. mtrace();
  6973. int result = FAIL;
  6974. char message[80]={0};
  6975. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6976. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  6977. LWS_Send(message);
  6978. result = TRUE;
  6979. return result;
  6980. }
  6981. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6982. {
  6983. mtrace();
  6984. int result = FAIL;
  6985. char message[80]={0};
  6986. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6987. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6988. LWS_Send(message);
  6989. result = TRUE;
  6990. return result;
  6991. }
  6992. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6993. {
  6994. mtrace();
  6995. int result = FAIL;
  6996. char message[80]={0};
  6997. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6999. LWS_Send(message);
  7000. result = TRUE;
  7001. return result;
  7002. }
  7003. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7004. {
  7005. mtrace();
  7006. int result = FAIL;
  7007. char message[80]={0};
  7008. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7009. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7010. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7011. LWS_Send(message);
  7012. result = TRUE;
  7013. return result;
  7014. }
  7015. int sendResetConfirmation(char *uuid,char *payload)
  7016. {
  7017. mtrace();
  7018. int result = FAIL;
  7019. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7020. char message[80]={0};
  7021. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7022. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7023. LWS_Send(message);
  7024. result = TRUE;
  7025. return result;
  7026. }
  7027. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7028. {
  7029. mtrace();
  7030. int result = FAIL;
  7031. char message[500]={0};
  7032. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7033. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7034. LWS_Send(message);
  7035. result = TRUE;
  7036. return result;
  7037. }
  7038. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7039. {
  7040. mtrace();
  7041. int result = FAIL;
  7042. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7043. char message[80]={0};
  7044. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7045. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7046. LWS_Send(message);
  7047. result = TRUE;
  7048. return result;
  7049. }
  7050. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7051. {
  7052. mtrace();
  7053. int result = FAIL;
  7054. char message[80]={0};
  7055. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7056. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7057. LWS_Send(message);
  7058. result = TRUE;
  7059. return result;
  7060. }
  7061. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7062. {
  7063. mtrace();
  7064. int result = FAIL;
  7065. char message[80]={0};
  7066. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7067. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7068. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7069. LWS_Send(message);
  7070. result = TRUE;
  7071. return result;
  7072. }
  7073. int sendUpdateFirmwareConfirmation(char *uuid)
  7074. {
  7075. mtrace();
  7076. int result = FAIL;
  7077. char message[60]={0};
  7078. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7079. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7080. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7081. LWS_Send(message);
  7082. result = TRUE;
  7083. return result;
  7084. }
  7085. int sendCertificateSignedConfirmation(char *uuid)
  7086. {
  7087. mtrace();
  7088. int result = PASS;
  7089. char message[4096]={0};
  7090. json_object *CertificateSigned = json_object_new_object();
  7091. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7092. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7093. sprintf(message,"[%d,\"%s\",%s]"
  7094. ,MESSAGE_TYPE_CALLRESULT
  7095. ,uuid
  7096. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7097. json_object_put(CertificateSigned);
  7098. LWS_Send(message);
  7099. return result;
  7100. }
  7101. int sendDeleteCertificateConfirmation(char *uuid)
  7102. {
  7103. mtrace();
  7104. int result = PASS;
  7105. char message[4096]={0};
  7106. json_object *DeleteCertificate = json_object_new_object();
  7107. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7108. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7109. sprintf(message,"[%d,\"%s\",%s]"
  7110. ,MESSAGE_TYPE_CALLRESULT
  7111. ,uuid
  7112. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7113. json_object_put(DeleteCertificate);
  7114. LWS_Send(message);
  7115. return result;
  7116. }
  7117. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7118. {
  7119. mtrace();
  7120. int result = PASS;
  7121. char message[4096]={0};
  7122. json_object *ExtendedTriggerMessage = json_object_new_object();
  7123. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7124. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7125. sprintf(message,"[%d,\"%s\",%s]"
  7126. ,MESSAGE_TYPE_CALLRESULT
  7127. ,uuid
  7128. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7129. json_object_put(ExtendedTriggerMessage);
  7130. LWS_Send(message);
  7131. return result;
  7132. }
  7133. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7134. {
  7135. mtrace();
  7136. int result = PASS;
  7137. char message[4096]={0};
  7138. json_object *GetInstalledCertificateIds = json_object_new_object();
  7139. json_object *certificateHashDataDatas = json_object_new_array();
  7140. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7141. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7142. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7143. {
  7144. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7145. {
  7146. json_object *certificateHashData = json_object_new_object();
  7147. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7148. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7149. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7150. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7151. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7152. }
  7153. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7154. }
  7155. else
  7156. {
  7157. json_object_put(certificateHashDataDatas);
  7158. }
  7159. sprintf(message,"[%d,\"%s\",%s]"
  7160. ,MESSAGE_TYPE_CALLRESULT
  7161. ,uuid
  7162. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7163. json_object_put(GetInstalledCertificateIds);
  7164. LWS_Send(message);
  7165. return result;
  7166. }
  7167. int sendGetLogConfirmation(char *uuid)
  7168. {
  7169. mtrace();
  7170. int result = PASS;
  7171. char message[4096]={0};
  7172. json_object *GetLog = json_object_new_object();
  7173. DEBUG_INFO("sendGetLogConfirmation...\n");
  7174. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7175. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7176. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7177. sprintf(message,"[%d,\"%s\",%s]"
  7178. ,MESSAGE_TYPE_CALLRESULT
  7179. ,uuid
  7180. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7181. json_object_put(GetLog);
  7182. LWS_Send(message);
  7183. return result;
  7184. }
  7185. int sendInstallCertificateConfirmation(char *uuid)
  7186. {
  7187. mtrace();
  7188. int result = PASS;
  7189. char message[4096]={0};
  7190. json_object *InstallCertificate = json_object_new_object();
  7191. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7192. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7193. sprintf(message,"[%d,\"%s\",%s]"
  7194. ,MESSAGE_TYPE_CALLRESULT
  7195. ,uuid
  7196. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7197. json_object_put(InstallCertificate);
  7198. LWS_Send(message);
  7199. return result;
  7200. }
  7201. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7202. {
  7203. mtrace();
  7204. int result = PASS;
  7205. char message[4096]={0};
  7206. json_object *SignedUpdateFirmware = json_object_new_object();
  7207. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7208. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7209. sprintf(message,"[%d,\"%s\",%s]"
  7210. ,MESSAGE_TYPE_CALLRESULT
  7211. ,uuid
  7212. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7213. json_object_put(SignedUpdateFirmware);
  7214. LWS_Send(message);
  7215. return result;
  7216. }
  7217. int sendUnknownConfirmation(char *uuid)
  7218. {
  7219. mtrace();
  7220. int result = PASS;
  7221. char message[256]={0};
  7222. DEBUG_INFO("sendUnknownConfirmation...\n");
  7223. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7224. LWS_Send(message);
  7225. return result;
  7226. }
  7227. //==========================================
  7228. // Handle server request routine Start
  7229. //==========================================
  7230. int handleCancelReservationRequest(char *uuid, char *payload)
  7231. {
  7232. mtrace();
  7233. int result = FAIL;
  7234. int gunNO = 0;
  7235. int reservationIdInt = -1;
  7236. char comfirmstr[20];
  7237. DEBUG_INFO("handleCancelReservationRequest...\n");
  7238. json_object *CancelReservation;
  7239. CancelReservation = json_tokener_parse(payload);
  7240. if(!is_error(CancelReservation))
  7241. {
  7242. // Required data
  7243. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7244. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7245. }
  7246. json_object_put(CancelReservation);
  7247. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7248. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7249. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7250. if(reservationIdInt != -1)
  7251. {
  7252. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7253. //check Transaction active
  7254. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7255. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7256. {
  7257. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7258. {
  7259. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7260. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7261. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7262. {
  7263. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7264. }
  7265. else
  7266. {
  7267. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7268. }
  7269. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7270. goto end;
  7271. }
  7272. }
  7273. for (int index = 0; index < CCS_QUANTITY; index++)
  7274. {
  7275. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7276. {
  7277. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7278. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7279. if(gunType[2] == GUN_TYPE_CCS)
  7280. {
  7281. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7282. }
  7283. else
  7284. {
  7285. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7286. }
  7287. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7288. goto end;
  7289. }
  7290. }
  7291. for (int index = 0; index < GB_QUANTITY; index++)
  7292. {
  7293. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7294. {
  7295. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7296. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7297. if(gunType[2] == GUN_TYPE_GBT)
  7298. {
  7299. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7300. }
  7301. else
  7302. {
  7303. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7304. }
  7305. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7306. goto end;
  7307. }
  7308. }
  7309. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7310. {
  7311. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7312. {
  7313. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7314. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7315. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7316. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7317. goto end;
  7318. }
  7319. }
  7320. for (int index = 0; index < AC_QUANTITY; index++)
  7321. {
  7322. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7323. {
  7324. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7325. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7327. {
  7328. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7329. }
  7330. else
  7331. {
  7332. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7333. }
  7334. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7335. goto end;
  7336. }
  7337. }
  7338. }
  7339. //The reservationId does NOT match the reservationId
  7340. sendCancelReservationConfirmation(uuid, comfirmstr);
  7341. end:
  7342. // Fill in ocpp packet uuid
  7343. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7344. return result;
  7345. }
  7346. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7347. {
  7348. mtrace();
  7349. int result = FAIL;
  7350. int gunIndex = 0;
  7351. char typeStr[16]={0};
  7352. char comfirmstr[20];
  7353. int specificId = FALSE;
  7354. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7355. json_object *ChangeAvailability;
  7356. ChangeAvailability = json_tokener_parse(payload);
  7357. if(!is_error(ChangeAvailability))
  7358. {
  7359. // Required data
  7360. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7361. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7362. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7363. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7364. }
  7365. json_object_put(ChangeAvailability);
  7366. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7367. {
  7368. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7369. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7370. }
  7371. else if(gunIndex == 0)
  7372. {
  7373. for(int i=0; i < gunTotalNumber; i++)
  7374. {
  7375. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7376. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7377. }
  7378. }
  7379. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7381. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7382. {
  7383. specificId = TRUE;
  7384. }
  7385. if(specificId == FALSE)
  7386. goto end;
  7387. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7388. {
  7389. //----------------------gunIndex is 0 ------------------------------------------------//
  7390. if(gunIndex == 0)
  7391. {
  7392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7393. {
  7394. for(int i=0; i < gunTotalNumber; i++)
  7395. {
  7396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7397. {
  7398. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7399. {
  7400. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7401. {
  7402. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7403. goto end;
  7404. }
  7405. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7406. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7407. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7408. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7409. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7410. {
  7411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7412. goto end;
  7413. }
  7414. }
  7415. }//END FOR CHAdeMO_QUANTITY
  7416. for (int index = 0; index < CCS_QUANTITY; index++)
  7417. {
  7418. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7419. {
  7420. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7421. {
  7422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7423. goto end;
  7424. }
  7425. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7426. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7427. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7428. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7429. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7430. {
  7431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7432. goto end;
  7433. }
  7434. }
  7435. }//END FOR CCS_QUANTITY
  7436. for (int index = 0; index < GB_QUANTITY; index++)
  7437. {
  7438. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7439. {
  7440. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7441. {
  7442. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7443. goto end;
  7444. }
  7445. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7446. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7447. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7448. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7449. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7450. {
  7451. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7452. goto end;
  7453. }
  7454. }
  7455. }// END FOR GB_QUANTITY
  7456. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7457. {
  7458. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7459. {
  7460. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7461. {
  7462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7463. goto end;
  7464. }
  7465. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7466. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7467. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7468. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7469. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7470. {
  7471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7472. goto end;
  7473. }
  7474. }
  7475. }// END FOR GENERAL_GUN_QUANTITY
  7476. for (int index = 0; index < AC_QUANTITY; index++)
  7477. {
  7478. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7479. {
  7480. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7481. {
  7482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7483. goto end;
  7484. }
  7485. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7486. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7487. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7488. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7489. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7490. {
  7491. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7492. goto end;
  7493. }
  7494. }
  7495. }//END FOR AC_QUANTITY
  7496. }// END FOR gunTotalNumber
  7497. }
  7498. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7499. {
  7500. for(int i=0; i < gunTotalNumber; i++)
  7501. {
  7502. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7503. {
  7504. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7505. goto end;
  7506. }
  7507. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7508. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7509. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7510. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7511. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7512. {
  7513. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7514. goto end;
  7515. }
  7516. }
  7517. }
  7518. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7519. goto end;
  7520. }
  7521. //----------------------gunIndex is not 0 ------------------------------------------------//
  7522. //check Transaction active
  7523. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7524. {
  7525. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7526. {
  7527. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7528. {
  7529. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7530. goto end;
  7531. }
  7532. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7533. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7534. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7535. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7536. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7537. {
  7538. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7539. goto end;
  7540. }
  7541. else
  7542. {
  7543. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7544. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7545. goto end;
  7546. }
  7547. }
  7548. }//END FOR CHAdeMO_QUANTITY
  7549. for (int index = 0; index < CCS_QUANTITY; index++)
  7550. {
  7551. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7552. {
  7553. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7554. {
  7555. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7556. goto end;
  7557. }
  7558. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7559. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7560. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7561. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7562. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7563. {
  7564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7565. goto end;
  7566. }
  7567. else
  7568. {
  7569. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7570. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7571. goto end;
  7572. }
  7573. }
  7574. }//END FOR CCS_QUANTITY
  7575. for (int index = 0; index < GB_QUANTITY; index++)
  7576. {
  7577. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7578. {
  7579. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7580. {
  7581. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7582. goto end;
  7583. }
  7584. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7585. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7586. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7587. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7588. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7589. {
  7590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7591. goto end;
  7592. }
  7593. else
  7594. {
  7595. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7596. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7597. goto end;
  7598. }
  7599. }
  7600. }// END FOR GB_QUANTITY
  7601. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7602. {
  7603. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7604. {
  7605. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7606. {
  7607. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7608. goto end;
  7609. }
  7610. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7611. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7612. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7613. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7614. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7615. {
  7616. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7617. goto end;
  7618. }
  7619. else
  7620. {
  7621. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7622. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7623. goto end;
  7624. }
  7625. }
  7626. }// END FOR GENERAL_GUN_QUANTITY
  7627. for (int index = 0; index < AC_QUANTITY; index++)
  7628. {
  7629. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7630. {
  7631. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7632. {
  7633. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7634. goto end;
  7635. }
  7636. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7637. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7638. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7639. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7640. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7641. {
  7642. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7643. goto end;
  7644. }
  7645. else
  7646. {
  7647. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7648. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7649. goto end;
  7650. }
  7651. }
  7652. }//END FOR AC_QUANTITY
  7653. }//END FOR AvailabilityTypeStr[Inoperative]
  7654. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7655. {
  7656. //----------------------gunIndex is 0 ------------------------------------------------//
  7657. if(gunIndex == 0)
  7658. {
  7659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7660. {
  7661. for(int i=0; i < gunTotalNumber; i++)
  7662. {
  7663. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7664. {
  7665. 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
  7666. {
  7667. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7668. goto end;
  7669. }
  7670. }//END FOR CHAdeMO_QUANTITY
  7671. for (int index = 0; index < CCS_QUANTITY; index++)
  7672. {
  7673. 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
  7674. {
  7675. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7676. goto end;
  7677. }
  7678. }//END FOR CCS_QUANTITY
  7679. for (int index = 0; index < GB_QUANTITY; index++)
  7680. {
  7681. 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
  7682. {
  7683. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7684. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7685. goto end;
  7686. }
  7687. }// END FOR GB_QUANTITY
  7688. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7689. {
  7690. 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
  7691. {
  7692. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7693. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7694. goto end;
  7695. }
  7696. }// END FOR GENERAL_GUN_QUANTITY
  7697. for (int index = 0; index < AC_QUANTITY; index++)
  7698. {
  7699. 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
  7700. {
  7701. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7702. goto end;
  7703. }
  7704. }//END FOR CHAdeMO_QUANTITY
  7705. }// END FOR gunTotalNumber
  7706. }
  7707. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7708. {
  7709. for(int i=0; i < gunTotalNumber; i++)
  7710. {
  7711. for (int index = 0; index < AC_QUANTITY; index++)
  7712. {
  7713. 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
  7714. {
  7715. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7716. goto end;
  7717. }
  7718. }//END FOR CHAdeMO_QUANTITY
  7719. } // END FOR gunTotalNumber
  7720. }
  7721. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7722. goto end;
  7723. }
  7724. //----------------------gunIndex is not 0 ------------------------------------------------//
  7725. //check Transaction active
  7726. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7727. {
  7728. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7729. {
  7730. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7731. goto end;
  7732. }
  7733. }//END FOR CHAdeMO_QUANTITY
  7734. for (int index = 0; index < CCS_QUANTITY; index++)
  7735. {
  7736. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7737. {
  7738. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7739. goto end;
  7740. }
  7741. }//END FOR CCS_QUANTITY
  7742. for (int index = 0; index < GB_QUANTITY; index++)
  7743. {
  7744. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7745. {
  7746. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7747. goto end;
  7748. }
  7749. }// END FOR GB_QUANTITY
  7750. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7751. {
  7752. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7753. {
  7754. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7755. goto end;
  7756. }
  7757. }// END FOR GENERAL_GUN_QUANTITY
  7758. for (int index = 0; index < AC_QUANTITY; index++)
  7759. {
  7760. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7761. {
  7762. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7763. goto end;
  7764. }
  7765. }//END FOR AC_QUANTITY
  7766. }//END FOR AvailabilityTypeStr[Operative]
  7767. end:
  7768. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7769. {
  7770. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7771. }
  7772. else
  7773. {
  7774. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7775. }
  7776. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7777. {
  7778. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7779. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7780. }
  7781. else if(gunIndex == 0)
  7782. {
  7783. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7784. {
  7785. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7786. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7787. }
  7788. }
  7789. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7790. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7791. return result;
  7792. }
  7793. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7794. {
  7795. mtrace();
  7796. int result = FAIL;
  7797. char keystr[40]={0};
  7798. char valuestr[256]={0};
  7799. char comfirmstr[20]={0};
  7800. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7801. json_object *ChangeConfiguration;
  7802. ChangeConfiguration = json_tokener_parse(payload);
  7803. if(!is_error(ChangeConfiguration))
  7804. {
  7805. // Required data
  7806. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7807. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7808. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7809. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7810. }
  7811. json_object_put(ChangeConfiguration);
  7812. if((uuid==NULL) || (payload ==NULL) )
  7813. {
  7814. DEBUG_ERROR("Payload is null\n");
  7815. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7816. }
  7817. else
  7818. {
  7819. int status = setKeyValue(keystr, valuestr);
  7820. switch(status)
  7821. {
  7822. case ConfigurationStatus_Accepted:
  7823. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7824. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7825. StoreConfigurationTable();
  7826. break;
  7827. case RebootRequired:
  7828. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7829. StoreConfigurationTable();
  7830. break;
  7831. case NotSupported:
  7832. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7833. break;
  7834. case ConfigurationStatus_Rejected:
  7835. default:
  7836. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7837. break;
  7838. }
  7839. }
  7840. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7841. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7842. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7843. {
  7844. ChageWebSocketPingInterval(atoi(valuestr));
  7845. }
  7846. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7847. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7848. {
  7849. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7850. SetOcppConnStatus(FALSE);
  7851. }
  7852. return result;
  7853. }
  7854. int handleClearCacheRequest(char *uuid, char *payload)
  7855. {
  7856. mtrace();
  7857. int result = FAIL;
  7858. char comfirmstr[20];
  7859. char rmFileCmd[100]={0};
  7860. struct stat stats;
  7861. DEBUG_INFO("handleClearCacheRequest...\n");
  7862. stat("/Storage/OCPP", &stats);
  7863. // Check for directory existence
  7864. if (S_ISDIR(stats.st_mode) == 1)
  7865. {}
  7866. else
  7867. {
  7868. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7869. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7870. system(rmFileCmd);
  7871. }
  7872. if(OCPP_cleanLocalCache())
  7873. {
  7874. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7875. }
  7876. else
  7877. {
  7878. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7879. }
  7880. sendClearCacheConfirmation(uuid, comfirmstr);
  7881. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7882. return result;
  7883. }
  7884. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7885. {
  7886. mtrace();
  7887. int result = FAIL;
  7888. int resultRename;
  7889. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7890. char chargingProfilePurposeStr[26]={0};
  7891. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7892. char tempchargingProfilePurposeStr[26]={0};
  7893. char str[100]={0};
  7894. char fname[200]={0};
  7895. char comfirmstr[20]={0};
  7896. char word[1600]={0};
  7897. int clearflag = FALSE;
  7898. int chargingProfileIdIsNULL = FALSE;
  7899. int connectorIsNULL = FALSE;
  7900. int chargingProfilePurposeIsNULL = FALSE;
  7901. int stackLevelIsNULL = FALSE;
  7902. //int GotoEnd = FALSE;
  7903. FILE *fptr1, *fptr2;
  7904. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7905. int n_chargingProfile=0;
  7906. int isEmptyFile = FALSE;
  7907. char sLineWord[1600]={0};
  7908. char chargingProfiles[10][100]={0};
  7909. int ChargeProfileCount = 0;
  7910. int ch;
  7911. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7912. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7913. json_object *ClearChargingProfile;
  7914. ClearChargingProfile = json_tokener_parse(payload);
  7915. if(!is_error(ClearChargingProfile))
  7916. {
  7917. // Optional data
  7918. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7919. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7920. else
  7921. chargingProfileIdIsNULL = TRUE;
  7922. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7923. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7924. else
  7925. connectorIsNULL = TRUE;
  7926. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7927. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7928. else
  7929. chargingProfilePurposeIsNULL = TRUE;
  7930. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7931. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7932. else
  7933. stackLevelIsNULL = TRUE;
  7934. }
  7935. json_object_put(ClearChargingProfile);
  7936. if(connectorIsNULL == FALSE)
  7937. {
  7938. switch(connectorIdInt)
  7939. {
  7940. case 0:
  7941. if(chargingProfilePurposeIsNULL == TRUE)
  7942. {
  7943. int l = 0;
  7944. strcpy(fname, ChargePointMaxProfile_JSON);
  7945. if((access(fname,F_OK))!=-1)
  7946. {
  7947. strcpy(chargingProfiles[l], fname);
  7948. l = l + 1;
  7949. }
  7950. strcpy(fname, TxDefaultProfile_0_JSON);
  7951. if((access(fname,F_OK))!=-1)
  7952. {
  7953. strcpy(chargingProfiles[l], fname);
  7954. l = l + 1;
  7955. }
  7956. ChargeProfileCount = l;
  7957. }
  7958. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7959. {
  7960. strcpy(fname, ChargePointMaxProfile_JSON);
  7961. if((access(fname,F_OK))!=-1)
  7962. {
  7963. strcpy(chargingProfiles[0], fname);
  7964. ChargeProfileCount = 1;
  7965. }
  7966. }
  7967. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7968. {
  7969. strcpy(fname, TxDefaultProfile_0_JSON);
  7970. if((access(fname,F_OK))!=-1)
  7971. {
  7972. strcpy(chargingProfiles[0], fname);
  7973. ChargeProfileCount = 1;
  7974. }
  7975. }
  7976. break;
  7977. default:
  7978. if(chargingProfilePurposeIsNULL == TRUE)
  7979. {
  7980. int m = 0;
  7981. memset(fname, 0, ARRAY_SIZE(fname));
  7982. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7983. if((access(fname,F_OK))!=-1)
  7984. {
  7985. strcpy(chargingProfiles[m], fname);
  7986. m = m + 1;
  7987. }
  7988. memset(fname, 0, ARRAY_SIZE(fname));
  7989. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7990. if((access(fname,F_OK))!=-1)
  7991. {
  7992. strcpy(chargingProfiles[m], fname);
  7993. m = m + 1;
  7994. }
  7995. ChargeProfileCount = m;
  7996. }
  7997. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7998. {
  7999. //strcpy(fname, TxDefaultProfile_1_JSON);
  8000. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8001. if((access(fname,F_OK))!=-1)
  8002. {
  8003. strcpy(chargingProfiles[0], fname);
  8004. ChargeProfileCount = 1;
  8005. }
  8006. }
  8007. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8008. {
  8009. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8010. if((access(fname,F_OK))!=-1)
  8011. {
  8012. strcpy(chargingProfiles[0], fname);
  8013. ChargeProfileCount = 1;
  8014. }
  8015. //strcpy(fname, TxProfile_1_JSON);
  8016. }
  8017. //strcpy(fname, ChargePointMaxProfile_JSON );
  8018. break;
  8019. }
  8020. }
  8021. else // Check all Charging Profiles
  8022. {
  8023. int i = 0;
  8024. char fnametemp[200]={0};
  8025. ChargeProfileCount = 0;
  8026. //Check ChargePointMaxProfile.json exit
  8027. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8028. {
  8029. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8030. i = i + 1;
  8031. }
  8032. //Check TxDefaultProfile_0.json exit
  8033. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8034. {
  8035. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8036. i = i + 1;
  8037. }
  8038. //Check TxDefaultProfile_%d.json
  8039. for(int j=1; j <= gunTotalNumber; j++)
  8040. {
  8041. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8042. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8043. if((access(fnametemp,F_OK))!=-1)
  8044. {
  8045. strcpy(chargingProfiles[i], fnametemp);
  8046. i = i + 1;
  8047. }
  8048. }
  8049. //Check TxProfile_%d.json
  8050. for(int j=1; j <= gunTotalNumber; j++)
  8051. {
  8052. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8053. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8054. if((access(fnametemp,F_OK))!=-1)
  8055. {
  8056. strcpy(chargingProfiles[i], fnametemp);
  8057. i = i + 1;
  8058. }
  8059. }
  8060. ChargeProfileCount = i;
  8061. }// End connectorIsNULL is TRUE
  8062. if(ChargeProfileCount == 0)
  8063. {
  8064. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8065. goto end;
  8066. }
  8067. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8068. {
  8069. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8070. goto end;
  8071. }
  8072. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8073. {
  8074. memset(str, 0, ARRAY_SIZE(str));
  8075. // clear temp file
  8076. sprintf(str,"rm -f %s",temp);
  8077. system(str);
  8078. for(int k=0; k < ChargeProfileCount; k++)
  8079. {
  8080. memset(str, 0, ARRAY_SIZE(str));
  8081. //clear file in C
  8082. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8083. system(str);
  8084. }
  8085. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8086. goto end;
  8087. }
  8088. else if(connectorIsNULL == TRUE)
  8089. {
  8090. for(int k=0; k < ChargeProfileCount; k++)
  8091. {
  8092. fptr1 = fopen(chargingProfiles[k], "r");
  8093. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8094. //Check Charging Profile Count
  8095. while(fscanf(fptr1, "%s", word) != EOF)
  8096. {
  8097. //DEBUG_INFO("word=%s\n",word);
  8098. if(strstr(word, "chargingProfileId")!= NULL)
  8099. {
  8100. //DEBUG_INFO("test chargingProfileId \n");
  8101. n_chargingProfile = n_chargingProfile + 1;
  8102. //DEBUG_INFO("chargingProfileId Found\n");
  8103. }
  8104. }
  8105. rewind(fptr1);
  8106. //search Charging Profile Element
  8107. //int i= 0;
  8108. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8109. {
  8110. json_object *tmpProfilee;
  8111. tmpProfilee = json_tokener_parse(sLineWord);
  8112. if(!is_error(tmpProfilee))
  8113. {
  8114. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8115. {
  8116. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8117. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8118. }
  8119. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8120. {
  8121. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8122. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8123. }
  8124. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8125. {
  8126. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8127. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8128. }
  8129. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8130. {
  8131. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8132. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8133. }
  8134. }
  8135. json_object_put(tmpProfilee);
  8136. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8137. {
  8138. //------- not write to fptr2-------//
  8139. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8140. //clearflag = TRUE;
  8141. }
  8142. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8143. {
  8144. //------- not write to fptr2-------//
  8145. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8146. }
  8147. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8148. {
  8149. //------- not write to fptr2-------//
  8150. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8151. }
  8152. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8153. {
  8154. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8155. }
  8156. else
  8157. {
  8158. fprintf(fptr2, sLineWord);//writing data into file
  8159. }
  8160. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8161. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8162. if(clearflag == TRUE)
  8163. {
  8164. fclose(fptr1);
  8165. fclose(fptr2);
  8166. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8167. system(str);
  8168. // clear temp file
  8169. sprintf(str,"rm -f %s",temp);
  8170. system(str);
  8171. }
  8172. else
  8173. {
  8174. fclose(fptr1);
  8175. fclose(fptr2);
  8176. memset(str, 0, ARRAY_SIZE(str));
  8177. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8178. system(str);
  8179. resultRename = rename(temp, chargingProfiles[k]);
  8180. if(resultRename == 0)
  8181. {
  8182. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8183. }
  8184. else
  8185. {
  8186. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8187. }
  8188. if(comfirmstr[0]== 0)
  8189. {
  8190. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8191. }
  8192. //Check chargingProfile is empty file
  8193. /*------ Read the file ----------------*/
  8194. fptr1=fopen(chargingProfiles[k],"r");
  8195. ch=fgetc(fptr1);
  8196. rewind(fptr1);
  8197. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8198. if(ch!=EOF)
  8199. {
  8200. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8201. {
  8202. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8203. if(sLineWord[0]=='\0')
  8204. {
  8205. isEmptyFile = TRUE;
  8206. break;
  8207. }
  8208. else
  8209. {
  8210. isEmptyFile = FALSE;
  8211. break;
  8212. }
  8213. }
  8214. }
  8215. else
  8216. isEmptyFile = TRUE;
  8217. fclose(fptr1);
  8218. if(isEmptyFile == TRUE)
  8219. {
  8220. memset(str, 0, ARRAY_SIZE(str));
  8221. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8222. system(str);
  8223. }
  8224. }
  8225. }// End of while(int k=0; k < ChargePointCount; k++)
  8226. }
  8227. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8228. {
  8229. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8230. for(int k=0; k < ChargeProfileCount; k++)
  8231. {
  8232. fptr1 = fopen(chargingProfiles[k], "r");
  8233. fptr2 = fopen(temp, "w+");
  8234. //Check Charging Profile Count
  8235. while(fscanf(fptr1, "%s", word) != EOF)
  8236. {
  8237. //DEBUG_INFO("word=%s\n",word);
  8238. if(strstr(word, "chargingProfileId")!= NULL)
  8239. {
  8240. n_chargingProfile = n_chargingProfile + 1;
  8241. }
  8242. }
  8243. rewind(fptr1);
  8244. //search Charging Profile Element
  8245. //int i= 0;
  8246. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8247. {
  8248. json_object *tmpProfilee;
  8249. tmpProfilee = json_tokener_parse(sLineWord);
  8250. if(!is_error(tmpProfilee))
  8251. {
  8252. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8253. {
  8254. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8255. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8256. }
  8257. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8258. {
  8259. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8260. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8261. }
  8262. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8263. {
  8264. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8265. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8266. }
  8267. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8268. {
  8269. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8270. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8271. }
  8272. }
  8273. json_object_put(tmpProfilee);
  8274. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8275. {
  8276. //------- not write to fptr2-------//
  8277. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8278. //clearflag = TRUE;
  8279. }
  8280. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8281. {
  8282. //------- not write to fptr2-------//
  8283. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8284. }
  8285. else if(stackLevelIsNULL == TRUE)
  8286. {
  8287. //Clear Whole File
  8288. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8289. clearflag = TRUE;
  8290. break;
  8291. }
  8292. else
  8293. {
  8294. fprintf(fptr2, sLineWord);//writing data into file
  8295. }
  8296. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8297. }
  8298. if(clearflag == TRUE)
  8299. {
  8300. fclose(fptr1);
  8301. fclose(fptr2);
  8302. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8303. system(str);
  8304. // clear temp file
  8305. sprintf(str,"rm -f %s",temp);
  8306. system(str);
  8307. }
  8308. else
  8309. {
  8310. fclose(fptr1);
  8311. fclose(fptr2);
  8312. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8313. system(str);
  8314. resultRename = rename(temp, chargingProfiles[k]);
  8315. if(resultRename == 0)
  8316. {
  8317. DEBUG_INFO("File ChargingProfile renamed successfully");
  8318. }
  8319. else
  8320. {
  8321. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8322. }
  8323. if(comfirmstr[0]== 0)
  8324. {
  8325. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8326. }
  8327. //Check chargingProfile is empty file
  8328. /*------ Read the file ----------------*/
  8329. fptr1=fopen(chargingProfiles[k],"r");
  8330. ch=fgetc(fptr1);
  8331. rewind(fptr1);
  8332. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8333. if(ch!=EOF)
  8334. {
  8335. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8336. {
  8337. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8338. if(sLineWord[0]=='\0')
  8339. {
  8340. isEmptyFile = TRUE;
  8341. break;
  8342. }
  8343. else
  8344. {
  8345. isEmptyFile = FALSE;
  8346. break;
  8347. }
  8348. }
  8349. }
  8350. else
  8351. isEmptyFile = TRUE;
  8352. fclose(fptr1);
  8353. if(isEmptyFile == TRUE)
  8354. {
  8355. memset(str, 0, ARRAY_SIZE(str));
  8356. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8357. system(str);
  8358. }
  8359. /*------- End of reading ---------------*/
  8360. }
  8361. } // while(int k=0; k < ChargeProfileCount; k++)
  8362. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8363. end:
  8364. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8365. {
  8366. if(connectorIdInt == 0)
  8367. {
  8368. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8369. {
  8370. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8371. }
  8372. }
  8373. else
  8374. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8375. }
  8376. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8377. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8378. return result;
  8379. }
  8380. void createFirmwareVersionByDataTransfer(void)
  8381. {
  8382. json_object *FirmwareDataTransfer = json_object_new_object();
  8383. // AC & DC model
  8384. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8385. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8386. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8387. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8388. // DC model
  8389. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8390. {
  8391. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8392. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8393. (gunType[3] != GUN_TYPE_UNKNOWN))
  8394. {
  8395. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8396. }
  8397. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8398. {
  8399. // DS DM DW
  8400. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8401. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8402. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8403. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8404. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8405. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8406. }
  8407. else
  8408. {
  8409. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8410. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8411. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8412. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8413. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8414. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8415. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8416. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8417. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8418. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8419. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8420. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8421. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8422. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8423. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8424. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8425. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8426. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8427. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8428. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8429. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8430. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8431. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8432. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8433. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8434. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8435. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8436. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8437. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8438. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8439. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8440. }
  8441. }
  8442. // 4G model
  8443. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8444. {
  8445. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8446. }
  8447. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8448. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8449. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8450. json_object_put(FirmwareDataTransfer);
  8451. }
  8452. int handleDataTransferRequest(char *uuid, char *payload)
  8453. {
  8454. mtrace();
  8455. json_object *response = json_object_new_object();
  8456. int result = FAIL;
  8457. char tempvendorId[255]={0};
  8458. char tempmessageId[50]={0};
  8459. char tempdata[512]={0};
  8460. char message[2048]={0};
  8461. DEBUG_INFO("handleDataTransferRequest...\n");
  8462. if((uuid != NULL) && (payload != NULL))
  8463. {
  8464. json_object *DataTransfer;
  8465. DataTransfer = json_tokener_parse(payload);
  8466. if(!is_error(DataTransfer))
  8467. {
  8468. // Required data
  8469. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8470. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8471. // Optional data
  8472. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8473. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8474. if(json_object_object_get(DataTransfer, "data") != NULL)
  8475. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8476. result = PASS;
  8477. }
  8478. json_object_put(DataTransfer);
  8479. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8480. {
  8481. // Send all moudle firmware version on EVSE
  8482. createFirmwareVersionByDataTransfer();
  8483. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8484. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8485. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8486. json_object_put(response);
  8487. }
  8488. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8489. {
  8490. system("/usr/bin/run_tmate_restart.sh &");
  8491. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8492. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8493. json_object_put(response);
  8494. }
  8495. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8496. {
  8497. json_object *data;
  8498. data = json_tokener_parse(tempdata);
  8499. if(!is_error(data))
  8500. {
  8501. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8502. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8503. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8504. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8505. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8506. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8507. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8508. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8509. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8510. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8511. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8512. }
  8513. else
  8514. {
  8515. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8516. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8517. }
  8518. json_object_put(data);
  8519. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8520. json_object_put(response);
  8521. }
  8522. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8523. {
  8524. json_object *data;
  8525. data = json_tokener_parse(tempdata);
  8526. if(!is_error(data))
  8527. {
  8528. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8529. if(json_object_object_get(data, "idToken") != NULL)
  8530. {
  8531. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8532. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8533. }
  8534. if(json_object_object_get(data, "price") != NULL)
  8535. {
  8536. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8537. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8538. }
  8539. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8540. }
  8541. else
  8542. {
  8543. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8544. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8545. }
  8546. json_object_put(data);
  8547. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8548. json_object_put(response);
  8549. }
  8550. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8551. {
  8552. json_object *data;
  8553. data = json_tokener_parse(tempdata);
  8554. if(!is_error(data))
  8555. {
  8556. if(json_object_object_get(data, "txId") != NULL)
  8557. {
  8558. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8559. for(int idx = 0;idx<gunTotalNumber;idx++)
  8560. {
  8561. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8562. {
  8563. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8564. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8565. if(json_object_object_get(data, "description") != NULL)
  8566. {
  8567. // California pricing V1.0
  8568. DEBUG_INFO("California pricing V1.0\n");
  8569. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8570. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8571. }
  8572. else
  8573. {
  8574. // California pricing V1.1
  8575. DEBUG_INFO("California pricing V1.1\n");
  8576. if(json_object_object_get(data, "timestamp") != NULL)
  8577. {
  8578. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8579. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8580. }
  8581. if(json_object_object_get(data, "meterValue") != NULL)
  8582. {
  8583. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8584. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8585. }
  8586. if(json_object_object_get(data, "cost") != NULL)
  8587. {
  8588. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8589. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8590. }
  8591. if(json_object_object_get(data, "state") != NULL)
  8592. {
  8593. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8594. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8595. }
  8596. if(json_object_object_get(data, "chargingPrice") != NULL)
  8597. {
  8598. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8599. {
  8600. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8601. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8602. }
  8603. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8604. {
  8605. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8606. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8607. }
  8608. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8609. {
  8610. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8611. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8612. }
  8613. }
  8614. if(json_object_object_get(data, "idlePrice") != NULL)
  8615. {
  8616. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8617. {
  8618. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8619. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8620. }
  8621. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8622. {
  8623. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8624. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8625. }
  8626. }
  8627. if(json_object_object_get(data, "nextPeriod") != NULL)
  8628. {
  8629. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8630. {
  8631. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8632. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8633. }
  8634. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8635. {
  8636. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8637. {
  8638. 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")));
  8639. ShmOCPP16Data->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"));
  8640. }
  8641. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8642. {
  8643. 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")));
  8644. ShmOCPP16Data->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"));
  8645. }
  8646. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8647. {
  8648. 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")));
  8649. ShmOCPP16Data->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"));
  8650. }
  8651. }
  8652. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8653. {
  8654. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8655. {
  8656. 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")));
  8657. ShmOCPP16Data->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"));
  8658. }
  8659. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8660. {
  8661. 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")));
  8662. ShmOCPP16Data->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"));
  8663. }
  8664. }
  8665. }
  8666. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8667. {
  8668. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8669. {
  8670. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8671. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8672. }
  8673. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8674. {
  8675. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8676. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8677. }
  8678. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8679. {
  8680. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8681. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8682. }
  8683. }
  8684. }
  8685. }
  8686. }
  8687. }
  8688. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8689. }
  8690. else
  8691. {
  8692. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8693. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8694. }
  8695. json_object_put(data);
  8696. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8697. json_object_put(response);
  8698. }
  8699. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8700. {
  8701. json_object *data;
  8702. data = json_tokener_parse(tempdata);
  8703. if(!is_error(data))
  8704. {
  8705. if(json_object_object_get(data, "txId") != NULL)
  8706. {
  8707. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8708. for(int idx = 0;idx<gunTotalNumber;idx++)
  8709. {
  8710. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8711. {
  8712. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8713. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8714. if(json_object_object_get(data, "description") != NULL)
  8715. {
  8716. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8717. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8718. }
  8719. }
  8720. }
  8721. }
  8722. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8723. }
  8724. else
  8725. {
  8726. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8727. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8728. }
  8729. json_object_put(data);
  8730. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8731. json_object_put(response);
  8732. }
  8733. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8734. {
  8735. json_object *data;
  8736. data = json_tokener_parse(tempdata);
  8737. if(!is_error(data))
  8738. {
  8739. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8740. if(json_object_object_get(data, "Content_Type") != NULL)
  8741. {
  8742. 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))
  8743. {
  8744. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8745. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8746. {
  8747. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8748. }
  8749. }
  8750. else
  8751. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8752. }
  8753. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8754. }
  8755. else
  8756. {
  8757. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8758. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8759. }
  8760. json_object_put(data);
  8761. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8762. json_object_put(response);
  8763. }
  8764. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8765. {
  8766. json_object *data;
  8767. data = json_tokener_parse(tempdata);
  8768. if(!is_error(data))
  8769. {
  8770. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8771. if(json_object_object_get(data, "Page_Index") != NULL)
  8772. {
  8773. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8774. }
  8775. if(json_object_object_get(data, "Duration") != NULL)
  8776. {
  8777. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8778. }
  8779. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8780. }
  8781. else
  8782. {
  8783. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8784. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8785. }
  8786. json_object_put(data);
  8787. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8788. json_object_put(response);
  8789. }
  8790. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8791. {
  8792. json_object *data;
  8793. data = json_tokener_parse(tempdata);
  8794. if(!is_error(data))
  8795. {
  8796. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8797. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8798. {
  8799. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8800. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8801. else
  8802. {
  8803. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8804. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8805. }
  8806. }
  8807. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8808. {
  8809. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8810. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8811. else
  8812. {
  8813. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8814. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8815. }
  8816. }
  8817. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8818. {
  8819. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8820. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8821. else
  8822. {
  8823. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8824. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8825. }
  8826. }
  8827. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8828. {
  8829. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8830. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8831. else
  8832. {
  8833. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8834. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8835. }
  8836. }
  8837. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8838. {
  8839. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8840. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8841. else
  8842. {
  8843. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8844. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8845. }
  8846. }
  8847. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8848. {
  8849. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8850. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8851. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8852. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8853. else
  8854. {
  8855. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8856. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8857. }
  8858. }
  8859. if(json_object_object_get(data, "isAuthentication") != NULL)
  8860. {
  8861. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  8862. {
  8863. case 0:
  8864. case 1:
  8865. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  8866. break;
  8867. default:
  8868. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8869. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8870. break;
  8871. }
  8872. }
  8873. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8874. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8875. }
  8876. else
  8877. {
  8878. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8879. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8880. }
  8881. json_object_put(data);
  8882. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8883. json_object_put(response);
  8884. }
  8885. else
  8886. {
  8887. // Can not find valid message id
  8888. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8889. }
  8890. }
  8891. else
  8892. {
  8893. // Payload is null
  8894. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8895. }
  8896. LWS_Send(message);
  8897. return result;
  8898. }
  8899. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8900. {
  8901. mtrace();
  8902. int result = FAIL;
  8903. int connectorIdInt, durationInt;
  8904. char chargingRateUnitStr[4]={0};
  8905. char comfirmstr[20];
  8906. int confirmPeriods = 0;
  8907. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8908. json_object *GetCompositeSchedule;
  8909. GetCompositeSchedule = json_tokener_parse(payload);
  8910. if(!is_error(GetCompositeSchedule))
  8911. {
  8912. // Required data
  8913. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8914. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8915. else
  8916. connectorIdInt = -1;
  8917. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8918. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8919. else
  8920. durationInt = 86400;
  8921. // Optional data
  8922. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8923. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8924. }
  8925. json_object_put(GetCompositeSchedule);
  8926. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8927. if((connectorIdInt == 0) ||
  8928. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8929. {
  8930. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8931. struct StructChargingProfile tmpProfile[1];
  8932. if(strstr(chargingRateUnitStr, "W") != NULL)
  8933. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8934. else
  8935. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8936. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8937. {
  8938. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8939. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8940. }
  8941. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8942. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8943. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8944. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8945. {
  8946. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8947. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8948. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8949. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8950. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8951. {
  8952. confirmPeriods = idx;
  8953. break;
  8954. }
  8955. }
  8956. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8957. {
  8958. confirmPeriods += 1;
  8959. }
  8960. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8961. }
  8962. else
  8963. {
  8964. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8965. }
  8966. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8967. return result;
  8968. }
  8969. int handleGetConfigurationRequest(char *uuid, char *payload)
  8970. {
  8971. mtrace();
  8972. int result = FAIL;
  8973. int MaxKeySupported = 0;
  8974. int n_keys = 0;
  8975. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8976. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8977. json_object *GetConfiguration;
  8978. GetConfiguration = json_tokener_parse(payload);
  8979. if(!is_error(GetConfiguration))
  8980. {
  8981. // Optional data
  8982. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8983. {
  8984. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8985. {
  8986. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8987. n_keys = idx + 1;
  8988. }
  8989. }
  8990. }
  8991. json_object_put(GetConfiguration);
  8992. UnknownKeynum = 0;
  8993. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8994. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8995. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8996. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8997. if(n_keys != 0)
  8998. {
  8999. for(int i=0;i<n_keys;i++)
  9000. {
  9001. getKeyValue(requestKey[i]);
  9002. }
  9003. }
  9004. else
  9005. {
  9006. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9007. getKeyValue("");
  9008. }
  9009. processUnkownKey();
  9010. sendGetConfigurationConfirmation(uuid);
  9011. return result;
  9012. }
  9013. static char fnamePlusPath[100]={0};
  9014. static char fnamePWithNoPath[60]={0};
  9015. void checkUploadLog(void)
  9016. {
  9017. FILE *fp;
  9018. /* Open the command for reading. */
  9019. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9020. if (fp == NULL) {
  9021. DEBUG_WARN("Failed to run command\n" );
  9022. exit(1);
  9023. }
  9024. int ftppathlen = 0;
  9025. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9026. int i = 0;
  9027. /* Read the output a line at a time - output it. */
  9028. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9029. if(i==0)
  9030. {
  9031. ftppathlen = strlen(fnamePlusPath);
  9032. DEBUG_INFO("%s\n", fnamePlusPath);
  9033. fnamePlusPath[ftppathlen]='\0';
  9034. break;
  9035. }
  9036. i= i+1;
  9037. }
  9038. /* close */
  9039. pclose(fp);
  9040. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9041. {
  9042. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9043. {
  9044. fnamePlusPath[k]='\0';
  9045. }
  9046. }
  9047. i=1;
  9048. //char fname[60]={0};
  9049. while(i < ftppathlen)
  9050. {
  9051. int len=ftppathlen-i;
  9052. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9053. {
  9054. DEBUG_INFO("compare '/' all right\n");
  9055. break;
  9056. }
  9057. i=i+1;
  9058. }
  9059. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9060. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9061. fnamePWithNoPath[i+1] = '\0';
  9062. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9063. {
  9064. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9065. {
  9066. fnamePWithNoPath[j]='\0';
  9067. }
  9068. }
  9069. FILE* fp1 = fopen(fnamePlusPath, "r");
  9070. if (fp1)
  9071. {
  9072. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9073. // file exists
  9074. fclose(fp1);
  9075. }
  9076. else
  9077. {
  9078. // file doesn't exist
  9079. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9080. }
  9081. }
  9082. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9083. {
  9084. mtrace();
  9085. int result = FAIL;
  9086. time_t CurrentTime;
  9087. struct tm *tm;
  9088. pthread_t th_Status;
  9089. CurrentTime = time(NULL);
  9090. tm = localtime(&CurrentTime);
  9091. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9092. sprintf((char*)ShmOCPP16Data->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);
  9093. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9094. if(!interLock.isGetDiagnosticGoing)
  9095. {
  9096. interLock.isGetDiagnosticGoing = 1;
  9097. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9098. sleep(1);
  9099. }
  9100. else
  9101. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9102. return result;
  9103. }
  9104. void* GetDiagnosticsProcess(void* data)
  9105. {
  9106. pthread_detach(pthread_self());
  9107. mtrace();
  9108. int retriesInt=0, retryIntervalInt=0;
  9109. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9110. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  9111. int port=0;
  9112. int isSuccess = FALSE;
  9113. char cmdBuf[2048];
  9114. struct tm *tmNow;
  9115. time_t CurrentTime;
  9116. struct tm tmStart;
  9117. struct tm tmStop;
  9118. CurrentTime = time(NULL);
  9119. tmNow=localtime(&CurrentTime);
  9120. uint16_t targetYear, targetMonth;
  9121. json_object *GetDiagnostics;
  9122. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9123. GetDiagnostics = json_tokener_parse(data);
  9124. if(!is_error(GetDiagnostics))
  9125. {
  9126. // Required data
  9127. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9128. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9129. // Optional data
  9130. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9131. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9132. else
  9133. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9134. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9135. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9136. else
  9137. retryIntervalInt = 30;
  9138. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9139. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9140. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9141. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9142. }
  9143. json_object_put(GetDiagnostics);
  9144. // Pack log to compress file
  9145. 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) &&
  9146. (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))
  9147. {
  9148. // Pack system log
  9149. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9150. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9151. targetYear = tmStart.tm_year;
  9152. targetMonth = tmStart.tm_mon;
  9153. do
  9154. {
  9155. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9156. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  9157. if(targetMonth+1>=13)
  9158. {
  9159. targetYear += 1;
  9160. targetMonth = 1;
  9161. }
  9162. else
  9163. {
  9164. targetMonth += 1;
  9165. }
  9166. }while((targetYear < (tmNow->tm_year+1900)) ||
  9167. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9168. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9169. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9170. system(cmdBuf);
  9171. // Pack charging & event log
  9172. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9173. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9174. targetYear = tmStart.tm_year;
  9175. targetMonth = tmStart.tm_mon;
  9176. do
  9177. {
  9178. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9179. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  9180. if(targetMonth+1>=13)
  9181. {
  9182. targetYear += 1;
  9183. targetMonth = 1;
  9184. }
  9185. else
  9186. {
  9187. targetMonth += 1;
  9188. }
  9189. }while((targetYear < (tmNow->tm_year+1900)) ||
  9190. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9191. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9192. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9193. system(cmdBuf);
  9194. // Combine log file
  9195. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9196. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9197. }
  9198. else
  9199. {
  9200. system("exec /root/logPackTools 'log' 6");
  9201. }
  9202. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9203. system(cmdBuf);
  9204. checkUploadLog();
  9205. //****************location*******************/
  9206. if(strcmp(locationstr,"")==0)
  9207. {
  9208. DEBUG_INFO("location is <Empty>!\n");
  9209. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9210. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9211. goto end;
  9212. }
  9213. memset(protocol, 0, ARRAY_SIZE(protocol));
  9214. memset(user, 0, ARRAY_SIZE(user) );
  9215. memset(password, 0, ARRAY_SIZE(password));
  9216. memset(host, 0, ARRAY_SIZE(host));
  9217. memset(path, 0, ARRAY_SIZE(path));
  9218. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9219. memset(host1, 0, ARRAY_SIZE(host1));
  9220. memset(path1, 0, ARRAY_SIZE(path1));
  9221. /*location: ftp://user:password@host:port/path*/
  9222. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9223. if((access(fnamePlusPath,F_OK))!=-1)
  9224. {
  9225. DEBUG_INFO("fnamePlusPath exist.\n");
  9226. }
  9227. else
  9228. {
  9229. DEBUG_INFO("fnamePlusPath not exist!\n");
  9230. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9231. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9232. goto end;
  9233. }
  9234. if(strchr(locationstr,'@')==NULL)
  9235. {
  9236. sscanf(locationstr,
  9237. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9238. protocol, host, &port, path);
  9239. strcpy(user,"anonymous");
  9240. strcpy(password,"");
  9241. }
  9242. else
  9243. {
  9244. //DEBUG_INFO("pch=%s\n", pch);
  9245. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9246. protocol, user, password, host, &port, path);
  9247. }
  9248. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9249. {
  9250. DEBUG_INFO("protocol is not ftp/http ! \n");
  9251. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9252. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9253. goto end;
  9254. }
  9255. if(strncmp(locationstr,"http", 4) == 0)
  9256. {
  9257. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9258. sprintf(ftppath,"/%s", path);
  9259. do
  9260. {
  9261. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9262. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9263. sleep(3);
  9264. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9265. if(!isSuccess)
  9266. {
  9267. DEBUG_INFO("Diagnostics fail.\n");
  9268. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9269. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9270. sleep(retryIntervalInt);
  9271. }
  9272. else
  9273. {
  9274. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9275. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9276. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9277. }
  9278. retriesInt--;
  9279. }while((isSuccess == 0)&&(retriesInt >= 0));
  9280. }
  9281. else
  9282. {
  9283. sscanf(host,"%[^/]%s",host1, path1);
  9284. if(strlen(path) > 0)
  9285. sprintf(ftppath,"/%s", path);
  9286. else
  9287. sprintf(ftppath,"/%s", path1);
  9288. int ftppathlen=strlen(ftppath);
  9289. int i=1;
  9290. char filenametemp[50];
  9291. while(i < ftppathlen)
  9292. {
  9293. int len=ftppathlen-i;
  9294. if(ftppath[len]== 47) // '/' ascll code: 47
  9295. {
  9296. DEBUG_INFO("find '/' all right\n");
  9297. break;
  9298. }
  9299. i=i+1;
  9300. }
  9301. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9302. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9303. filenametemp[i+1] = 0;
  9304. if(port == 0)
  9305. port = 21;
  9306. do
  9307. {
  9308. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9309. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9310. sleep(3);
  9311. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9312. if(!isSuccess)
  9313. {
  9314. DEBUG_INFO("Diagnostics fail.\n");
  9315. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9316. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9317. sleep(retryIntervalInt);
  9318. }
  9319. else
  9320. {
  9321. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9322. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9323. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9324. }
  9325. retriesInt--;
  9326. }while((!isSuccess)&&(retriesInt >= 0));
  9327. }
  9328. end:
  9329. system("rm -f /mnt/*");
  9330. sleep(5);
  9331. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9332. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9333. interLock.isGetDiagnosticGoing = 0;
  9334. pthread_exit(NULL);
  9335. }
  9336. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9337. {
  9338. mtrace();
  9339. int result = FAIL;
  9340. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9341. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9342. {
  9343. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9344. locallistVersion = -1;
  9345. }
  9346. else
  9347. {
  9348. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9349. OCPP_getListVerion();
  9350. }
  9351. //from db.OCPP_getListVerion
  9352. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9353. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9354. sendGetLocalListVersionConfirmation(uuid,"");
  9355. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9356. return result;
  9357. }
  9358. int handleRemoteStartRequest(char *uuid, char *payload)
  9359. {
  9360. mtrace();
  9361. int result = FAIL;
  9362. int connectorIdInt=-1;
  9363. int tempIndex = 0;
  9364. int connectorIdIsNULL, chargingProfileIsNULL;
  9365. char comfirmstr[20]={0};
  9366. char cmdBuf[512];
  9367. json_object *RemoteStartTransaction;
  9368. FILE *fp;
  9369. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9370. if(server_pending == TRUE)
  9371. {
  9372. return 0;
  9373. }
  9374. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9375. RemoteStartTransaction = json_tokener_parse(payload);
  9376. if(!is_error(RemoteStartTransaction))
  9377. {
  9378. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9379. {
  9380. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9381. }
  9382. else
  9383. {
  9384. connectorIdIsNULL = TRUE;
  9385. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9386. {
  9387. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9388. {
  9389. connectorIdIsNULL = FALSE;
  9390. connectorIdInt = (gun_index+1);
  9391. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9392. break;
  9393. }
  9394. }
  9395. }
  9396. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9397. {
  9398. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9399. // Required data
  9400. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9401. // Optional data
  9402. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9403. {
  9404. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9405. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9406. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9407. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9408. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9409. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9410. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9411. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9412. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9413. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9414. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9415. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9416. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9417. {
  9418. sprintf((char*)ShmOCPP16Data->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")));
  9419. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9420. ShmOCPP16Data->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"));
  9421. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9422. ShmOCPP16Data->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"));
  9423. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9424. sprintf((char*)ShmOCPP16Data->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")));
  9425. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9426. {
  9427. 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++)
  9428. {
  9429. ShmOCPP16Data->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"));
  9430. ShmOCPP16Data->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"));
  9431. 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)
  9432. ShmOCPP16Data->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"));
  9433. }
  9434. }
  9435. }
  9436. }
  9437. else
  9438. {
  9439. chargingProfileIsNULL = TRUE;
  9440. }
  9441. }
  9442. }
  9443. else
  9444. {
  9445. connectorIdIsNULL = TRUE;
  9446. }
  9447. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9448. {
  9449. DEBUG_WARN("Connector id is NULL\n.");
  9450. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9451. goto end;
  9452. }
  9453. /*
  9454. enum _SYSTEM_STATUS
  9455. {
  9456. S_BOOTING = 0,
  9457. S_IDLE, = 1
  9458. S_AUTHORIZING, = 2
  9459. S_REASSIGN_CHECK, = 3
  9460. S_REASSIGN, = 4
  9461. S_PRECHARGE, = 5
  9462. S_PREPARING_FOR_EV, = 6
  9463. S_PREPARING_FOR_EVSE, = 7
  9464. S_CHARGING, = 8
  9465. S_TERMINATING, = 9
  9466. S_COMPLETE, = 10
  9467. S_ALARM, = 11
  9468. S_FAULT = 12
  9469. }
  9470. */
  9471. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9472. {
  9473. //check Transaction active
  9474. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9475. {
  9476. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9477. {
  9478. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9479. }
  9480. else
  9481. {
  9482. tempIndex = connectorIdInt -1;
  9483. }
  9484. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9485. {
  9486. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9487. {
  9488. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9489. {
  9490. //Reserved
  9491. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9492. }
  9493. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9494. {
  9495. //Reserved
  9496. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9498. goto end;
  9499. }
  9500. else
  9501. {
  9502. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9503. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9504. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9505. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9506. {
  9507. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9508. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9509. goto end;
  9510. }
  9511. }//END FOR ELSE
  9512. }
  9513. }// END FOR CHAdeMO_QUANTITY
  9514. }
  9515. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9516. {
  9517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9518. {
  9519. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9520. }
  9521. else
  9522. {
  9523. tempIndex = connectorIdInt -1;
  9524. }
  9525. for (int index = 0; index < CCS_QUANTITY; index++)
  9526. {
  9527. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9528. {
  9529. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9530. {
  9531. //Reserved
  9532. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9533. }
  9534. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9535. {
  9536. //Reserved
  9537. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9538. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9539. goto end;
  9540. }
  9541. else
  9542. {
  9543. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9544. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9545. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9546. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9547. {
  9548. DEBUG_WARN("CCS connector not allow start\n.");
  9549. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9550. goto end;
  9551. }
  9552. }// END FOR ELSE
  9553. }
  9554. }// END FOR CCS_QUANTITY
  9555. }
  9556. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9557. {
  9558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9559. {
  9560. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9561. }
  9562. else
  9563. {
  9564. tempIndex = connectorIdInt -1;
  9565. }
  9566. for (int index = 0; index < GB_QUANTITY; index++)
  9567. {
  9568. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9569. {
  9570. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9571. {
  9572. //Reserved
  9573. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9574. }
  9575. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9576. {
  9577. //Reserved
  9578. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9579. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9580. goto end;
  9581. }
  9582. else
  9583. {
  9584. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9585. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9586. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9587. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9588. {
  9589. DEBUG_WARN("GB connector not allow start\n.");
  9590. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9591. goto end;
  9592. }
  9593. }// END FOR ELSE
  9594. }
  9595. } // END FOR GB_QUANTITY
  9596. }
  9597. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9598. {
  9599. tempIndex = connectorIdInt -1;
  9600. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9601. {
  9602. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9603. {
  9604. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9605. {
  9606. //Reserved
  9607. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9608. }
  9609. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9610. {
  9611. //Reserved
  9612. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9613. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9614. goto end;
  9615. }
  9616. else
  9617. {
  9618. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9619. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9620. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9621. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9622. {
  9623. DEBUG_WARN("GB connector not allow start\n.");
  9624. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9625. goto end;
  9626. }
  9627. }// END FOR ELSE
  9628. }
  9629. } // END FOR GB_QUANTITY
  9630. }
  9631. else
  9632. {
  9633. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9634. {
  9635. tempIndex = 2;
  9636. }
  9637. else
  9638. {
  9639. tempIndex = connectorIdInt -1;
  9640. }
  9641. for (int index = 0; index < AC_QUANTITY; index++)
  9642. {
  9643. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9644. {
  9645. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9646. {
  9647. //Reserved
  9648. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9649. }
  9650. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9651. {
  9652. //Reserved
  9653. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9654. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9655. goto end;
  9656. }
  9657. else
  9658. {
  9659. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9660. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9661. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9662. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9663. {
  9664. DEBUG_WARN("AC connector not allow start\n.");
  9665. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9666. goto end;
  9667. }
  9668. }//END FOR ELSE
  9669. }
  9670. }// END FOR AC_QUANTITY
  9671. }
  9672. if(chargingProfileIsNULL == FALSE)
  9673. {
  9674. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9675. {
  9676. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9677. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9678. //memset idTag
  9679. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9680. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9681. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9682. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9683. // Save profile to file
  9684. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9685. system(cmdBuf);
  9686. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9687. fp = fopen(cmdBuf, "w");
  9688. 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));
  9689. fclose(fp);
  9690. }
  9691. else
  9692. {
  9693. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9694. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9695. }
  9696. }
  9697. else
  9698. {
  9699. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9700. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9701. //memset idTag
  9702. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9703. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9704. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9705. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9706. }
  9707. }
  9708. else
  9709. {
  9710. DEBUG_WARN("Connector id over\n.");
  9711. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9712. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9713. }
  9714. end:
  9715. json_object_put(RemoteStartTransaction);
  9716. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9717. {
  9718. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9719. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9720. }
  9721. //OCPP send RemoteStartConfirmation by first.
  9722. sendRemoteStartConfirmation(uuid, comfirmstr);
  9723. return result;
  9724. }
  9725. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9726. {
  9727. mtrace();
  9728. int result = FAIL;
  9729. int match = FALSE;
  9730. int GunNO = 0;
  9731. int tempIndex = 0;
  9732. int transactionIdInt=0;
  9733. int transactionIdIsNULL= TRUE;
  9734. char comfirmstr[20];
  9735. json_object *RemoteStopTransaction;
  9736. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9737. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9738. if(server_pending == TRUE)
  9739. {
  9740. return 0;
  9741. }
  9742. RemoteStopTransaction = json_tokener_parse(payload);
  9743. if(!is_error(RemoteStopTransaction))
  9744. {
  9745. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9746. {
  9747. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9748. transactionIdIsNULL = FALSE;
  9749. }
  9750. }
  9751. json_object_put(RemoteStopTransaction);
  9752. if(transactionIdIsNULL == FALSE)
  9753. {
  9754. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9755. {
  9756. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9757. {
  9758. //check Transaction active
  9759. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9760. {
  9761. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9762. {
  9763. tempIndex = ((gun_index==2) ? 1: 0);
  9764. }
  9765. else
  9766. {
  9767. tempIndex = gun_index;
  9768. }
  9769. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9770. {
  9771. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9772. {
  9773. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9774. {
  9775. match = TRUE;
  9776. GunNO = gun_index;
  9777. }
  9778. }
  9779. }// END FOR CHAdeMO_QUANTITY
  9780. }
  9781. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9782. {
  9783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9784. {
  9785. tempIndex = ((gun_index==2) ? 1: 0);
  9786. }
  9787. else
  9788. {
  9789. tempIndex = gun_index;
  9790. }
  9791. for (int index = 0; index < CCS_QUANTITY; index++)
  9792. {
  9793. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9794. {
  9795. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9796. {
  9797. match = TRUE;
  9798. GunNO = gun_index;
  9799. }
  9800. }
  9801. }// END FOR CCS_QUANTITY
  9802. }
  9803. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9804. {
  9805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9806. {
  9807. tempIndex = ((gun_index==2) ? 1: 0);
  9808. }
  9809. else
  9810. {
  9811. tempIndex = gun_index;
  9812. }
  9813. for (int index = 0; index < GB_QUANTITY; index++)
  9814. {
  9815. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9816. {
  9817. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9818. {
  9819. match = TRUE;
  9820. GunNO = gun_index;
  9821. }
  9822. }
  9823. }// END FOR GB_QUANTITY
  9824. }
  9825. else if(gunType[gun_index] == GUN_TYPE_DO)
  9826. {
  9827. tempIndex = gun_index;
  9828. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9829. {
  9830. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9831. {
  9832. 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
  9833. {
  9834. match = TRUE;
  9835. GunNO = gun_index;
  9836. }
  9837. }
  9838. }// END FOR GB_QUANTITY
  9839. }
  9840. else
  9841. {
  9842. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9843. {
  9844. tempIndex = 2;
  9845. }
  9846. else
  9847. {
  9848. tempIndex = gun_index;
  9849. }
  9850. for (int index = 0; index < AC_QUANTITY; index++)
  9851. {
  9852. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9853. {
  9854. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9855. {
  9856. match = TRUE;
  9857. GunNO = gun_index;
  9858. }
  9859. }
  9860. }// END FOR CHAdeMO_QUANTITY
  9861. } // END FOR AC ELSE
  9862. }// CHECK IF ResponseTransactionId == transactionIdInt
  9863. }//END FOR
  9864. if( match == TRUE)
  9865. {
  9866. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9867. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9868. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9869. }
  9870. else
  9871. {
  9872. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9873. }
  9874. }
  9875. else
  9876. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9877. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9878. return result;
  9879. }
  9880. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9881. {
  9882. mtrace();
  9883. int result = FAIL;
  9884. int connectorIdInt=0, reservationIdInt=0;
  9885. int tempIndex = 0;
  9886. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9887. char comfirmstr[20]={0};
  9888. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9889. int c = 0;
  9890. char *loc;
  9891. //char *ptr;
  9892. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9893. strcpy(sstrtemp, stringtrimspace(payload));
  9894. //***(1)connectorId ****/
  9895. c=0;
  9896. loc = strstr(sstrtemp, "connectorId");
  9897. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9898. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9899. {
  9900. sstr[c] = loc[strlen("connectorId")+2+c];
  9901. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9902. c++;
  9903. }
  9904. sstr[c] = '\0';
  9905. connectorIdInt = atoi(sstr);
  9906. //***(2)expiryDate ****/
  9907. loc = strstr(sstrtemp, "expiryDate");
  9908. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9909. c = 0;
  9910. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9911. {
  9912. sstr[c] = loc[3+strlen("expiryDate")+c];
  9913. c++;
  9914. }
  9915. sstr[c] = '\0';
  9916. strcpy(expiryDatestr, sstr);
  9917. //***(3)idTag ****/
  9918. loc = strstr(sstrtemp, "idTag");
  9919. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9920. c = 0;
  9921. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9922. {
  9923. sstr[c] = loc[3+strlen("idTag")+c];
  9924. c++;
  9925. }
  9926. sstr[c] = '\0';
  9927. strcpy(idTagstr, sstr);
  9928. //***(4)parentIdTag ****/
  9929. loc = strstr(sstrtemp, "parentIdTag");
  9930. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9931. c = 0;
  9932. if(loc == NULL)
  9933. {
  9934. strcpy(parentIdTagstr, "");
  9935. }
  9936. else
  9937. {
  9938. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9939. {
  9940. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9941. c++;
  9942. }
  9943. sstr[c] = '\0';
  9944. strcpy(parentIdTagstr, sstr);
  9945. }
  9946. //***(5)reservationId ****/
  9947. c=0;
  9948. loc = strstr(sstrtemp, "reservationId");
  9949. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9950. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9951. {
  9952. sstr[c] = loc[strlen("reservationId")+2+c];
  9953. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9954. c++;
  9955. }
  9956. sstr[c] = '\0';
  9957. reservationIdInt = atoi(sstr);
  9958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9959. /*
  9960. enum SYSTEM_STATUS
  9961. {
  9962. SYS_MODE_BOOTING = 0,
  9963. SYS_MODE_IDLE = 1,
  9964. SYS_MODE_AUTHORIZING = 2,
  9965. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9966. SYS_MODE_REASSIGN = 4,
  9967. SYS_MODE_PREPARING = 5,
  9968. SYS_MODE_PREPARE_FOR_EV = 6,
  9969. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9970. SYS_MODE_CHARGING = 8,
  9971. SYS_MODE_TERMINATING = 9,
  9972. SYS_MODE_COMPLETE = 10,
  9973. SYS_MODE_ALARM = 11,
  9974. SYS_MODE_FAULT = 12,
  9975. SYS_MODE_RESERVATION = 13,
  9976. SYS_MODE_BOOKING = 14,
  9977. SYS_MODE_MAINTAIN = 15,
  9978. SYS_MODE_DEBUG = 16,
  9979. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9980. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9981. SYS_MODE_UPDATE = 19
  9982. };
  9983. */
  9984. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9985. {
  9986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9987. goto end;
  9988. }
  9989. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9990. {
  9991. //check Transaction active
  9992. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9993. {
  9994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9995. {
  9996. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9997. }
  9998. else
  9999. {
  10000. tempIndex = connectorIdInt -1;
  10001. }
  10002. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10003. {
  10004. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10005. {
  10006. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10007. {
  10008. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10009. {
  10010. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10011. {
  10012. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10014. }
  10015. 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'))
  10016. {
  10017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10018. }
  10019. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10020. {
  10021. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10022. }
  10023. else
  10024. {
  10025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10026. }
  10027. }
  10028. 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
  10029. {
  10030. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10031. }
  10032. }
  10033. else
  10034. {
  10035. //replace reservation
  10036. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10037. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10038. }
  10039. }
  10040. } // END FOR CHAdeMO_QUANTITY
  10041. }
  10042. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10043. {
  10044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10045. {
  10046. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10047. }
  10048. else
  10049. {
  10050. tempIndex = connectorIdInt -1;
  10051. }
  10052. for (int index = 0; index < CCS_QUANTITY; index++)
  10053. {
  10054. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10055. {
  10056. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10057. {
  10058. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10059. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10060. {
  10061. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10062. {
  10063. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10065. }
  10066. 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'))
  10067. {
  10068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10069. }
  10070. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10071. {
  10072. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10073. }
  10074. else
  10075. {
  10076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10077. }
  10078. }
  10079. 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
  10080. {
  10081. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10082. }
  10083. }
  10084. else
  10085. {
  10086. //replace reservation
  10087. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10088. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10089. }
  10090. }
  10091. } // END FOR CCS_QUANTITY
  10092. }
  10093. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10094. {
  10095. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10096. {
  10097. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10098. }
  10099. else
  10100. {
  10101. tempIndex = connectorIdInt -1;
  10102. }
  10103. for (int index = 0; index < GB_QUANTITY; index++)
  10104. {
  10105. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10106. {
  10107. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10108. {
  10109. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10110. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10111. {
  10112. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10113. {
  10114. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10116. }
  10117. 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'))
  10118. {
  10119. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10120. }
  10121. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10122. {
  10123. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10124. }
  10125. else
  10126. {
  10127. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10128. }
  10129. }
  10130. 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
  10131. {
  10132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10133. }
  10134. }
  10135. else
  10136. {
  10137. //replace reservation
  10138. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10139. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10140. }
  10141. }
  10142. }// END FOR GB_QUANTITY
  10143. }
  10144. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10145. {
  10146. tempIndex = connectorIdInt -1;
  10147. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10148. {
  10149. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10150. {
  10151. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10152. {
  10153. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10154. 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
  10155. {
  10156. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10157. {
  10158. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10159. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10160. }
  10161. 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'))
  10162. {
  10163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10164. }
  10165. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10166. {
  10167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10168. }
  10169. else
  10170. {
  10171. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10172. }
  10173. }
  10174. 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
  10175. {
  10176. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10177. }
  10178. }
  10179. else
  10180. {
  10181. //replace reservation
  10182. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10183. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10184. }
  10185. }
  10186. }// END FOR GB_QUANTITY
  10187. }
  10188. else
  10189. {
  10190. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10191. {
  10192. tempIndex = 2;
  10193. }
  10194. else
  10195. {
  10196. tempIndex = (connectorIdInt -1);
  10197. }
  10198. for (int index = 0; index < AC_QUANTITY; index++)
  10199. {
  10200. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10201. {
  10202. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10203. {
  10204. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10205. {
  10206. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10207. {
  10208. 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))
  10209. {
  10210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10211. }
  10212. else
  10213. {
  10214. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10216. }
  10217. }
  10218. 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'))
  10219. {
  10220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10221. }
  10222. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10223. {
  10224. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10225. }
  10226. else
  10227. {
  10228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10229. }
  10230. }
  10231. 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
  10232. {
  10233. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10234. }
  10235. }
  10236. else
  10237. {
  10238. //replace reservation
  10239. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10240. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10241. }
  10242. }
  10243. } // END FOR AC_QUANTITY
  10244. }
  10245. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10246. }
  10247. else if(connectorIdInt == 0)
  10248. {
  10249. //check Transaction active
  10250. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10251. {
  10252. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10253. {
  10254. 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'))
  10255. {
  10256. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10257. goto end;
  10258. }
  10259. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10260. {
  10261. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10262. goto end;
  10263. }
  10264. 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
  10265. {
  10266. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10267. goto end;
  10268. }
  10269. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10270. {
  10271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10272. goto end;
  10273. }
  10274. }
  10275. }// END FOR CHAdeMO_QUANTITY
  10276. for (int index = 0; index < CCS_QUANTITY; index++)
  10277. {
  10278. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10279. {
  10280. 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'))
  10281. {
  10282. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10283. goto end;
  10284. }
  10285. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10286. {
  10287. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10288. goto end;
  10289. }
  10290. 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
  10291. {
  10292. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10293. goto end;
  10294. }
  10295. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10296. {
  10297. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10298. goto end;
  10299. }
  10300. }
  10301. } // END FOR CCS_QUANTITY
  10302. for (int index = 0; index < GB_QUANTITY; index++)
  10303. {
  10304. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10305. {
  10306. 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'))
  10307. {
  10308. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10309. goto end;
  10310. }
  10311. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10312. {
  10313. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10314. goto end;
  10315. }
  10316. 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
  10317. {
  10318. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10319. goto end;
  10320. }
  10321. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10322. {
  10323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10324. goto end;
  10325. }
  10326. }
  10327. } // END FOR GB_QUANTITY
  10328. for (int index = 0; index < AC_QUANTITY; index++)
  10329. {
  10330. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10331. {
  10332. 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'))
  10333. {
  10334. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10335. goto end;
  10336. }
  10337. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10338. {
  10339. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10340. goto end;
  10341. }
  10342. 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
  10343. {
  10344. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10345. goto end;
  10346. }
  10347. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10348. {
  10349. 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))
  10350. {
  10351. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10352. goto end;
  10353. }
  10354. }
  10355. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10356. {
  10357. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10358. goto end;
  10359. }
  10360. }
  10361. }// END FOR AC_QUANTITY
  10362. //The connectorId is 0
  10363. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10364. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10365. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10366. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10367. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10368. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10369. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10370. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10371. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10372. result = TRUE;
  10373. return result;
  10374. }
  10375. else
  10376. {
  10377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10378. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10379. }
  10380. if(strcmp(comfirmstr,"Accepted") == 0)
  10381. {
  10382. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10383. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10384. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10385. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10386. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10387. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10388. result = TRUE;
  10389. return result;
  10390. }
  10391. end:
  10392. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10393. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10394. return result;
  10395. }
  10396. int handleResetRequest(char *uuid, char *payload)
  10397. {
  10398. mtrace();
  10399. int result = FAIL;
  10400. char sstr[10]={0},sstrtemp[30]={ 0 };
  10401. char typestr[10]={0};
  10402. char comfirmstr[20]={0};
  10403. int c = 0;
  10404. char *loc;
  10405. DEBUG_INFO("handleResetRequest...\n");
  10406. strcpy(sstrtemp, stringtrimspace(payload));
  10407. loc = strstr(sstrtemp, "type");
  10408. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10409. c = 0;
  10410. while (loc[3+strlen("type")+c] != '\"')
  10411. {
  10412. sstr[c] = loc[3+strlen("type")+c];
  10413. c++;
  10414. }
  10415. sstr[c] = '\0';
  10416. strcpy(typestr,sstr);
  10417. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10418. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10419. {
  10420. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10421. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10422. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10423. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10424. }
  10425. else
  10426. {
  10427. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10428. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10429. result = PASS;
  10430. }
  10431. sendResetConfirmation(uuid, comfirmstr);
  10432. return result;
  10433. }
  10434. int handleSendLocalListRequest(char *uuid, char *payload)
  10435. {
  10436. mtrace();
  10437. int result = FAIL;
  10438. char comfirmstr[20];
  10439. int checkState_Faulted = FALSE;
  10440. json_object *SendLocalList;
  10441. DEBUG_INFO("handleSendLocalListRequest...\n");
  10442. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10443. {
  10444. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10445. goto end;
  10446. }
  10447. //check Charge Point state
  10448. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10449. {
  10450. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10451. {
  10452. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10453. }
  10454. }
  10455. for (int index = 0; index < CCS_QUANTITY; index++)
  10456. {
  10457. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10458. {
  10459. checkState_Faulted = TRUE; //OCPP Status
  10460. }
  10461. }
  10462. for (int index = 0; index < GB_QUANTITY; index++)
  10463. {
  10464. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10465. {
  10466. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10467. }
  10468. }
  10469. //check Charge Point state
  10470. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10471. {
  10472. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10473. {
  10474. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10475. }
  10476. }
  10477. //check Charge Point state
  10478. for (int index = 0; index < AC_QUANTITY; index++)
  10479. {
  10480. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10481. {
  10482. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10483. }
  10484. }
  10485. if(checkState_Faulted == TRUE)
  10486. {
  10487. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10488. goto end;
  10489. }
  10490. // Parsing payload
  10491. SendLocalList = json_tokener_parse(payload);
  10492. if(!is_error(SendLocalList))
  10493. {
  10494. // Required data
  10495. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10496. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10497. // Optional data
  10498. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10499. {
  10500. //Check UpdateType
  10501. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10502. {
  10503. //Local list full update
  10504. DEBUG_INFO("Local list full update.\n");
  10505. OCPP_getListVerion();
  10506. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10507. {
  10508. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10509. goto end;
  10510. }
  10511. OCPP_cleanLocalList();
  10512. }
  10513. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10514. {
  10515. //Local list different update
  10516. DEBUG_INFO("Local list different update.\n");
  10517. OCPP_getListVerion();
  10518. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10519. {
  10520. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10521. goto end;
  10522. }
  10523. }
  10524. else
  10525. {
  10526. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10527. goto end;
  10528. }
  10529. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10530. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10531. {
  10532. sprintf((char*)ShmOCPP16Data->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")));
  10533. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10534. {
  10535. sprintf((char*)ShmOCPP16Data->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")));
  10536. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10537. sprintf((char*)ShmOCPP16Data->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")));
  10538. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10539. sprintf((char*)ShmOCPP16Data->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")));
  10540. }
  10541. // Add to db
  10542. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10543. {
  10544. //Local list full update
  10545. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10546. idx,
  10547. ShmOCPP16Data->SendLocalList.ListVersion,
  10548. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10549. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10550. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10551. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10552. // update list
  10553. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10554. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10555. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10556. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10557. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10558. }
  10559. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10560. {
  10561. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10562. idx,
  10563. ShmOCPP16Data->SendLocalList.ListVersion,
  10564. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10565. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10566. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10567. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10568. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10569. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10570. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10571. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10572. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10573. }
  10574. }
  10575. }
  10576. else
  10577. {
  10578. //Check UpdateType
  10579. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10580. {
  10581. //Local list full update
  10582. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10583. OCPP_cleanLocalList();
  10584. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10585. goto end;
  10586. }
  10587. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10588. {
  10589. //Local list different update
  10590. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10591. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10592. goto end;
  10593. }
  10594. }
  10595. result = PASS;
  10596. }
  10597. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10598. end:
  10599. json_object_put(SendLocalList);
  10600. sendSendLocalListConfirmation(uuid, comfirmstr);
  10601. return result;
  10602. }
  10603. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10604. {
  10605. mtrace();
  10606. int result = FAIL;
  10607. struct StructSetChargingProfile SetProfileReq = {0};
  10608. int tempchargingProfileIdInt;
  10609. int chargingSchedulePeriodCount = 0;
  10610. char comfirmstr[20]={0};
  10611. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10612. char rmFileCmd[128]={0};
  10613. int profileQuantity = 0;
  10614. json_object *SetChargingProfile;
  10615. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10616. SetChargingProfile = json_tokener_parse(payload);
  10617. if(!is_error(SetChargingProfile))
  10618. {
  10619. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10620. {
  10621. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10622. }
  10623. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10624. {
  10625. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10626. {
  10627. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10628. }
  10629. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10630. {
  10631. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10632. }
  10633. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10634. {
  10635. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10636. }
  10637. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10638. {
  10639. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10640. }
  10641. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10642. {
  10643. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10644. }
  10645. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10646. {
  10647. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10648. }
  10649. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10650. {
  10651. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10652. }
  10653. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10654. {
  10655. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10656. }
  10657. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10658. {
  10659. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10660. {
  10661. 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")));
  10662. }
  10663. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10664. {
  10665. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10666. }
  10667. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10668. {
  10669. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10670. }
  10671. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10672. {
  10673. 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")));
  10674. }
  10675. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10676. {
  10677. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10678. if(chargingSchedulePeriodCount <= 10)
  10679. {
  10680. 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++)
  10681. {
  10682. 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)
  10683. {
  10684. 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"));
  10685. }
  10686. 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)
  10687. {
  10688. 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"));
  10689. }
  10690. 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)
  10691. {
  10692. 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"));
  10693. }
  10694. }
  10695. }
  10696. }
  10697. }
  10698. }
  10699. }
  10700. // Profile periods quantity check
  10701. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10702. {
  10703. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10704. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10705. goto end;
  10706. }
  10707. // Profile purpose info check
  10708. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10709. {
  10710. FILE *fp;
  10711. char dataLine[4096]={0};
  10712. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  10713. if(SetProfileReq.ConnectorId != 0)
  10714. {
  10715. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10716. DEBUG_WARN("Profile connector id is not 0.\n");
  10717. goto end;
  10718. }
  10719. fp = fopen(ChargePointMaxProfile_JSON, "r");
  10720. if (!fp)
  10721. {
  10722. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  10723. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  10724. }
  10725. else
  10726. {
  10727. while(fscanf(fp, "%s", dataLine) != EOF)
  10728. {
  10729. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10730. {
  10731. profileQuantity += 1;
  10732. }
  10733. }
  10734. }
  10735. fclose(fp);
  10736. }
  10737. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10738. {
  10739. FILE *fp;
  10740. char dataLine[4096]={0};
  10741. char filename[128]={0};
  10742. int tmpProfileQuantity;
  10743. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  10744. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10745. {
  10746. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10747. DEBUG_WARN("Profile connector id is over max gun number.\n");
  10748. goto end;
  10749. }
  10750. if(SetProfileReq.ConnectorId == 0)
  10751. {
  10752. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  10753. {
  10754. tmpProfileQuantity = 0;
  10755. memset(filename, 0, ARRAY_SIZE(filename));
  10756. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10757. fp = fopen(filename, "r");
  10758. if (!fp)
  10759. {
  10760. DEBUG_INFO("%s does not create.\n", filename);
  10761. fp = fopen(filename, "w+");
  10762. }
  10763. else
  10764. {
  10765. while(fscanf(fp, "%s", dataLine) != EOF)
  10766. {
  10767. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10768. {
  10769. tmpProfileQuantity += 1;
  10770. }
  10771. }
  10772. }
  10773. fclose(fp);
  10774. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  10775. }
  10776. }
  10777. else
  10778. {
  10779. memset(filename, 0, ARRAY_SIZE(filename));
  10780. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  10781. fp = fopen(filename, "r");
  10782. if (!fp)
  10783. {
  10784. DEBUG_INFO("%s does not create.\n", filename);
  10785. fp = fopen(filename, "w+");
  10786. }
  10787. else
  10788. {
  10789. while(fscanf(fp, "%s", dataLine) != EOF)
  10790. {
  10791. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10792. {
  10793. profileQuantity += 1;
  10794. }
  10795. }
  10796. }
  10797. fclose(fp);
  10798. }
  10799. }
  10800. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10801. {
  10802. int isMatchTransactiodId= FALSE;
  10803. FILE *fp;
  10804. char dataLine[4096]={0};
  10805. char filename[128]={0};
  10806. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  10807. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10808. if(SetProfileReq.ConnectorId == 0)
  10809. {
  10810. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10811. DEBUG_WARN("Profile connector id is 0.\n");
  10812. goto end;
  10813. }
  10814. int tempIndex = 0;
  10815. //check Transaction active
  10816. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  10817. {
  10818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10819. {
  10820. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10821. }
  10822. else
  10823. {
  10824. tempIndex = SetProfileReq.ConnectorId -1;
  10825. }
  10826. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10827. {
  10828. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10829. {
  10830. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10831. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10832. {
  10833. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10834. {
  10835. isMatchTransactiodId = TRUE;
  10836. break;
  10837. }
  10838. }
  10839. }
  10840. }
  10841. }
  10842. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  10843. {
  10844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10845. {
  10846. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10847. }
  10848. else
  10849. {
  10850. tempIndex = SetProfileReq.ConnectorId -1;
  10851. }
  10852. for (int index = 0; index < CCS_QUANTITY; index++)
  10853. {
  10854. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10855. {
  10856. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10857. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10858. {
  10859. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10860. {
  10861. isMatchTransactiodId = TRUE;
  10862. break;
  10863. }
  10864. }
  10865. }
  10866. }
  10867. }
  10868. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  10869. {
  10870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10871. {
  10872. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10873. }
  10874. else
  10875. {
  10876. tempIndex = SetProfileReq.ConnectorId -1;
  10877. }
  10878. for (int index = 0; index < GB_QUANTITY; index++)
  10879. {
  10880. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10881. {
  10882. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10883. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10884. {
  10885. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10886. {
  10887. isMatchTransactiodId = TRUE;
  10888. break;
  10889. }
  10890. }
  10891. }
  10892. }
  10893. }
  10894. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  10895. {
  10896. tempIndex = SetProfileReq.ConnectorId -1;
  10897. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10898. {
  10899. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10900. {
  10901. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10902. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10903. {
  10904. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10905. {
  10906. isMatchTransactiodId = TRUE;
  10907. break;
  10908. }
  10909. }
  10910. }
  10911. }
  10912. }
  10913. else
  10914. {
  10915. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10916. {
  10917. tempIndex = 2;
  10918. }
  10919. else
  10920. {
  10921. tempIndex = (SetProfileReq.ConnectorId -1);
  10922. }
  10923. for (int index = 0; index < AC_QUANTITY; index++)
  10924. {
  10925. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10926. {
  10927. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10928. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10929. {
  10930. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10931. {
  10932. isMatchTransactiodId = TRUE;
  10933. break;
  10934. }
  10935. }
  10936. }
  10937. }
  10938. }
  10939. //check Transaction active
  10940. if(isMatchTransactiodId == FALSE)
  10941. {
  10942. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10943. DEBUG_WARN("Tx profile transaction id is not match.\n");
  10944. goto end;
  10945. }
  10946. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10947. {
  10948. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10949. DEBUG_WARN("Connector id is over max gun number.\n");
  10950. goto end;
  10951. }
  10952. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  10953. fp = fopen(filename, "r");
  10954. if (!fp)
  10955. {
  10956. DEBUG_INFO("%s does not create.\n", filename);
  10957. fp = fopen(filename, "w+");
  10958. }
  10959. else
  10960. {
  10961. //Check Charging Profile Count
  10962. while(fscanf(fp, "%s", dataLine) != EOF)
  10963. {
  10964. //DEBUG_INFO("word=%s\n",word);
  10965. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10966. {
  10967. profileQuantity += 1;
  10968. }
  10969. }
  10970. }
  10971. fclose(fp);
  10972. }
  10973. // Check ChargeProfileMaxStackLevel
  10974. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  10975. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10976. {
  10977. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10978. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10979. goto end;
  10980. }
  10981. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10982. {
  10983. FILE *fp;
  10984. char dataLine[4096]={0};
  10985. char fnametemp[128]={0};
  10986. int tmpProfileQuantity;
  10987. //Check ChargePointMaxProfile.json exit
  10988. profileQuantity = 0;
  10989. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10990. {
  10991. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10992. //Check Charging Profile Count
  10993. tmpProfileQuantity = 0;
  10994. while(fscanf(fp, "%s", dataLine) != EOF)
  10995. {
  10996. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10997. {
  10998. profileQuantity += 1;
  10999. tmpProfileQuantity += 1;
  11000. }
  11001. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11002. }
  11003. fclose(fp);
  11004. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11005. }
  11006. //Check TxDefaultProfile_%d.json
  11007. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11008. {
  11009. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11010. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11011. if((access(fnametemp,F_OK))!=-1)
  11012. {
  11013. fp = fopen(fnametemp, "r");
  11014. //Check Charging Profile Count
  11015. tmpProfileQuantity = 0;
  11016. while(fscanf(fp, "%s", dataLine) != EOF)
  11017. {
  11018. //DEBUG_INFO("word=%s\n",word);
  11019. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11020. {
  11021. profileQuantity += 1;
  11022. tmpProfileQuantity += 1;
  11023. }
  11024. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11025. }
  11026. fclose(fp);
  11027. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11028. }
  11029. }
  11030. //Check TxProfile_%d.json
  11031. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11032. {
  11033. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11034. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  11035. if((access(fnametemp,F_OK))!=-1)
  11036. {
  11037. fp = fopen(fnametemp, "r");
  11038. //Check Charging Profile Count
  11039. tmpProfileQuantity = 0;
  11040. while(fscanf(fp, "%s", dataLine) != EOF)
  11041. {
  11042. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11043. {
  11044. profileQuantity += 1;
  11045. tmpProfileQuantity += 1;
  11046. }
  11047. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11048. }
  11049. fclose(fp);
  11050. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11051. }
  11052. }
  11053. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11054. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11055. {
  11056. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11057. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11058. goto end;
  11059. }
  11060. }
  11061. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11062. //**********************************Write to File********************************************************/
  11063. {
  11064. FILE *infile;
  11065. FILE *outfile;
  11066. char dataLine[4096]={0};
  11067. char filename[128]={0};
  11068. int chkChar=0;
  11069. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11070. {
  11071. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11072. {
  11073. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11074. }
  11075. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11076. {
  11077. if(SetProfileReq.ConnectorId==0)
  11078. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11079. else
  11080. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11081. }
  11082. else
  11083. {
  11084. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11085. }
  11086. infile = fopen (filename, "r");
  11087. outfile = fopen (tempfile, "w");
  11088. chkChar = fgetc(infile);
  11089. rewind(infile);
  11090. if(chkChar == EOF)
  11091. {
  11092. // Profile is empty
  11093. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11094. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11095. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11096. fclose(infile);
  11097. fclose(outfile);
  11098. sprintf(rmFileCmd,"rm -f %s",filename);
  11099. system(rmFileCmd);
  11100. rename(tempfile, filename);
  11101. }
  11102. else
  11103. {
  11104. // Profile is not empty
  11105. int ChargingProfileAdded = FALSE;
  11106. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11107. {
  11108. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11109. json_object *tmpChargingProfile;
  11110. tmpChargingProfile = json_tokener_parse(dataLine);
  11111. if(!is_error(SetChargingProfile))
  11112. {
  11113. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11114. {
  11115. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11116. {
  11117. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11118. }
  11119. }
  11120. }
  11121. json_object_put(tmpChargingProfile);
  11122. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11123. {
  11124. if(ChargingProfileAdded == FALSE)
  11125. {
  11126. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11127. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11128. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11129. ChargingProfileAdded = TRUE;
  11130. }
  11131. }
  11132. else
  11133. {
  11134. fprintf(outfile,"%s\n",dataLine);
  11135. if(ChargingProfileAdded == FALSE)
  11136. {
  11137. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11138. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11139. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11140. ChargingProfileAdded = TRUE;
  11141. }
  11142. }
  11143. } // end of while loop
  11144. fclose(infile);
  11145. fclose(outfile);
  11146. sprintf(rmFileCmd,"rm -f %s",filename);
  11147. system(rmFileCmd);
  11148. rename(tempfile, filename);
  11149. }
  11150. }
  11151. sleep(1);
  11152. result = TRUE;
  11153. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11154. }
  11155. end:
  11156. json_object_put(SetChargingProfile);
  11157. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11158. {
  11159. if(SetProfileReq.ConnectorId == 0)
  11160. {
  11161. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11162. {
  11163. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11164. }
  11165. }
  11166. else
  11167. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11168. }
  11169. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11170. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11171. return result;
  11172. }
  11173. int handleTriggerMessageRequest(char *uuid, char *payload)
  11174. {
  11175. mtrace();
  11176. int result = FAIL;
  11177. int connectorIdIsNULL = FALSE;
  11178. int connectorIdInt =0;
  11179. char sstr[40]={0},sstrtemp[100]={ 0 };
  11180. char requestedMessagestr[40]={0};
  11181. char comfirmstr[20]={0};
  11182. int c = 0;
  11183. char *loc;
  11184. DEBUG_INFO("handleTriggerMessageRequest\n");
  11185. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11186. strcpy(sstrtemp, stringtrimspace(payload));
  11187. c = 0;
  11188. loc = strstr(sstrtemp, "requestedMessage");
  11189. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11190. {
  11191. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11192. c++;
  11193. }
  11194. sstr[c] = '\0';
  11195. strcpy(requestedMessagestr, sstr);
  11196. c = 0;
  11197. loc = strstr(sstrtemp, "connectorId");
  11198. if(loc == NULL)
  11199. {
  11200. connectorIdIsNULL = TRUE;
  11201. }
  11202. else
  11203. {
  11204. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11205. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11206. {
  11207. sstr[c] = loc[strlen("connectorId")+2+c];
  11208. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11209. c++;
  11210. }
  11211. sstr[c] = '\0';
  11212. connectorIdInt = atoi(sstr);
  11213. }
  11214. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11215. {
  11216. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11217. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11218. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11219. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11220. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11221. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11222. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11223. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11224. {
  11225. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11226. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11227. return TRUE;
  11228. }
  11229. else
  11230. {
  11231. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11232. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11233. }
  11234. }
  11235. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11236. {
  11237. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11238. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11239. return TRUE;
  11240. }
  11241. //==========================
  11242. // Trigger message
  11243. //==========================
  11244. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11245. {
  11246. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11247. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11248. {
  11249. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11250. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11251. }
  11252. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11253. }
  11254. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11255. {
  11256. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11257. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11258. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11259. }
  11260. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11261. {
  11262. //sendBootNotificationRequest();
  11263. server_sign = FALSE;
  11264. }
  11265. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11266. {
  11267. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11268. }
  11269. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11270. {
  11271. if(connectorIdIsNULL == FALSE)
  11272. {
  11273. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11274. {
  11275. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11276. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11277. }
  11278. }
  11279. else
  11280. {
  11281. for(int idx=0;idx< gunTotalNumber;idx++)
  11282. {
  11283. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11284. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11285. }
  11286. }
  11287. }
  11288. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11289. {
  11290. if(connectorIdIsNULL == FALSE)
  11291. {
  11292. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11293. {
  11294. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11295. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11296. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11297. }
  11298. }
  11299. else
  11300. {
  11301. for(int idx=0;idx< gunTotalNumber;idx++)
  11302. {
  11303. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11304. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11305. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11306. }
  11307. }
  11308. }
  11309. return result;
  11310. }
  11311. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11312. {
  11313. mtrace();
  11314. int result = FAIL;
  11315. int connectorIdInt =0;
  11316. char comfirmstr[20]={0};
  11317. int tempIndex = 0;
  11318. json_object *UnlockConnector;
  11319. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11320. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11321. UnlockConnector = json_tokener_parse(payload);
  11322. if(!is_error(UnlockConnector))
  11323. {
  11324. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11325. {
  11326. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11327. }
  11328. }
  11329. json_object_put(UnlockConnector);
  11330. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11331. if(gunTotalNumber == 0)
  11332. {
  11333. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11334. goto end;
  11335. }
  11336. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11337. {
  11338. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11339. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11340. goto end;
  11341. }
  11342. else
  11343. {
  11344. //check Transaction active
  11345. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11346. {
  11347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11348. {
  11349. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11350. }
  11351. else
  11352. {
  11353. tempIndex = connectorIdInt -1;
  11354. }
  11355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11356. {
  11357. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11358. {
  11359. //stop Transaction
  11360. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11361. }
  11362. }
  11363. }
  11364. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11365. {
  11366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11367. {
  11368. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11369. }
  11370. else
  11371. {
  11372. tempIndex = connectorIdInt -1;
  11373. }
  11374. for (int index = 0; index < CCS_QUANTITY; index++)
  11375. {
  11376. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11377. {
  11378. //stop Transaction
  11379. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11380. }
  11381. }
  11382. }
  11383. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11384. {
  11385. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11386. {
  11387. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11388. }
  11389. else
  11390. {
  11391. tempIndex = connectorIdInt -1;
  11392. }
  11393. for (int index = 0; index < GB_QUANTITY; index++)
  11394. {
  11395. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11396. {
  11397. //stop Transaction
  11398. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11399. }
  11400. }
  11401. }
  11402. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11403. {
  11404. tempIndex = connectorIdInt -1;
  11405. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11406. {
  11407. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  11408. {
  11409. //stop Transaction
  11410. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11411. }
  11412. }
  11413. }
  11414. else
  11415. {
  11416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11417. {
  11418. tempIndex = 2;
  11419. }
  11420. else
  11421. {
  11422. tempIndex = connectorIdInt-1;
  11423. }
  11424. for (int index = 0; index < AC_QUANTITY; index++)
  11425. {
  11426. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11427. {
  11428. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11429. }
  11430. }
  11431. }
  11432. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11433. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11434. result = TRUE;
  11435. return result;
  11436. }
  11437. end:
  11438. //json_object_put(obj); --- remove temporally
  11439. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11440. return result;
  11441. }
  11442. static char UpdateFirmwarepayloadData[300]={0};
  11443. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11444. {
  11445. mtrace();
  11446. int result = FAIL;
  11447. pthread_t t;
  11448. sendUpdateFirmwareConfirmation(uuid);
  11449. memset(UpdateFirmwarepayloadData, 0, 300);
  11450. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11451. if(!interLock.isUpdateFirmwareGoing)
  11452. {
  11453. interLock.isUpdateFirmwareGoing = 1;
  11454. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11455. sleep(1);
  11456. }
  11457. else
  11458. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11459. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11460. return result;
  11461. }
  11462. void *UpdateFirmwareProcess(void *data)
  11463. {
  11464. pthread_detach(pthread_self());
  11465. mtrace();
  11466. int retriesInt =0, retryIntervalInt=0;
  11467. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11468. int port=0;
  11469. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11470. int isSuccess = 0;
  11471. char ftpbuf[1024];
  11472. char temp[1024];
  11473. char * pch;
  11474. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11475. json_object *UpdateFirmware;
  11476. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11477. if(!is_error(UpdateFirmware))
  11478. {
  11479. // Required data
  11480. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11481. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11482. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11483. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11484. // Optional data
  11485. if(json_object_object_get(UpdateFirmware, "retries"))
  11486. {
  11487. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11488. }
  11489. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11490. {
  11491. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11492. }
  11493. }
  11494. json_object_put(UpdateFirmware);
  11495. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11496. memset(path, 0, ARRAY_SIZE(path));
  11497. // Wait retrieveData
  11498. if(strlen(retrieveDatestr) > 10)
  11499. {
  11500. do
  11501. {
  11502. sleep(1);
  11503. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11504. }
  11505. // Ready to download
  11506. system("rm -f /mnt/*");
  11507. if(strncmp(locationstr,"http", 4) == 0)
  11508. {
  11509. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11510. sprintf(ftppath,"/%s", path);
  11511. DEBUG_INFO("locationstr: %s\n", locationstr);
  11512. DEBUG_INFO("protocol: %s\n",protocol);
  11513. DEBUG_INFO("host: %s\n",host);
  11514. DEBUG_INFO("path: %s\n",path);
  11515. DEBUG_INFO("ftppath: %s\n",ftppath);
  11516. int ftppathlen=strlen(ftppath);
  11517. int i=1;
  11518. char filenametemp[50];
  11519. while(i < ftppathlen)
  11520. {
  11521. int len=ftppathlen-i;
  11522. if(ftppath[len]== 47) // '/' ascll code: 47
  11523. {
  11524. DEBUG_INFO("compare '/' all right\n");
  11525. break;
  11526. }
  11527. i=i+1;
  11528. }
  11529. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11530. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11531. filenametemp[i+1] = 0;
  11532. do
  11533. {
  11534. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11535. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11536. sleep(1);
  11537. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11538. if(!isSuccess)
  11539. {
  11540. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11541. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11542. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11543. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11544. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11545. }
  11546. else
  11547. {
  11548. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11549. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11550. }
  11551. retriesInt--;
  11552. }while((isSuccess == 0)&&(retriesInt >= 0));
  11553. }
  11554. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11555. {
  11556. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11557. memset(temp, 0, ARRAY_SIZE(temp));
  11558. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11559. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11560. int ftppathlen=strlen(ftpbuf);
  11561. int i=1;
  11562. char filenametemp[50];
  11563. while(i < ftppathlen)
  11564. {
  11565. int len=ftppathlen-i;
  11566. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11567. {
  11568. DEBUG_INFO(" compare '/' all right\n");
  11569. break;
  11570. }
  11571. i=i+1;
  11572. }
  11573. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11574. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11575. filenametemp[i+1] = 0;
  11576. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11577. pch=strchr(temp,'@');
  11578. if(pch==NULL)
  11579. {
  11580. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11581. protocol, host, &port, path);
  11582. strcpy(user,"anonymous");
  11583. strcpy(password,"");
  11584. }
  11585. else
  11586. {
  11587. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11588. protocol, user, password, host, &port, path);
  11589. }
  11590. sscanf(host,"%[^/]%s",host1, path1);
  11591. sprintf(ftppath,"%s", path1);
  11592. //DEBUG_INFO("protocol =%s\n",protocol);
  11593. //DEBUG_INFO("user =%s\n",user);
  11594. //DEBUG_INFO("password =%s\n",password);
  11595. //DEBUG_INFO("host1 =%s\n",host1);
  11596. //DEBUG_INFO("port =%d\n",port);
  11597. //DEBUG_INFO("path1 =%s\n",path1);
  11598. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11599. //ftpFile(host, user, password, port, ftppath, fname);
  11600. //download firmware pthred
  11601. if(port == 0)
  11602. {
  11603. port = 21;
  11604. }
  11605. do
  11606. {
  11607. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11608. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11609. sleep(1);
  11610. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11611. if(!isSuccess)
  11612. {
  11613. //BulldogUtil.sleepMs(interval*1000);
  11614. DEBUG_INFO("Update firmware request and download file fail.\n");
  11615. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11616. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11617. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11618. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11619. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11620. }
  11621. else
  11622. {
  11623. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11624. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11625. }
  11626. retriesInt--;
  11627. }while((!isSuccess)&&(retriesInt >= 0));
  11628. }
  11629. else
  11630. {
  11631. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11632. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11633. sleep(1);
  11634. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11635. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11636. }
  11637. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11638. interLock.isUpdateFirmwareGoing = 0;
  11639. pthread_exit(NULL);
  11640. }
  11641. int handleCertificateSignedRequest(char *uuid, char *payload)
  11642. {
  11643. mtrace();
  11644. int result = PASS;
  11645. json_object *CertificateSigned;
  11646. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11647. CertificateSigned = json_tokener_parse(payload);
  11648. if(!is_error(CertificateSigned))
  11649. {
  11650. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11651. }
  11652. json_object_put(CertificateSigned);
  11653. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11654. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11655. fclose(fp);
  11656. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11657. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11658. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11659. sendCertificateSignedConfirmation(uuid);
  11660. return result;
  11661. }
  11662. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11663. {
  11664. mtrace();
  11665. int result = PASS;
  11666. json_object *DeleteCertificate;
  11667. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11668. DeleteCertificate = json_tokener_parse(payload);
  11669. if(!is_error(DeleteCertificate))
  11670. {
  11671. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11672. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11673. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11674. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11675. }
  11676. json_object_put(DeleteCertificate);
  11677. /*
  11678. * TODO: Delete certificateSigned process
  11679. */
  11680. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11681. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11682. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11683. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11684. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11685. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11686. sendDeleteCertificateConfirmation(uuid);
  11687. return result;
  11688. }
  11689. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11690. {
  11691. mtrace();
  11692. int result = PASS;
  11693. json_object *ExtendedTriggerMessage;
  11694. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11695. ExtendedTriggerMessage = json_tokener_parse(payload);
  11696. if(!is_error(ExtendedTriggerMessage))
  11697. {
  11698. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11699. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11700. {
  11701. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11702. }
  11703. else
  11704. {
  11705. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11706. }
  11707. }
  11708. json_object_put(ExtendedTriggerMessage);
  11709. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11710. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11711. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11712. {
  11713. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11714. }
  11715. else
  11716. {
  11717. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11718. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11719. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11720. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11721. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11722. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11723. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11724. {
  11725. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11726. }
  11727. else
  11728. {
  11729. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11730. }
  11731. }
  11732. sendExtendedTriggerMessageConfirmation(uuid);
  11733. //==========================
  11734. // Trigger message
  11735. //==========================
  11736. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11737. {
  11738. //sendBootNotificationRequest();
  11739. server_sign = FALSE;
  11740. }
  11741. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11742. {
  11743. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11744. }
  11745. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11746. {
  11747. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11748. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11749. {
  11750. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11751. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11752. }
  11753. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11754. }
  11755. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11756. {
  11757. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11758. }
  11759. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11760. {
  11761. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11762. {
  11763. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11764. }
  11765. else
  11766. {
  11767. for(int idx=0;idx< gunTotalNumber;idx++)
  11768. {
  11769. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11770. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11771. }
  11772. }
  11773. }
  11774. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11775. {
  11776. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11777. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11778. {
  11779. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  11780. }
  11781. }
  11782. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11783. {
  11784. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11785. {
  11786. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11787. }
  11788. else
  11789. {
  11790. for(int idx=0;idx< gunTotalNumber;idx++)
  11791. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11792. }
  11793. }
  11794. return result;
  11795. }
  11796. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11797. {
  11798. mtrace();
  11799. int result = PASS;
  11800. json_object *GetInstalledCertificateIds;
  11801. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11802. GetInstalledCertificateIds = json_tokener_parse(payload);
  11803. if(!is_error(GetInstalledCertificateIds))
  11804. {
  11805. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11806. }
  11807. json_object_put(GetInstalledCertificateIds);
  11808. /*
  11809. * TODO: Return installed certificate process
  11810. */
  11811. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11812. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11813. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11814. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11815. sendGetInstalledCertificateIdsConfirmation(uuid);
  11816. return result;
  11817. }
  11818. int handleGetLogRequest(char *uuid, char *payload)
  11819. {
  11820. mtrace();
  11821. int result = PASS;
  11822. json_object *GetLog;
  11823. DEBUG_INFO("handleGetLogRequest...\n");
  11824. GetLog = json_tokener_parse(payload);
  11825. if(!is_error(GetLog))
  11826. {
  11827. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11828. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11829. if(json_object_object_get(GetLog, "retries") != NULL)
  11830. {
  11831. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11832. }
  11833. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11834. {
  11835. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11836. }
  11837. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11838. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11839. {
  11840. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11841. }
  11842. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11843. {
  11844. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11845. }
  11846. }
  11847. json_object_put(GetLog);
  11848. /*
  11849. * TODO: Upload log process
  11850. */
  11851. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11852. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11853. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11854. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11855. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11856. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11857. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11858. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11859. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11860. sendGetLogConfirmation(uuid);
  11861. return result;
  11862. }
  11863. int handleInstallCertificateRequest(char *uuid, char *payload)
  11864. {
  11865. mtrace();
  11866. int result = PASS;
  11867. json_object *InstallCertificate;
  11868. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11869. InstallCertificate = json_tokener_parse(payload);
  11870. if(!is_error(InstallCertificate))
  11871. {
  11872. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11873. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11874. /*
  11875. * TODO: Install certificate process
  11876. */
  11877. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11878. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11879. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11880. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11881. sendInstallCertificateConfirmation(uuid);
  11882. }
  11883. json_object_put(InstallCertificate);
  11884. return result;
  11885. }
  11886. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11887. {
  11888. mtrace();
  11889. int result = PASS;
  11890. json_object *SignedUpdateFirmware;
  11891. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11892. SignedUpdateFirmware = json_tokener_parse(payload);
  11893. if(!is_error(SignedUpdateFirmware))
  11894. {
  11895. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11896. {
  11897. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11898. }
  11899. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11900. {
  11901. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11902. }
  11903. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11904. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11905. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11906. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11907. {
  11908. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11909. }
  11910. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11911. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11912. }
  11913. json_object_put(SignedUpdateFirmware);
  11914. /*
  11915. * TODO: Upgrade firmware process
  11916. */
  11917. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11918. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  11919. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  11920. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  11921. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  11922. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  11923. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  11924. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  11925. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  11926. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  11927. sendInstallCertificateConfirmation(uuid);
  11928. return result;
  11929. }
  11930. int handleUnknownRequest(char *uuid, char *payload)
  11931. {
  11932. mtrace();
  11933. int result = PASS;
  11934. DEBUG_INFO("handleUnknownRequest...\n");
  11935. sendUnknownConfirmation(uuid);
  11936. result = PASS;
  11937. return result;
  11938. }
  11939. //==========================================
  11940. // Handle server response routine
  11941. //==========================================
  11942. void handleAuthorizeResponse(char *payload, int gun_index)
  11943. {
  11944. mtrace();
  11945. char expiryDatestr[30]={0};
  11946. char parentIdTagstr[20]={0};
  11947. char statusstr[20]={0};
  11948. int expiryDateISNULL=FALSE;
  11949. int parentIdTagISNULL=FALSE;
  11950. DEBUG_INFO("handleAuthorizeResponse...\n");
  11951. json_object *Authorize;
  11952. Authorize = json_tokener_parse(payload);
  11953. if(!is_error(Authorize))
  11954. {
  11955. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11956. {
  11957. // Required data
  11958. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11959. // Optional data
  11960. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11961. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11962. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11963. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11964. }
  11965. }
  11966. json_object_put(Authorize);
  11967. if(expiryDateISNULL == FALSE)
  11968. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11969. if(parentIdTagISNULL == FALSE)
  11970. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11971. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11972. //Update idTag information to authorization cache if supproted
  11973. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11974. {
  11975. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11976. }
  11977. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11978. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11979. authorizeRetryTimes = 0;
  11980. }
  11981. void handleBootNotificationResponse(char *payload, int gun_index)
  11982. {
  11983. mtrace();
  11984. char statusStr[12]={0};
  11985. char currentTimeStr[30]={0};
  11986. int intervalInt = 0;
  11987. DEBUG_INFO("handleBootNotificationResponse...\n");
  11988. json_object *BootNotification;
  11989. BootNotification = json_tokener_parse(payload);
  11990. if(!is_error(BootNotification))
  11991. {
  11992. // Required data
  11993. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11994. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11995. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11996. }
  11997. json_object_put(BootNotification);
  11998. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11999. BootNotificationInterval = intervalInt;
  12000. HeartBeatWaitTime = intervalInt;
  12001. //write back to ShmOCPP16Data->BootNotification
  12002. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12003. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12004. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12005. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12006. {
  12007. server_sign = TRUE;
  12008. server_pending =FALSE;
  12009. }
  12010. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12011. {
  12012. server_pending = TRUE;
  12013. }
  12014. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12015. srand(time(NULL));
  12016. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12017. SetOcppConnStatus(TRUE);
  12018. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12019. }
  12020. void handleDataTransferResponse(char *payload, int gun_index)
  12021. {
  12022. char sstr[160]={0};//sstr[200]={ 0 };
  12023. int c = 0;
  12024. char *loc;
  12025. DEBUG_INFO("handleDataTransferResponse ...\n");
  12026. loc = strstr(payload, "status");
  12027. c = 0;
  12028. while (loc[3+strlen("status")+c] != '\"')
  12029. {
  12030. sstr[c] = loc[3+strlen("status")+c];
  12031. c++;
  12032. }
  12033. sstr[c] = '\0';
  12034. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12035. }
  12036. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12037. {
  12038. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12039. //struct json_object *obj;
  12040. // obj = json_tokener_parse(payload);
  12041. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12042. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12043. //No fields are defined.
  12044. }
  12045. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12046. {
  12047. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12048. //struct json_object *obj;
  12049. // obj = json_tokener_parse(payload);
  12050. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12051. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12052. //No fields are defined.
  12053. }
  12054. void handleHeartbeatResponse(char *payload, int gun_index)
  12055. {
  12056. mtrace();
  12057. DEBUG_INFO("handleHeartbeatResponse...\n");
  12058. json_object *Heartbeat;
  12059. Heartbeat = json_tokener_parse(payload);
  12060. if(!is_error(Heartbeat))
  12061. {
  12062. // Required data
  12063. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12064. }
  12065. json_object_put(Heartbeat);
  12066. if(FirstHeartBeat == 0)
  12067. {
  12068. FirstHeartBeat = 1;
  12069. DEBUG_INFO("FirstHeartBeat \n");
  12070. }
  12071. HeartBeatWithNOResponse = 0;
  12072. clientTime.Heartbeat=time((time_t*)NULL);
  12073. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12074. }
  12075. void handleMeterValuesResponse(char *payload, int gun_index)
  12076. {
  12077. mtrace();
  12078. DEBUG_INFO("handleMeterValuesResponse...\n");
  12079. }
  12080. void handleStartTransactionResponse(char *payload, int gun_index)
  12081. {
  12082. mtrace();
  12083. //int transactionIdInt = 0;
  12084. FILE *outfile;
  12085. char data[100]={0};
  12086. DEBUG_INFO("handleStartTransactionResponse...\n");
  12087. json_object *StartTransaction;
  12088. StartTransaction = json_tokener_parse(payload);
  12089. if(!is_error(StartTransaction))
  12090. {
  12091. // Required data
  12092. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12093. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12094. // Optional data
  12095. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12096. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12097. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12098. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12099. }
  12100. json_object_put(StartTransaction);
  12101. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12102. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12103. //-----------Start : write to the Queue TransactionId file -----------------//
  12104. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12105. {}
  12106. else
  12107. {
  12108. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12109. if(log == NULL)
  12110. {
  12111. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12112. return ;
  12113. }
  12114. else
  12115. {
  12116. fclose(log);
  12117. }
  12118. }
  12119. // open file for writing
  12120. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12121. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12122. {
  12123. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12124. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12125. fputs(data, outfile);
  12126. fclose (outfile);
  12127. }
  12128. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12129. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12130. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12131. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12132. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12133. }
  12134. void handleStatusNotificationResponse(char *payload, int gun_index)
  12135. {
  12136. mtrace();
  12137. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12138. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12139. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12140. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12141. }
  12142. void handleStopTransactionnResponse(char *payload, int gun_index)
  12143. {
  12144. mtrace();
  12145. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12146. json_object *StopTransaction;
  12147. StopTransaction = json_tokener_parse(payload);
  12148. if(!is_error(StopTransaction))
  12149. {
  12150. // Optional data
  12151. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12152. {
  12153. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12154. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12155. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12156. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12157. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12158. }
  12159. }
  12160. json_object_put(StopTransaction);
  12161. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12162. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12163. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12164. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12165. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12166. }
  12167. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12168. {
  12169. mtrace();
  12170. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12171. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12172. }
  12173. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12174. {
  12175. mtrace();
  12176. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12177. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12178. }
  12179. void handleSignCertificateResponse(char *payload, int gun_index)
  12180. {
  12181. mtrace();
  12182. DEBUG_INFO("handleSignCertificateResponse...\n");
  12183. json_object *SignCertificate;
  12184. SignCertificate = json_tokener_parse(payload);
  12185. if(!is_error(SignCertificate))
  12186. {
  12187. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12188. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12189. }
  12190. json_object_put(SignCertificate);
  12191. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12192. }
  12193. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12194. {
  12195. mtrace();
  12196. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12197. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12198. }
  12199. //==========================================
  12200. // Handle Error routine
  12201. //==========================================
  12202. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12203. {
  12204. mtrace();
  12205. #ifdef SystemLogMessage
  12206. DEBUG_INFO("errorCode: %s\n", errorCode);
  12207. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12208. DEBUG_INFO("errorDetails: %s\n", payload);
  12209. #endif
  12210. }
  12211. //===============================================
  12212. // Common routine
  12213. //===============================================
  12214. int initialConfigurationTable(void)
  12215. {
  12216. //clock_t start_t, end_t, total_t;
  12217. FILE *fp;
  12218. FILE *outfile;
  12219. char str[512]={0};
  12220. char sstr[256]={0};
  12221. int c = 0;
  12222. char *loc;
  12223. int confVersion = 8;
  12224. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12225. //start_t = clock();
  12226. //printf("Starting of the program, start_t = %ld\n", start_t);
  12227. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12228. // Check configuration file size is correct
  12229. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12230. {
  12231. struct stat st;
  12232. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12233. if(st.st_size < 3100)
  12234. {
  12235. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12236. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12237. }
  12238. }
  12239. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12240. {
  12241. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12242. if(outfile == NULL)
  12243. {
  12244. DEBUG_INFO("Error opening file\n");
  12245. return FALSE;
  12246. }
  12247. /*Core Profile*/
  12248. //AllowOfflineTxForUnknownId
  12249. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12253. //AuthorizationCacheEnabled
  12254. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12258. //AuthorizeRemoteTxRequests
  12259. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12263. //BlinkRepeat
  12264. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12268. //ClockAlignedDataInterval
  12269. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12273. //ConnectionTimeOut
  12274. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12278. //GetConfigurationMaxKeys
  12279. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12283. // HeartbeatInterval
  12284. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12288. // LightIntensity
  12289. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12293. // LocalAuthorizeOffline
  12294. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12298. // LocalPreAuthorize
  12299. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12303. // MaxEnergyOnInvalidId
  12304. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12308. // MeterValuesAlignedData
  12309. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  12313. else
  12314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12316. // MeterValuesAlignedDataMaxLength
  12317. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12321. else
  12322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12324. // MeterValuesSampledData
  12325. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  12329. else
  12330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12332. // MeterValuesSampledDataMaxLength
  12333. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12335. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12337. else
  12338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12340. // MeterValueSampleInterval
  12341. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12345. // MinimumStatusDuration
  12346. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12349. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12351. // NumberOfConnectors
  12352. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12354. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12355. {
  12356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12357. }
  12358. else
  12359. {
  12360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12361. }
  12362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12363. // ResetRetries
  12364. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12368. // ConnectorPhaseRotation
  12369. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12373. // ConnectorPhaseRotationMaxLength
  12374. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12378. // StopTransactionOnEVSideDisconnect
  12379. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12383. // StopTransactionOnInvalidId
  12384. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12388. // StopTxnAlignedData
  12389. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12393. // StopTxnAlignedDataMaxLength
  12394. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12398. // StopTxnSampledData
  12399. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12401. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12403. else
  12404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12406. // StopTxnSampledDataMaxLength
  12407. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12410. {
  12411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12412. }
  12413. else
  12414. {
  12415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12416. }
  12417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12418. // SupportedFeatureProfiles
  12419. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12423. // SupportedFeatureProfilesMaxLength
  12424. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12428. // TransactionMessageAttempts
  12429. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12432. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12434. // TransactionMessageRetryInterval
  12435. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12438. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12440. // UnlockConnectorOnEVSideDisconnect
  12441. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12445. // WebSocketPingInterval
  12446. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12450. // QueueOffLineMeterValues
  12451. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12455. // AuthorizationKey
  12456. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12460. // SecurityProfile
  12461. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12465. // DefaultPrice
  12466. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12470. // CustomDisplayCostAndPrice
  12471. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12475. // CustomIdleFeeAfterStop
  12476. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12480. // TimeOffset
  12481. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12485. // NextTimeOffsetTransitionDateTime
  12486. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12490. // TimeOffsetNextTransition
  12491. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12495. // Configuration Version
  12496. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12500. //* Local Auth List Management Profile*/
  12501. #if 0
  12502. //For OCTT Test Case
  12503. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12506. #endif
  12507. #if 1
  12508. //LocalAuthListEnabled
  12509. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12513. #endif
  12514. //LocalAuthListMaxLength
  12515. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12519. //SendLocalListMaxLength
  12520. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12524. //ReserveConnectorZeroSupported
  12525. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12529. //* Smart Charging Profile */
  12530. //ChargeProfileMaxStackLevel
  12531. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12535. // ChargingScheduleAllowedChargingRateUnit
  12536. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12540. // ChargingScheduleMaxPeriods
  12541. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12545. // ConnectorSwitch3to1PhaseSupported
  12546. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12550. // MaxChargingProfilesInstalled
  12551. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12555. fclose(outfile);
  12556. }
  12557. else
  12558. {
  12559. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12560. char keystr[60]={0};
  12561. char readonlystr[10]={0};
  12562. char valuestr[256]={0};
  12563. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12564. if(fp == NULL) {
  12565. DEBUG_INFO("Error opening file");
  12566. return FALSE;
  12567. }
  12568. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12569. {
  12570. //DEBUG_INFO("Get Configuration \n");
  12571. if(strlen(str) > 0)
  12572. {
  12573. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12574. //*************************key*********************************/
  12575. if(strstr(str, "key") != NULL)
  12576. {
  12577. loc = strstr(str, "key");
  12578. c = 0;
  12579. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12580. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12581. {
  12582. sstr[c] = loc[strlen("key")+3+c];
  12583. c++;
  12584. }
  12585. sstr[c] = '\0';
  12586. strcpy(keystr,sstr);
  12587. }
  12588. //*************************readonly*********************************/
  12589. if(strstr(str, "readonly") != NULL)
  12590. {
  12591. loc = strstr(str, "readonly");
  12592. c = 0;
  12593. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12594. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12595. {
  12596. sstr[c] = loc[strlen("readonly")+2+c];
  12597. c++;
  12598. }
  12599. sstr[c] = '\0';
  12600. strcpy(readonlystr,sstr);
  12601. }
  12602. //*************************value*********************************/
  12603. if(strstr(str, "value") != NULL)
  12604. {
  12605. loc = strstr(str, "value");
  12606. c = 0;
  12607. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12608. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12609. {
  12610. sstr[c] = loc[strlen("value")+3+c];
  12611. c++;
  12612. }
  12613. sstr[c] = '\0';
  12614. strcpy(valuestr,sstr);
  12615. }
  12616. // DEBUG_INFO("keystr=%s\n",keystr);
  12617. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12618. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12619. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12620. {
  12621. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12622. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12624. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12625. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12626. }
  12627. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12628. {
  12629. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12630. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12632. }
  12633. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12634. {
  12635. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12637. }
  12638. if(strcmp(keystr, "BlinkRepeat") == 0)
  12639. {
  12640. //Charger.BlinkRepeat = Integer.parseInt(value);
  12641. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12643. }
  12644. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12645. {
  12646. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12648. }
  12649. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12650. {
  12651. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12653. }
  12654. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12655. {
  12656. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12658. }
  12659. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12660. {
  12661. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12663. HeartBeatWaitTime = atoi(valuestr);
  12664. }
  12665. if(strcmp(keystr, "LightIntensity") == 0)
  12666. {
  12667. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12669. }
  12670. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12671. {
  12672. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12674. }
  12675. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12676. {
  12677. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12679. }
  12680. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12681. {
  12682. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12684. }
  12685. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12686. {
  12687. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12689. }
  12690. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12691. {
  12692. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12694. }
  12695. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12696. {
  12697. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12699. }
  12700. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12701. {
  12702. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12704. }
  12705. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12706. {
  12707. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12709. }
  12710. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12711. {
  12712. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12714. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12715. }
  12716. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12717. {
  12718. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12720. }
  12721. if(strcmp(keystr, "ResetRetries") == 0)
  12722. {
  12723. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12725. }
  12726. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12727. {
  12728. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12730. }
  12731. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12732. {
  12733. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12735. }
  12736. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12737. {
  12738. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12740. }
  12741. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12742. {
  12743. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12745. }
  12746. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12747. {
  12748. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12750. }
  12751. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12752. {
  12753. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12755. }
  12756. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12757. {
  12758. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12760. }
  12761. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12762. {
  12763. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12765. }
  12766. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12767. {
  12768. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12770. }
  12771. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12772. {
  12773. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12775. }
  12776. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12777. {
  12778. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12780. TransactionMessageAttemptsValue = atoi(valuestr);
  12781. }
  12782. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12783. {
  12784. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12786. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12787. }
  12788. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12789. {
  12790. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12792. }
  12793. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12794. {
  12795. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12797. }
  12798. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12799. {
  12800. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12802. }
  12803. if(strcmp(keystr, "AuthorizationKey") == 0)
  12804. {
  12805. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12806. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12808. }
  12809. if(strcmp(keystr, "SecurityProfile") == 0)
  12810. {
  12811. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12813. }
  12814. if(strcmp(keystr, "DefaultPrice") == 0)
  12815. {
  12816. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12818. }
  12819. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12820. {
  12821. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12823. }
  12824. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12825. {
  12826. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12828. }
  12829. if(strcmp(keystr, "TimeOffset") == 0)
  12830. {
  12831. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12833. }
  12834. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12835. {
  12836. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12838. }
  12839. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12840. {
  12841. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12843. }
  12844. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12845. {
  12846. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12848. }
  12849. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12850. {
  12851. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12853. }
  12854. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12855. {
  12856. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12858. }
  12859. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12860. {
  12861. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12862. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12863. }
  12864. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12865. {
  12866. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12868. }
  12869. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12870. {
  12871. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12873. }
  12874. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12875. {
  12876. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12878. }
  12879. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12880. {
  12881. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12883. }
  12884. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12885. {
  12886. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12888. }
  12889. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12890. {
  12891. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12893. }
  12894. }
  12895. }
  12896. fclose(fp);
  12897. }
  12898. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12899. {
  12900. return PASS;
  12901. }
  12902. else
  12903. {
  12904. return FAIL;
  12905. }
  12906. }
  12907. void StoreConfigurationTable(void)
  12908. {
  12909. FILE *outfile;
  12910. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12911. if(outfile == NULL)
  12912. {
  12913. DEBUG_INFO("Error opening file");
  12914. return ;
  12915. }
  12916. /*Core Profile*/
  12917. //AllowOfflineTxForUnknownId
  12918. /*
  12919. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12920. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12923. */
  12924. //DEBUG_INFO("data=%s\n",data);
  12925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12926. //AuthorizationCacheEnabled
  12927. /*
  12928. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12931. */
  12932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12933. //AuthorizeRemoteTxRequests
  12934. /*
  12935. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12938. */
  12939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12940. //BlinkRepeat
  12941. /*
  12942. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12945. */
  12946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12947. //ClockAlignedDataInterval
  12948. /*
  12949. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12952. */
  12953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12954. //ConnectionTimeOut
  12955. /*
  12956. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12959. */
  12960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12961. //GetConfigurationMaxKeys
  12962. /*
  12963. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12966. */
  12967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12968. // HeartbeatInterval
  12969. /*
  12970. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12973. */
  12974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12975. // LightIntensity
  12976. /*
  12977. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12980. */
  12981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12982. // LocalAuthorizeOffline
  12983. /*
  12984. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12987. */
  12988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12989. // LocalPreAuthorize
  12990. /*
  12991. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12994. */
  12995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12996. // MaxEnergyOnInvalidId
  12997. /*
  12998. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13001. */
  13002. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13004. // MeterValuesAlignedData
  13005. /*
  13006. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13009. */
  13010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13011. // MeterValuesAlignedDataMaxLength
  13012. /*
  13013. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13016. */
  13017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13018. // MeterValuesSampledData
  13019. /*
  13020. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13023. */
  13024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13025. // MeterValuesSampledDataMaxLength
  13026. /*
  13027. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13030. */
  13031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13032. // MeterValueSampleInterval
  13033. /*
  13034. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13037. */
  13038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13039. // MinimumStatusDuration
  13040. /*
  13041. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13044. */
  13045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13046. // NumberOfConnectors
  13047. /*
  13048. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13050. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13051. {
  13052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13053. }
  13054. else
  13055. {
  13056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13057. }
  13058. */
  13059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13060. // ResetRetries
  13061. /*
  13062. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13065. */
  13066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13067. // ConnectorPhaseRotation
  13068. /*
  13069. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13072. */
  13073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13074. // ConnectorPhaseRotationMaxLength
  13075. /*
  13076. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13079. */
  13080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13081. // StopTransactionOnEVSideDisconnect
  13082. /*
  13083. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13086. */
  13087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13088. // StopTransactionOnInvalidId
  13089. /*
  13090. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13093. */
  13094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13095. // StopTxnAlignedData
  13096. /*
  13097. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13100. */
  13101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13102. // StopTxnAlignedDataMaxLength
  13103. /*
  13104. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13107. */
  13108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13109. // StopTxnSampledData
  13110. /*
  13111. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13114. */
  13115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13116. // StopTxnSampledDataMaxLength
  13117. /*
  13118. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13121. */
  13122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13123. // SupportedFeatureProfiles
  13124. /*
  13125. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13128. */
  13129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13130. // SupportedFeatureProfilesMaxLength
  13131. /*
  13132. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13135. */
  13136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13137. // TransactionMessageAttempts
  13138. /*
  13139. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13142. */
  13143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13144. // TransactionMessageRetryInterval
  13145. /*
  13146. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13149. */
  13150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13151. // UnlockConnectorOnEVSideDisconnect
  13152. /*
  13153. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13156. */
  13157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13158. // WebSocketPingInterval
  13159. /*
  13160. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13163. */
  13164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13165. // QueueOffLineMeterValues
  13166. /*
  13167. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13170. */
  13171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13172. // AuthorizationKey
  13173. /*
  13174. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13177. */
  13178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13179. // SecurityProfile
  13180. /*
  13181. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13184. */
  13185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13186. // DefaultPrice
  13187. /*
  13188. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13191. */
  13192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13193. // CustomDisplayCostAndPrice
  13194. /*
  13195. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13198. */
  13199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13200. // CustomIdleFeeAfterStop
  13201. /*
  13202. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13205. */
  13206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13207. // TimeOffset
  13208. /*
  13209. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13212. */
  13213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13214. // NextTimeOffsetTransitionDateTime
  13215. /*
  13216. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13219. */
  13220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13221. // TimeOffsetNextTransition
  13222. /*
  13223. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13226. */
  13227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13228. // ConfigurationVersion
  13229. /*
  13230. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13233. */
  13234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13235. //* Local Auth List Management Profile*/
  13236. //LocalAuthListEnabled
  13237. /*
  13238. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13241. */
  13242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13243. //LocalAuthListMaxLength
  13244. /*
  13245. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13248. */
  13249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13250. //SendLocalListMaxLength
  13251. /*
  13252. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13255. */
  13256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13257. //ReserveConnectorZeroSupported
  13258. /*
  13259. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13262. */
  13263. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13264. //* Smart Charging Profile */
  13265. //ChargeProfileMaxStackLevel
  13266. /*
  13267. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13270. */
  13271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13272. // ChargingScheduleAllowedChargingRateUnit
  13273. /*
  13274. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13277. */
  13278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13279. // ChargingScheduleMaxPeriods
  13280. /*
  13281. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13284. */
  13285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13286. // ConnectorSwitch3to1PhaseSupported
  13287. /*
  13288. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13291. */
  13292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13293. // MaxChargingProfilesInstalled
  13294. /*
  13295. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13298. */
  13299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13300. fclose(outfile);
  13301. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13302. }
  13303. void getKeyValue(char *keyReq)
  13304. {
  13305. int isEmpty = FALSE;
  13306. int isKnowKey = FALSE;
  13307. DEBUG_INFO("keyReq = %s\n", keyReq);
  13308. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13309. isEmpty = TRUE;
  13310. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13311. {
  13312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13315. {
  13316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13317. }
  13318. else
  13319. {
  13320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13321. }
  13322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13323. isKnowKey = TRUE;
  13324. }
  13325. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13326. {
  13327. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13330. {
  13331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13332. }
  13333. else
  13334. {
  13335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13336. }
  13337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13338. isKnowKey = TRUE;
  13339. }
  13340. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13341. {
  13342. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13345. {
  13346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13347. }
  13348. else
  13349. {
  13350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13351. }
  13352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13353. isKnowKey = TRUE;
  13354. }
  13355. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13356. {
  13357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13360. {
  13361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13362. }
  13363. else
  13364. {
  13365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13366. }
  13367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13368. isKnowKey = TRUE;
  13369. }
  13370. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13371. {
  13372. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13375. {
  13376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13377. }
  13378. else
  13379. {
  13380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13381. }
  13382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13383. isKnowKey = TRUE;
  13384. }
  13385. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13386. {
  13387. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13390. {
  13391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13392. }
  13393. else
  13394. {
  13395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13396. }
  13397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13398. isKnowKey = TRUE;
  13399. }
  13400. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13401. {
  13402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13405. {
  13406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13407. }
  13408. else
  13409. {
  13410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13411. }
  13412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13413. isKnowKey = TRUE;
  13414. }
  13415. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13416. {
  13417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13420. {
  13421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13422. }
  13423. else
  13424. {
  13425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13426. }
  13427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13428. isKnowKey = TRUE;
  13429. }
  13430. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13431. {
  13432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13435. {
  13436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13437. }
  13438. else
  13439. {
  13440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13441. }
  13442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13443. isKnowKey = TRUE;
  13444. }
  13445. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13446. {
  13447. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13450. {
  13451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13452. }
  13453. else
  13454. {
  13455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13456. }
  13457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13458. isKnowKey = TRUE;
  13459. }
  13460. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13461. {
  13462. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13465. {
  13466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13467. }
  13468. else
  13469. {
  13470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13471. }
  13472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13473. isKnowKey = TRUE;
  13474. }
  13475. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13476. {
  13477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13480. {
  13481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13482. }
  13483. else
  13484. {
  13485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13486. }
  13487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13488. isKnowKey = TRUE;
  13489. }
  13490. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13491. {
  13492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13495. {
  13496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13497. }
  13498. else
  13499. {
  13500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13501. }
  13502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13503. isKnowKey = TRUE;
  13504. }
  13505. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13506. {
  13507. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13510. {
  13511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13512. }
  13513. else
  13514. {
  13515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13516. }
  13517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13518. isKnowKey = TRUE;
  13519. }
  13520. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13521. {
  13522. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13525. {
  13526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13527. }
  13528. else
  13529. {
  13530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13531. }
  13532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13533. isKnowKey = TRUE;
  13534. }
  13535. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13536. {
  13537. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13539. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13540. {
  13541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13542. }
  13543. else
  13544. {
  13545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13546. }
  13547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13548. isKnowKey = TRUE;
  13549. }
  13550. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13551. {
  13552. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13555. {
  13556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13557. }
  13558. else
  13559. {
  13560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13561. }
  13562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13563. isKnowKey = TRUE;
  13564. }
  13565. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13566. {
  13567. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13569. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13570. {
  13571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13572. }
  13573. else
  13574. {
  13575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13576. }
  13577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13578. isKnowKey = TRUE;
  13579. }
  13580. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13581. {
  13582. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13585. {
  13586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13587. }
  13588. else
  13589. {
  13590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13591. }
  13592. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13594. isKnowKey = TRUE;
  13595. }
  13596. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13597. {
  13598. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13601. {
  13602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13603. }
  13604. else
  13605. {
  13606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13607. }
  13608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13609. isKnowKey = TRUE;
  13610. }
  13611. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13612. {
  13613. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13616. {
  13617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13618. }
  13619. else
  13620. {
  13621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13622. }
  13623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13624. isKnowKey = TRUE;
  13625. }
  13626. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13627. {
  13628. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13631. {
  13632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13633. }
  13634. else
  13635. {
  13636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13637. }
  13638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13639. isKnowKey = TRUE;
  13640. }
  13641. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13642. {
  13643. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13646. {
  13647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13648. }
  13649. else
  13650. {
  13651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13652. }
  13653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13654. isKnowKey = TRUE;
  13655. }
  13656. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13657. {
  13658. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13660. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13661. {
  13662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13663. }
  13664. else
  13665. {
  13666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13667. }
  13668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13669. isKnowKey = TRUE;
  13670. }
  13671. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13672. {
  13673. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13676. {
  13677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13678. }
  13679. else
  13680. {
  13681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13682. }
  13683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13684. isKnowKey = TRUE;
  13685. }
  13686. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13687. {
  13688. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13691. {
  13692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13693. }
  13694. else
  13695. {
  13696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13697. }
  13698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13699. isKnowKey = TRUE;
  13700. }
  13701. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13702. {
  13703. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13706. {
  13707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13708. }
  13709. else
  13710. {
  13711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13712. }
  13713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13714. isKnowKey = TRUE;
  13715. }
  13716. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13717. {
  13718. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13721. {
  13722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13723. }
  13724. else
  13725. {
  13726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13727. }
  13728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13729. isKnowKey = TRUE;
  13730. }
  13731. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13732. {
  13733. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13736. {
  13737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13738. }
  13739. else
  13740. {
  13741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13742. }
  13743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13744. isKnowKey = TRUE;
  13745. }
  13746. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13747. {
  13748. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13750. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13751. {
  13752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13753. }
  13754. else
  13755. {
  13756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13757. }
  13758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13759. isKnowKey = TRUE;
  13760. }
  13761. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13762. {
  13763. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13766. {
  13767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13768. }
  13769. else
  13770. {
  13771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13772. }
  13773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13774. isKnowKey = TRUE;
  13775. }
  13776. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13777. {
  13778. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13781. {
  13782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13783. }
  13784. else
  13785. {
  13786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13787. }
  13788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13789. isKnowKey = TRUE;
  13790. }
  13791. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13792. {
  13793. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13796. {
  13797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13798. }
  13799. else
  13800. {
  13801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13802. }
  13803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13804. isKnowKey = TRUE;
  13805. }
  13806. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13807. {
  13808. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13810. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13811. {
  13812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13813. }
  13814. else
  13815. {
  13816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13817. }
  13818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13819. isKnowKey = TRUE;
  13820. }
  13821. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13822. {
  13823. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13826. {
  13827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13828. }
  13829. else
  13830. {
  13831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13832. }
  13833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13834. isKnowKey = TRUE;
  13835. }
  13836. /*
  13837. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13838. {
  13839. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13842. {
  13843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13844. }
  13845. else
  13846. {
  13847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13848. }
  13849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13850. isKnowKey = TRUE;
  13851. }*/
  13852. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13853. {
  13854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13857. {
  13858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13859. }
  13860. else
  13861. {
  13862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13863. }
  13864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13865. isKnowKey = TRUE;
  13866. }
  13867. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13868. {
  13869. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13872. {
  13873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13874. }
  13875. else
  13876. {
  13877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13878. }
  13879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13880. isKnowKey = TRUE;
  13881. }
  13882. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13883. {
  13884. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13886. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13887. {
  13888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13889. }
  13890. else
  13891. {
  13892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13893. }
  13894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13895. isKnowKey = TRUE;
  13896. }
  13897. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13898. {
  13899. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13901. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13902. {
  13903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13904. }
  13905. else
  13906. {
  13907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13908. }
  13909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13910. isKnowKey = TRUE;
  13911. }
  13912. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  13913. {
  13914. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  13915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  13916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  13917. {
  13918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  13919. }
  13920. else
  13921. {
  13922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  13923. }
  13924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  13925. isKnowKey = TRUE;
  13926. }
  13927. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  13928. {
  13929. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  13930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  13931. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  13932. {
  13933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  13934. }
  13935. else
  13936. {
  13937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  13938. }
  13939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  13940. isKnowKey = TRUE;
  13941. }
  13942. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  13943. {
  13944. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  13945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  13946. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  13947. {
  13948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  13949. }
  13950. else
  13951. {
  13952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  13953. }
  13954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  13955. isKnowKey = TRUE;
  13956. }
  13957. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13958. {
  13959. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13961. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13962. {
  13963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13964. }
  13965. else
  13966. {
  13967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13968. }
  13969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13970. isKnowKey = TRUE;
  13971. }
  13972. #if 1
  13973. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13974. {
  13975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13977. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13978. {
  13979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13980. }
  13981. else
  13982. {
  13983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13984. }
  13985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13986. isKnowKey = TRUE;
  13987. }
  13988. #endif
  13989. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13990. {
  13991. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13993. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13994. {
  13995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13996. }
  13997. else
  13998. {
  13999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14000. }
  14001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14002. isKnowKey = TRUE;
  14003. }
  14004. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14005. {
  14006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14008. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14009. {
  14010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14011. }
  14012. else
  14013. {
  14014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14015. }
  14016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14017. isKnowKey = TRUE;
  14018. }
  14019. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14020. {
  14021. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14023. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14024. {
  14025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14026. }
  14027. else
  14028. {
  14029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14030. }
  14031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14032. isKnowKey = TRUE;
  14033. }
  14034. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14035. {
  14036. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14038. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14039. {
  14040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14041. }
  14042. else
  14043. {
  14044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14045. }
  14046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14047. isKnowKey = TRUE;
  14048. }
  14049. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14050. {
  14051. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14053. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14054. {
  14055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14056. }
  14057. else
  14058. {
  14059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14060. }
  14061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14062. isKnowKey = TRUE;
  14063. }
  14064. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14065. {
  14066. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14068. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14069. {
  14070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14071. }
  14072. else
  14073. {
  14074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14075. }
  14076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14077. isKnowKey = TRUE;
  14078. }
  14079. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14080. {
  14081. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14083. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14084. {
  14085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14086. }
  14087. else
  14088. {
  14089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14090. }
  14091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14092. isKnowKey = TRUE;
  14093. }
  14094. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14095. {
  14096. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14098. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14099. {
  14100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14101. }
  14102. else
  14103. {
  14104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14105. }
  14106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14107. isKnowKey = TRUE;
  14108. }
  14109. //=========================================================
  14110. if(!isEmpty && !isKnowKey)
  14111. {
  14112. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14113. strcpy(unknownkey[UnknownKeynum], keyReq);
  14114. UnknownKeynum = UnknownKeynum + 1;
  14115. }
  14116. }
  14117. void processUnkownKey(void)
  14118. {
  14119. DEBUG_INFO("processUnkownKey...\n");
  14120. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14121. for(int index=0; index < UnknownKeynum; index++)
  14122. {
  14123. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14124. {
  14125. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14126. }
  14127. }
  14128. }
  14129. int setKeyValue(char *key, char *value)
  14130. {
  14131. int isSuccess = NotSupported;
  14132. int check_ascii=0;
  14133. char str[256]={0};
  14134. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14135. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14136. {
  14137. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14139. {
  14140. strcpy(str, (const char*)value);
  14141. for(int i = 0; str[i]; i++){
  14142. str[i] = tolower(str[i]);
  14143. }
  14144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14145. isSuccess = ConfigurationStatus_Accepted;
  14146. }
  14147. else
  14148. {
  14149. isSuccess = ConfigurationStatus_Rejected;
  14150. }
  14151. }
  14152. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14153. {
  14154. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14156. {
  14157. strcpy(str, (const char*)value);
  14158. for(int i = 0; str[i]; i++){
  14159. str[i] = tolower(str[i]);
  14160. }
  14161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14162. isSuccess = ConfigurationStatus_Accepted;
  14163. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14164. }
  14165. else
  14166. {
  14167. isSuccess = ConfigurationStatus_Rejected;
  14168. }
  14169. }
  14170. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14171. {
  14172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14173. {
  14174. strcpy(str, (const char*)value);
  14175. for(int i = 0; str[i]; i++)
  14176. {
  14177. str[i] = tolower(str[i]);
  14178. }
  14179. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14181. isSuccess = ConfigurationStatus_Accepted;
  14182. }
  14183. else
  14184. {
  14185. isSuccess = ConfigurationStatus_Rejected;
  14186. }
  14187. }
  14188. if(strcmp(key, "BlinkRepeat") == 0)
  14189. {
  14190. //Charger.BlinkRepeat = Integer.parseInt(value);
  14191. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14192. {
  14193. check_ascii = value[0];
  14194. if( (check_ascii < 48) || (check_ascii > 57) )
  14195. {
  14196. isSuccess = ConfigurationStatus_Rejected;
  14197. }
  14198. else
  14199. {
  14200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14201. isSuccess = ConfigurationStatus_Accepted;
  14202. }
  14203. }
  14204. else
  14205. {
  14206. isSuccess = ConfigurationStatus_Rejected;
  14207. }
  14208. }
  14209. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14210. {
  14211. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14212. {
  14213. check_ascii = value[0];
  14214. if( (check_ascii < 48) || (check_ascii > 57) )
  14215. {
  14216. isSuccess = ConfigurationStatus_Rejected;
  14217. }
  14218. else
  14219. {
  14220. if((atoi(value) == 0) || (atoi(value) >= 10))
  14221. {
  14222. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14224. isSuccess = ConfigurationStatus_Accepted;
  14225. }
  14226. else
  14227. isSuccess = ConfigurationStatus_Rejected;
  14228. }
  14229. }
  14230. else
  14231. {
  14232. isSuccess = ConfigurationStatus_Rejected;
  14233. }
  14234. }
  14235. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14236. {
  14237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14238. {
  14239. check_ascii = value[0];
  14240. if( (check_ascii < 48) || (check_ascii > 57) )
  14241. {
  14242. isSuccess = ConfigurationStatus_Rejected;
  14243. }
  14244. else
  14245. {
  14246. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14248. isSuccess = ConfigurationStatus_Accepted;
  14249. }
  14250. }
  14251. else
  14252. {
  14253. isSuccess = ConfigurationStatus_Rejected;
  14254. }
  14255. }
  14256. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14257. {
  14258. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14259. {
  14260. check_ascii = value[0];
  14261. if( (check_ascii < 48) || (check_ascii > 57) )
  14262. {
  14263. isSuccess = ConfigurationStatus_Rejected;
  14264. }
  14265. else
  14266. {
  14267. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14269. isSuccess = ConfigurationStatus_Accepted;
  14270. }
  14271. }
  14272. else
  14273. {
  14274. isSuccess = ConfigurationStatus_Rejected;
  14275. }
  14276. }
  14277. if(strcmp(key, "HeartbeatInterval") == 0)
  14278. {
  14279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14280. {
  14281. check_ascii = value[0];
  14282. if( (check_ascii < 48) || (check_ascii > 57) )
  14283. {
  14284. isSuccess = ConfigurationStatus_Rejected;
  14285. }
  14286. else
  14287. {
  14288. if((atoi(value) == 0) || (atoi(value) >= 10))
  14289. {
  14290. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14292. HeartBeatWaitTime = atoi(value);
  14293. isSuccess = ConfigurationStatus_Accepted;
  14294. }
  14295. else
  14296. {
  14297. isSuccess = ConfigurationStatus_Rejected;
  14298. }
  14299. }
  14300. }
  14301. else
  14302. {
  14303. isSuccess = ConfigurationStatus_Rejected;
  14304. }
  14305. }
  14306. if(strcmp(key, "LightIntensity") == 0)
  14307. {
  14308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14309. {
  14310. check_ascii = value[0];
  14311. if( (check_ascii < 48) || (check_ascii > 57) )
  14312. {
  14313. isSuccess = ConfigurationStatus_Rejected;
  14314. }
  14315. else
  14316. {
  14317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14318. isSuccess = ConfigurationStatus_Accepted;
  14319. }
  14320. }
  14321. else
  14322. {
  14323. isSuccess = ConfigurationStatus_Rejected;
  14324. }
  14325. }
  14326. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14327. {
  14328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14329. {
  14330. strcpy(str, (const char*)value);
  14331. for(int i = 0; str[i]; i++)
  14332. {
  14333. str[i] = tolower(str[i]);
  14334. }
  14335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14336. isSuccess = ConfigurationStatus_Accepted;
  14337. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14338. }
  14339. else
  14340. {
  14341. isSuccess = ConfigurationStatus_Rejected;
  14342. }
  14343. }
  14344. if(strcmp(key, "LocalPreAuthorize") == 0)
  14345. {
  14346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14347. {
  14348. strcpy(str, (const char*)value);
  14349. for(int i = 0; str[i]; i++)
  14350. {
  14351. str[i] = tolower(str[i]);
  14352. }
  14353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14354. isSuccess = ConfigurationStatus_Accepted;
  14355. }
  14356. else
  14357. {
  14358. isSuccess = ConfigurationStatus_Rejected;
  14359. }
  14360. }
  14361. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14362. {
  14363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14364. {
  14365. check_ascii = value[0];
  14366. if( (check_ascii < 48) || (check_ascii > 57) )
  14367. {
  14368. isSuccess = ConfigurationStatus_Rejected;
  14369. }
  14370. else
  14371. {
  14372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14373. isSuccess = ConfigurationStatus_Accepted;
  14374. }
  14375. }
  14376. else
  14377. {
  14378. isSuccess = ConfigurationStatus_Rejected;
  14379. }
  14380. }
  14381. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14382. {
  14383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14384. {
  14385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14386. isSuccess = ConfigurationStatus_Accepted;
  14387. }
  14388. else
  14389. {
  14390. isSuccess = ConfigurationStatus_Rejected;
  14391. }
  14392. }
  14393. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14394. {
  14395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14396. {
  14397. check_ascii = value[0];
  14398. if( (check_ascii < 48) || (check_ascii > 57) )
  14399. {
  14400. isSuccess = ConfigurationStatus_Rejected;
  14401. }
  14402. else
  14403. {
  14404. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14406. isSuccess = ConfigurationStatus_Accepted;
  14407. }
  14408. }
  14409. else
  14410. {
  14411. isSuccess = ConfigurationStatus_Rejected;
  14412. }
  14413. }
  14414. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14415. {
  14416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14417. {
  14418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14419. isSuccess = ConfigurationStatus_Accepted;
  14420. }
  14421. else
  14422. {
  14423. isSuccess = ConfigurationStatus_Rejected;
  14424. }
  14425. }
  14426. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14427. {
  14428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14429. {
  14430. check_ascii = value[0];
  14431. if( (check_ascii < 48) || (check_ascii > 57) )
  14432. {
  14433. isSuccess = ConfigurationStatus_Rejected;
  14434. }
  14435. else
  14436. {
  14437. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14439. isSuccess = ConfigurationStatus_Accepted;
  14440. }
  14441. }
  14442. else
  14443. {
  14444. isSuccess = ConfigurationStatus_Rejected;
  14445. }
  14446. }
  14447. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14448. {
  14449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14450. {
  14451. check_ascii = value[0];
  14452. if( (check_ascii < 48) || (check_ascii > 57) )
  14453. {
  14454. isSuccess = ConfigurationStatus_Rejected;
  14455. }
  14456. else
  14457. {
  14458. if((atoi(value) == 0) || (atoi(value) >= 10))
  14459. {
  14460. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14462. isSuccess = ConfigurationStatus_Accepted;
  14463. }
  14464. else
  14465. {
  14466. isSuccess = ConfigurationStatus_Rejected;
  14467. }
  14468. }
  14469. }
  14470. else
  14471. {
  14472. isSuccess = ConfigurationStatus_Rejected;
  14473. }
  14474. }
  14475. if(strcmp(key, "MinimumStatusDuration") == 0)
  14476. {
  14477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14478. {
  14479. check_ascii = value[0];
  14480. if( (check_ascii < 48) || (check_ascii > 57) )
  14481. {
  14482. isSuccess = ConfigurationStatus_Rejected;
  14483. }
  14484. else
  14485. {
  14486. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14487. {
  14488. isSuccess = ConfigurationStatus_Rejected;
  14489. }
  14490. else
  14491. {
  14492. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14494. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14495. isSuccess = ConfigurationStatus_Accepted;
  14496. }
  14497. }
  14498. }
  14499. else
  14500. {
  14501. isSuccess = ConfigurationStatus_Rejected;
  14502. }
  14503. }
  14504. if(strcmp(key, "NumberOfConnectors") == 0)
  14505. {
  14506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14507. {
  14508. check_ascii = value[0];
  14509. if( (check_ascii < 48) || (check_ascii > 57) )
  14510. {
  14511. isSuccess = ConfigurationStatus_Rejected;
  14512. }
  14513. else
  14514. {
  14515. //Charger.ResetRetries = Integer.parseInt(value);
  14516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14517. isSuccess = ConfigurationStatus_Accepted;
  14518. }
  14519. }
  14520. else
  14521. {
  14522. isSuccess = ConfigurationStatus_Rejected;
  14523. }
  14524. }
  14525. if(strcmp(key, "ResetRetries") == 0)
  14526. {
  14527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14528. {
  14529. check_ascii = value[0];
  14530. if( (check_ascii < 48) || (check_ascii > 57) )
  14531. {
  14532. isSuccess = ConfigurationStatus_Rejected;
  14533. }
  14534. else
  14535. {
  14536. //Charger.ResetRetries = Integer.parseInt(value);
  14537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14538. isSuccess = ConfigurationStatus_Accepted;
  14539. }
  14540. }
  14541. else
  14542. {
  14543. isSuccess = ConfigurationStatus_Rejected;
  14544. }
  14545. }
  14546. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14547. {
  14548. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14549. {
  14550. strcpy(str, (const char*)value);
  14551. for(int i = 0; str[i]; i++)
  14552. {
  14553. str[i] = tolower(str[i]);
  14554. }
  14555. if(strcmp(str, "notapplicable")== 0)
  14556. {
  14557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14558. isSuccess = ConfigurationStatus_Accepted;
  14559. }
  14560. else if(strcmp(str, "unknown")== 0)
  14561. {
  14562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14563. isSuccess = ConfigurationStatus_Accepted;
  14564. }
  14565. else if(strcmp(str, "rst")== 0)
  14566. {
  14567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14568. isSuccess = ConfigurationStatus_Accepted;
  14569. }
  14570. else if(strcmp(str, "rts")== 0)
  14571. {
  14572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14573. isSuccess = ConfigurationStatus_Accepted;
  14574. }
  14575. else if(strcmp(str, "srt")== 0)
  14576. {
  14577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14578. isSuccess = ConfigurationStatus_Accepted;
  14579. }
  14580. else if(strcmp(str, "str")== 0)
  14581. {
  14582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14583. isSuccess = ConfigurationStatus_Accepted;
  14584. }
  14585. else if(strcmp(str, "trs")== 0)
  14586. {
  14587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14588. isSuccess = ConfigurationStatus_Accepted;
  14589. }
  14590. else if(strcmp(str, "tsr")== 0)
  14591. {
  14592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14593. isSuccess = ConfigurationStatus_Accepted;
  14594. }
  14595. else
  14596. {
  14597. isSuccess = ConfigurationStatus_Rejected;
  14598. }
  14599. }
  14600. else
  14601. {
  14602. isSuccess = ConfigurationStatus_Rejected;
  14603. }
  14604. }
  14605. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14606. {
  14607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14608. {
  14609. check_ascii = value[0];
  14610. if( (check_ascii < 48) || (check_ascii > 57) )
  14611. {
  14612. isSuccess = ConfigurationStatus_Rejected;
  14613. }
  14614. else
  14615. {
  14616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14617. isSuccess = ConfigurationStatus_Accepted;
  14618. }
  14619. }
  14620. else
  14621. {
  14622. isSuccess = ConfigurationStatus_Rejected;
  14623. }
  14624. }
  14625. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14626. {
  14627. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14628. {
  14629. strcpy(str, (const char*)value);
  14630. for(int i = 0; str[i]; i++)
  14631. {
  14632. str[i] = tolower(str[i]);
  14633. }
  14634. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14636. isSuccess = ConfigurationStatus_Accepted;
  14637. }
  14638. else
  14639. {
  14640. isSuccess = ConfigurationStatus_Rejected;
  14641. }
  14642. }
  14643. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14644. {
  14645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14646. {
  14647. strcpy(str, (const char*)value);
  14648. for(int i = 0; str[i]; i++)
  14649. {
  14650. str[i] = tolower(str[i]);
  14651. }
  14652. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14654. isSuccess = ConfigurationStatus_Accepted;
  14655. }
  14656. else
  14657. {
  14658. isSuccess = ConfigurationStatus_Rejected;
  14659. }
  14660. }
  14661. if(strcmp(key, "StopTxnAlignedData") == 0)
  14662. {
  14663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14664. {
  14665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14666. isSuccess = ConfigurationStatus_Accepted;
  14667. }
  14668. else
  14669. {
  14670. isSuccess = ConfigurationStatus_Rejected;
  14671. }
  14672. }
  14673. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14674. {
  14675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14676. {
  14677. check_ascii = value[0];
  14678. if( (check_ascii < 48) || (check_ascii > 57) )
  14679. {
  14680. isSuccess = ConfigurationStatus_Rejected;
  14681. }
  14682. else
  14683. {
  14684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14685. isSuccess = ConfigurationStatus_Accepted;
  14686. }
  14687. }
  14688. else
  14689. {
  14690. isSuccess = ConfigurationStatus_Rejected;
  14691. }
  14692. }
  14693. if(strcmp(key, "StopTxnSampledData") == 0)
  14694. {
  14695. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14696. {
  14697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14698. isSuccess = ConfigurationStatus_Accepted;
  14699. }
  14700. else
  14701. {
  14702. isSuccess = ConfigurationStatus_Rejected;
  14703. }
  14704. }
  14705. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14706. {
  14707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14708. {
  14709. check_ascii = value[0];
  14710. if( (check_ascii < 48) || (check_ascii > 57) )
  14711. {
  14712. isSuccess = ConfigurationStatus_Rejected;
  14713. }
  14714. else
  14715. {
  14716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14717. isSuccess = ConfigurationStatus_Accepted;
  14718. }
  14719. }
  14720. else
  14721. {
  14722. isSuccess = ConfigurationStatus_Rejected;
  14723. }
  14724. }
  14725. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14726. {
  14727. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14728. {
  14729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14730. isSuccess = ConfigurationStatus_Accepted;
  14731. }
  14732. else
  14733. {
  14734. isSuccess = ConfigurationStatus_Rejected;
  14735. }
  14736. }
  14737. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14738. {
  14739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14740. {
  14741. check_ascii = value[0];
  14742. if( (check_ascii < 48) || (check_ascii > 57) )
  14743. {
  14744. isSuccess = ConfigurationStatus_Rejected;
  14745. }
  14746. else
  14747. {
  14748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14749. isSuccess = ConfigurationStatus_Accepted;
  14750. }
  14751. }
  14752. else
  14753. {
  14754. isSuccess = ConfigurationStatus_Rejected;
  14755. }
  14756. }
  14757. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14758. {
  14759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14760. {
  14761. check_ascii = value[0];
  14762. if( (check_ascii < 48) || (check_ascii > 57) )
  14763. {
  14764. isSuccess = ConfigurationStatus_Rejected;
  14765. }
  14766. else
  14767. {
  14768. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14770. TransactionMessageAttemptsValue = atoi(value);
  14771. isSuccess = ConfigurationStatus_Accepted;
  14772. }
  14773. }
  14774. else
  14775. {
  14776. isSuccess = ConfigurationStatus_Rejected;
  14777. }
  14778. }
  14779. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14780. {
  14781. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14782. {
  14783. check_ascii = value[0];
  14784. if( (check_ascii < 48) || (check_ascii > 57) )
  14785. {
  14786. isSuccess = ConfigurationStatus_Rejected;
  14787. }
  14788. else
  14789. {
  14790. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14792. TransactionMessageRetryIntervalValue = atoi(value);
  14793. isSuccess = ConfigurationStatus_Accepted;
  14794. }
  14795. }
  14796. else
  14797. {
  14798. isSuccess = ConfigurationStatus_Rejected;
  14799. }
  14800. }
  14801. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14802. {
  14803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14804. {
  14805. strcpy(str, (const char*)value);
  14806. for(int i = 0; str[i]; i++)
  14807. {
  14808. str[i] = tolower(str[i]);
  14809. }
  14810. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14812. isSuccess = ConfigurationStatus_Accepted;
  14813. }
  14814. else
  14815. {
  14816. isSuccess = ConfigurationStatus_Rejected;
  14817. }
  14818. }
  14819. if(strcmp(key, "WebSocketPingInterval") == 0)
  14820. {
  14821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14822. {
  14823. check_ascii = value[0];
  14824. if( (check_ascii < 48) || (check_ascii > 57) )
  14825. {
  14826. isSuccess = ConfigurationStatus_Rejected;
  14827. }
  14828. else
  14829. {
  14830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14831. isSuccess = ConfigurationStatus_Accepted;
  14832. }
  14833. }
  14834. else
  14835. {
  14836. isSuccess = ConfigurationStatus_Rejected;
  14837. }
  14838. }
  14839. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  14840. {
  14841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14842. {
  14843. strcpy(str, (const char*)value);
  14844. for(int i = 0; str[i]; i++)
  14845. {
  14846. str[i] = tolower(str[i]);
  14847. }
  14848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14849. isSuccess = ConfigurationStatus_Accepted;
  14850. }
  14851. else
  14852. {
  14853. isSuccess = ConfigurationStatus_Rejected;
  14854. }
  14855. }
  14856. if(strcmp(key, "AuthorizationKey") == 0)
  14857. {
  14858. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14859. {
  14860. strcpy(str, (const char*)value);
  14861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14862. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14863. isSuccess = ConfigurationStatus_Accepted;
  14864. }
  14865. else
  14866. {
  14867. isSuccess = ConfigurationStatus_Rejected;
  14868. }
  14869. }
  14870. if(strcmp(key, "SecurityProfile") == 0)
  14871. {
  14872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14873. {
  14874. check_ascii = value[0];
  14875. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14876. {
  14877. isSuccess = ConfigurationStatus_Rejected;
  14878. }
  14879. else if(check_ascii == 0x33)
  14880. {
  14881. isSuccess = NotSupported;
  14882. }
  14883. else
  14884. {
  14885. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14886. {
  14887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14888. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14889. isSuccess = ConfigurationStatus_Accepted;
  14890. }
  14891. else
  14892. isSuccess = ConfigurationStatus_Rejected;
  14893. }
  14894. }
  14895. else
  14896. {
  14897. isSuccess = ConfigurationStatus_Rejected;
  14898. }
  14899. }
  14900. if(strcmp(key, "DefaultPrice") == 0)
  14901. {
  14902. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14903. {
  14904. strcpy(str, (const char*)value);
  14905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14906. isSuccess = ConfigurationStatus_Accepted;
  14907. }
  14908. else
  14909. {
  14910. isSuccess = ConfigurationStatus_Rejected;
  14911. }
  14912. }
  14913. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14914. {
  14915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14916. {
  14917. strcpy(str, (const char*)value);
  14918. for(int i = 0; str[i]; i++)
  14919. {
  14920. str[i] = tolower(str[i]);
  14921. }
  14922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14923. isSuccess = ConfigurationStatus_Accepted;
  14924. }
  14925. else
  14926. {
  14927. isSuccess = ConfigurationStatus_Rejected;
  14928. }
  14929. }
  14930. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14931. {
  14932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14933. {
  14934. strcpy(str, (const char*)value);
  14935. for(int i = 0; str[i]; i++)
  14936. {
  14937. str[i] = tolower(str[i]);
  14938. }
  14939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14940. isSuccess = ConfigurationStatus_Accepted;
  14941. }
  14942. else
  14943. {
  14944. isSuccess = ConfigurationStatus_Rejected;
  14945. }
  14946. }
  14947. if(strcmp(key, "TimeOffset") == 0)
  14948. {
  14949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14950. {
  14951. strcpy(str, (const char*)value);
  14952. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  14953. isSuccess = ConfigurationStatus_Accepted;
  14954. }
  14955. else
  14956. {
  14957. isSuccess = ConfigurationStatus_Rejected;
  14958. }
  14959. }
  14960. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  14961. {
  14962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14963. {
  14964. strcpy(str, (const char*)value);
  14965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  14966. isSuccess = ConfigurationStatus_Accepted;
  14967. }
  14968. else
  14969. {
  14970. isSuccess = ConfigurationStatus_Rejected;
  14971. }
  14972. }
  14973. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  14974. {
  14975. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14976. {
  14977. strcpy(str, (const char*)value);
  14978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  14979. isSuccess = ConfigurationStatus_Accepted;
  14980. }
  14981. else
  14982. {
  14983. isSuccess = ConfigurationStatus_Rejected;
  14984. }
  14985. }
  14986. #if 0
  14987. //For OCPP Test Case
  14988. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14989. {
  14990. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14991. {
  14992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14993. isSuccess = ConfigurationStatus_Accepted;
  14994. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14995. }
  14996. else
  14997. {
  14998. isSuccess = ConfigurationStatus_Rejected;
  14999. }
  15000. }
  15001. #endif
  15002. #if 1
  15003. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15004. {
  15005. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15006. {
  15007. strcpy(str, (const char*)value);
  15008. for(int i = 0; str[i]; i++)
  15009. {
  15010. str[i] = tolower(str[i]);
  15011. }
  15012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15013. isSuccess = ConfigurationStatus_Accepted;
  15014. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15015. }
  15016. else
  15017. {
  15018. isSuccess = ConfigurationStatus_Rejected;
  15019. }
  15020. }
  15021. #endif
  15022. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15023. {
  15024. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15025. {
  15026. check_ascii = value[0];
  15027. if( (check_ascii < 48) || (check_ascii > 57) )
  15028. {
  15029. isSuccess = ConfigurationStatus_Rejected;
  15030. }
  15031. else
  15032. {
  15033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15034. isSuccess = ConfigurationStatus_Accepted;
  15035. }
  15036. }
  15037. else
  15038. {
  15039. isSuccess = ConfigurationStatus_Rejected;
  15040. }
  15041. }
  15042. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15043. {
  15044. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15045. {
  15046. check_ascii = value[0];
  15047. if( (check_ascii < 48) || (check_ascii > 57) )
  15048. {
  15049. isSuccess = ConfigurationStatus_Rejected;
  15050. }
  15051. else
  15052. {
  15053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15054. isSuccess = ConfigurationStatus_Accepted;
  15055. }
  15056. }
  15057. else
  15058. {
  15059. isSuccess = ConfigurationStatus_Rejected;
  15060. }
  15061. }
  15062. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15063. {
  15064. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15065. {
  15066. strcpy(str, (const char*)value);
  15067. for(int i = 0; str[i]; i++)
  15068. {
  15069. str[i] = tolower(str[i]);
  15070. }
  15071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15072. isSuccess = ConfigurationStatus_Accepted;
  15073. }
  15074. else
  15075. {
  15076. isSuccess = ConfigurationStatus_Rejected;
  15077. }
  15078. }
  15079. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15080. {
  15081. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15082. {
  15083. check_ascii = value[0];
  15084. if( (check_ascii < 48) || (check_ascii > 57) )
  15085. {
  15086. isSuccess = ConfigurationStatus_Rejected;
  15087. }
  15088. else
  15089. {
  15090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15091. isSuccess = ConfigurationStatus_Accepted;
  15092. }
  15093. }
  15094. else
  15095. {
  15096. isSuccess = ConfigurationStatus_Rejected;
  15097. }
  15098. }
  15099. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15100. {
  15101. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15102. {
  15103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15104. isSuccess = ConfigurationStatus_Accepted;
  15105. }
  15106. else
  15107. {
  15108. isSuccess = ConfigurationStatus_Rejected;
  15109. }
  15110. }
  15111. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15112. {
  15113. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15114. {
  15115. check_ascii = value[0];
  15116. if( (check_ascii < 48) || (check_ascii > 57) )
  15117. {
  15118. isSuccess = ConfigurationStatus_Rejected;
  15119. }
  15120. else
  15121. {
  15122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15123. isSuccess = ConfigurationStatus_Accepted;
  15124. }
  15125. }
  15126. else
  15127. {
  15128. isSuccess = ConfigurationStatus_Rejected;
  15129. }
  15130. }
  15131. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15132. {
  15133. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15134. {
  15135. strcpy(str, (const char*)value);
  15136. for(int i = 0; str[i]; i++)
  15137. {
  15138. str[i] = tolower(str[i]);
  15139. }
  15140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15141. isSuccess = ConfigurationStatus_Accepted;
  15142. }
  15143. else
  15144. {
  15145. isSuccess = ConfigurationStatus_Rejected;
  15146. }
  15147. }
  15148. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15149. {
  15150. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15151. {
  15152. check_ascii = value[0];
  15153. if( (check_ascii < 48) || (check_ascii > 57) )
  15154. {
  15155. isSuccess = ConfigurationStatus_Rejected;
  15156. }
  15157. else
  15158. {
  15159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15160. isSuccess = ConfigurationStatus_Accepted;
  15161. }
  15162. }
  15163. else
  15164. {
  15165. isSuccess = ConfigurationStatus_Rejected;
  15166. }
  15167. }
  15168. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15169. return isSuccess;
  15170. }
  15171. int TransactionMessageAttemptsGet(void)
  15172. {
  15173. return TransactionMessageAttemptsValue;
  15174. }
  15175. int FirstHeartBeatResponse(void)
  15176. {
  15177. return FirstHeartBeat;
  15178. }
  15179. int TransactionMessageRetryIntervalGet(void)
  15180. {
  15181. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15182. }
  15183. int ReadHttpStatus(int sock)
  15184. {
  15185. //char c;
  15186. char buff[1024]="",*ptr=buff+1;
  15187. int bytes_received, status;
  15188. DEBUG_INFO("Begin Response ..\n");
  15189. while((bytes_received = recv(sock, ptr, 1, 0))){
  15190. if(bytes_received==-1){
  15191. perror("ReadHttpStatus");
  15192. exit(1);
  15193. }
  15194. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15195. ptr++;
  15196. }
  15197. *ptr=0;
  15198. ptr=buff+1;
  15199. sscanf(ptr,"%*s %d ", &status);
  15200. DEBUG_INFO("%s\n",ptr);
  15201. DEBUG_INFO("status=%d\n",status);
  15202. DEBUG_INFO("End Response ..\n");
  15203. return (bytes_received>0)?status:0;
  15204. }
  15205. //the only filed that it parsed is 'Content-Length'
  15206. int ParseHeader(int sock)
  15207. {
  15208. //char c;
  15209. char buff[1024]="",*ptr=buff+4;
  15210. int bytes_received;
  15211. DEBUG_INFO("Begin HEADER ..\n");
  15212. while((bytes_received = recv(sock, ptr, 1, 0))){
  15213. if(bytes_received==-1){
  15214. perror("Parse Header");
  15215. exit(1);
  15216. }
  15217. if(
  15218. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15219. (ptr[-1]=='\r') && (*ptr=='\n' )
  15220. ) break;
  15221. ptr++;
  15222. }
  15223. *ptr=0;
  15224. ptr=buff+4;
  15225. //printf("%s",ptr);
  15226. if(bytes_received){
  15227. ptr=strstr(ptr,"Content-Length:");
  15228. if(ptr){
  15229. sscanf(ptr,"%*s %d",&bytes_received);
  15230. }else
  15231. bytes_received=-1; //unknown size
  15232. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15233. }
  15234. DEBUG_INFO("End HEADER ..\n");
  15235. return bytes_received ;
  15236. }
  15237. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15238. {
  15239. int result = TRUE;
  15240. char rmFileCmd[100]={0};
  15241. char FilePath[100]={0};
  15242. char ftpbuf[200];
  15243. int systemresult;
  15244. sprintf(FilePath,"/mnt/%s",filename);
  15245. system("ping 8.8.8.8 &");
  15246. if((access(FilePath,F_OK))!=-1)
  15247. {
  15248. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15249. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15250. system(rmFileCmd);
  15251. }
  15252. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15253. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15254. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15255. systemresult = system(ftpbuf);
  15256. if(systemresult != 0)
  15257. {
  15258. DEBUG_INFO("http DownLoad error!\n");
  15259. result = FALSE;
  15260. }
  15261. system("pkill ping");
  15262. return result;
  15263. }
  15264. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15265. {
  15266. int result = TRUE;
  15267. char rmFileCmd[100]={0};
  15268. char FilePath[100]={0};
  15269. char ftpbuf[200];
  15270. int systemresult;
  15271. sprintf(FilePath,"/mnt/%s",filename);
  15272. system("ping 8.8.8.8 &");
  15273. if((access(FilePath,F_OK))!=-1)
  15274. {
  15275. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15276. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15277. system(rmFileCmd);
  15278. }
  15279. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15280. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15281. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15282. systemresult = system(ftpbuf);
  15283. if(systemresult != 0)
  15284. {
  15285. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15286. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15287. systemresult = system(ftpbuf);
  15288. if(systemresult != 0)
  15289. {
  15290. DEBUG_WARN("wget error!\n");
  15291. result = FALSE;
  15292. }
  15293. }
  15294. system("pkill ping");
  15295. return result;
  15296. }
  15297. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15298. {
  15299. char rmFileCmd[100]={0};
  15300. char FilePath[100]={0};
  15301. char buf[512];
  15302. int systemresult = 0;
  15303. //DEBUG_INFO("filename=%s\n",filename);
  15304. //DEBUG_INFO("url=%s\n",url);
  15305. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15306. if((access(FilePath,F_OK))!=-1)
  15307. {
  15308. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15309. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15310. system(rmFileCmd);
  15311. }
  15312. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15313. if(fp == NULL)
  15314. {
  15315. DEBUG_INFO("log is NULL\n");
  15316. return FALSE;
  15317. }
  15318. else
  15319. {
  15320. fprintf(fp, "%s\n", url);
  15321. fprintf(fp, "%s\n", filename);
  15322. fclose(fp);
  15323. }
  15324. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15325. if(phpFP == NULL)
  15326. {
  15327. DEBUG_INFO("PHP upload fail.\n");
  15328. return FALSE;
  15329. }
  15330. else
  15331. {
  15332. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15333. {
  15334. if(strstr(buf, "result") != NULL)
  15335. {
  15336. sscanf(buf, "result: %d", &systemresult);
  15337. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15338. }
  15339. }
  15340. pclose(phpFP);
  15341. }
  15342. if(systemresult != 1)
  15343. {
  15344. DEBUG_INFO("HTTP upload error!\n");
  15345. return FALSE;
  15346. }
  15347. return TRUE;
  15348. }
  15349. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15350. {
  15351. struct hostent* server;
  15352. char *IPbuffer;
  15353. char ftpbuf[200];
  15354. int systemresult;
  15355. // To retrieve host information
  15356. server = gethostbyname(location);
  15357. // To convert an Internet network
  15358. // address into ASCII string
  15359. IPbuffer = inet_ntoa(*((struct in_addr*)
  15360. server->h_addr_list[0]));
  15361. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15362. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15363. /* format : ftpput -u username -p passwd IP target source*/
  15364. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15365. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15366. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15367. systemresult = system(ftpbuf);
  15368. DEBUG_INFO("systemresult=%d\n",systemresult);
  15369. if(systemresult != 0)
  15370. {
  15371. DEBUG_INFO("ftpput error!\n");
  15372. return FALSE;
  15373. }
  15374. return TRUE;
  15375. }
  15376. int GetOcppServerURL()
  15377. {
  15378. int result = FALSE;
  15379. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15380. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15381. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15382. struct yuarel url;
  15383. char urlStr[512];
  15384. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15385. {
  15386. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15387. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15388. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15389. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15390. if(yuarel_parse(&url, urlStr) != -1)
  15391. {
  15392. sprintf(OcppProtocol, "%s", url.scheme);
  15393. sprintf(OcppHost, "%s", url.host);
  15394. if(url.path == NULL)
  15395. OcppTempPath[0] = '\0';
  15396. else
  15397. {
  15398. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15399. {
  15400. sprintf(OcppTempPath, "%s/", url.path);
  15401. }
  15402. else
  15403. {
  15404. sprintf(OcppTempPath, "%s", url.path);
  15405. }
  15406. }
  15407. if(url.port == 0)
  15408. {
  15409. if(strcmp(OcppProtocol, "wss") == 0)
  15410. OcppPort = 443;
  15411. else
  15412. OcppPort = 80;
  15413. }
  15414. else
  15415. OcppPort = url.port;
  15416. result = TRUE;
  15417. }
  15418. }
  15419. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15420. {
  15421. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15422. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15423. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15424. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15425. if(yuarel_parse(&url, urlStr) != -1)
  15426. {
  15427. sprintf(OcppProtocol, "%s", url.scheme);
  15428. sprintf(OcppHost, "%s", url.host);
  15429. if(url.path == NULL)
  15430. OcppTempPath[0] = '\0';
  15431. else
  15432. sprintf(OcppTempPath, "%s", url.path);
  15433. if(url.port == 0)
  15434. {
  15435. if(strcmp(OcppProtocol, "wss") == 0)
  15436. OcppPort = 443;
  15437. else
  15438. OcppPort = 80;
  15439. }
  15440. else
  15441. OcppPort = url.port;
  15442. result = TRUE;
  15443. }
  15444. }
  15445. else
  15446. {
  15447. strcpy(OcppHost,"");
  15448. }
  15449. return result;
  15450. }
  15451. int GetOcppPath()
  15452. {
  15453. int result = FALSE;
  15454. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15455. {
  15456. if(OcppTempPath == NULL)
  15457. {
  15458. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15459. }
  15460. else
  15461. {
  15462. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15463. }
  15464. result = TRUE;
  15465. goto End;
  15466. }
  15467. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15468. {
  15469. if(OcppTempPath == NULL)
  15470. {
  15471. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15472. }
  15473. else
  15474. {
  15475. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15476. }
  15477. result = TRUE;
  15478. goto End;
  15479. }
  15480. else
  15481. {
  15482. strcpy(OcppPath,"");
  15483. }
  15484. End:
  15485. return result;
  15486. }
  15487. int GetOcppPort()
  15488. {
  15489. return OcppPort;
  15490. }
  15491. int GetOcppConnStatus(void)
  15492. {
  15493. return ShmOCPP16Data->OcppConnStatus;
  15494. }
  15495. void SetOcppConnStatus(uint8_t status)
  15496. {
  15497. ShmOCPP16Data->OcppConnStatus = status;
  15498. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15499. }
  15500. int GetHeartBeatWithNOResponse(void)
  15501. {
  15502. return HeartBeatWithNOResponse;
  15503. }
  15504. void SetHeartBeatWithNOResponse(void)
  15505. {
  15506. HeartBeatWithNOResponse = 0;
  15507. }
  15508. void GetStartTransactionIdTag(int gun_index)
  15509. {
  15510. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15511. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15512. }
  15513. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15514. {
  15515. char ch;
  15516. FILE *fptr1;
  15517. int temptransactionId;
  15518. char str[100]={0};
  15519. temptransactionId = 0;
  15520. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15521. {
  15522. DEBUG_INFO("IdTag is empty.\n");
  15523. return temptransactionId;
  15524. }
  15525. /*------ Read the file ----------------*/
  15526. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15527. if (!fptr1)
  15528. {
  15529. DEBUG_INFO("QueueTransactionId file open error.\n");
  15530. //printf(" File not found or unable to open the input file!!\n");
  15531. return temptransactionId;
  15532. }
  15533. ch=fgetc(fptr1);
  15534. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15535. rewind(fptr1);
  15536. if(ch!=EOF)
  15537. {
  15538. // printf("%c",ch);
  15539. while (fgets(str, 100, fptr1) != NULL)
  15540. {
  15541. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15542. if(str[0]=='\0')
  15543. {
  15544. break;
  15545. }
  15546. char *revbuf[8] = {0}; // Variable store string split
  15547. int num = 0;// Quantity after string split
  15548. DEBUG_INFO("Transaction queue data= %s\n", str);
  15549. splitstring(str,",",revbuf,&num); // String split
  15550. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15551. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15552. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15553. DEBUG_INFO("------------------------------\n");
  15554. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15555. {
  15556. if(isStopTransaction)
  15557. {
  15558. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15559. {
  15560. temptransactionId = atoi(revbuf[2]);
  15561. //break;
  15562. }
  15563. }
  15564. else
  15565. {
  15566. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15567. {
  15568. temptransactionId = atoi(revbuf[2]);
  15569. //break;
  15570. }
  15571. }
  15572. }
  15573. }
  15574. }
  15575. else
  15576. DEBUG_INFO("EOF\n");
  15577. fclose(fptr1);
  15578. /*------- End of reading ---------------*/
  15579. return temptransactionId;
  15580. }
  15581. void SetTransactionIdZero(int transactionId)
  15582. {
  15583. char ch;
  15584. FILE *fptr1, *fptr2;
  15585. int temptransactionId = 0;
  15586. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15587. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15588. if (!fptr1)
  15589. {
  15590. //printf(" File not found or unable to open the input file!!\n");
  15591. return ;
  15592. }
  15593. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15594. if (!fptr2)
  15595. {
  15596. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15597. fclose(fptr1);
  15598. return ;
  15599. }
  15600. ch=fgetc(fptr1);
  15601. rewind(fptr1);
  15602. if(ch!=EOF)
  15603. {
  15604. // copy all contents to the temporary file except the specific line
  15605. while (fgets(str, 100, fptr1) != NULL)
  15606. {
  15607. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15608. if(str[0]=='\0')
  15609. {
  15610. break;
  15611. }
  15612. char *revbuf[8] = {0};
  15613. int num = 0;
  15614. strcpy(strtemp, str);
  15615. splitstring(str,",",revbuf,&num);
  15616. if(revbuf[2][0] != '\0')
  15617. {
  15618. temptransactionId = atoi(revbuf[2]);
  15619. if(transactionId != temptransactionId)
  15620. {
  15621. fprintf(fptr2, "%s\n", strtemp);
  15622. }
  15623. }
  15624. }
  15625. }
  15626. fclose(fptr1);
  15627. fclose(fptr2);
  15628. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15629. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15630. /*------ Read the file ----------------*/
  15631. }
  15632. int InternetDisconnect(void)
  15633. {
  15634. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15635. }
  15636. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15637. void storeTempStopTransaction(int gun_index)
  15638. {
  15639. char guid[37]={0};
  15640. int tempIndex = 0;
  15641. char TempStopTransaction[256];
  15642. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15643. DEBUG_INFO("storeTempStopTransaction...\n");
  15644. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15645. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15646. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15647. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15648. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15649. {
  15650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15651. {
  15652. tempIndex = ((gun_index==2) ? 1: 0);
  15653. }
  15654. else
  15655. {
  15656. tempIndex = gun_index;
  15657. }
  15658. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15659. {
  15660. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15661. {
  15662. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15663. }
  15664. }// END OF CHAdeMO_QUANTITY
  15665. }
  15666. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15667. {
  15668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15669. {
  15670. tempIndex = ((gun_index==2) ? 1: 0);
  15671. }
  15672. else
  15673. {
  15674. tempIndex = gun_index;
  15675. }
  15676. for (int index = 0; index < CCS_QUANTITY; index++)
  15677. {
  15678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15679. {
  15680. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15681. }
  15682. }// END OF CCS_QUANTITY
  15683. }
  15684. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15685. {
  15686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15687. {
  15688. tempIndex = ((gun_index==2) ? 1: 0);
  15689. }
  15690. else
  15691. {
  15692. tempIndex = gun_index;
  15693. }
  15694. for (int index = 0; index < GB_QUANTITY; index++)
  15695. {
  15696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15697. {
  15698. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15699. }
  15700. }// END OF GB_QUANTITY
  15701. }
  15702. else if(gunType[gun_index] == GUN_TYPE_DO)
  15703. {
  15704. tempIndex = gun_index;
  15705. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15706. {
  15707. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15708. {
  15709. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15710. }
  15711. }
  15712. }
  15713. else
  15714. {
  15715. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15716. {
  15717. tempIndex = 2;
  15718. }
  15719. else
  15720. {
  15721. tempIndex = gun_index;
  15722. }
  15723. for (int index = 0; index < AC_QUANTITY; index++)
  15724. {
  15725. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15726. {
  15727. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15728. }
  15729. }// END OF AC_QUANTITY
  15730. }
  15731. //Stop Transaction Time
  15732. struct timeval tmnow;
  15733. struct tm *tm;
  15734. char buf[28];//, usec_buf[6];
  15735. gettimeofday(&tmnow, NULL);
  15736. time_t t;
  15737. t = time(NULL);
  15738. /*UTC time and date*/
  15739. tm = gmtime(&t);
  15740. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15742. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15744. random_uuid(guid);
  15745. /***********************************transactionData******************************************************/
  15746. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15748. //=================================
  15749. //1. Transaction_Begin
  15750. //=================================
  15751. //============================== Energy.Active.Import.Interval ===========================================
  15752. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15753. {
  15754. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15755. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  15758. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15759. 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))
  15760. {
  15761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15762. }
  15763. else
  15764. {
  15765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15766. }
  15767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15769. }
  15770. //=================================
  15771. //2. Transaction_End
  15772. //=================================
  15773. //2.1====================================== Current.Import L1 ==============================================
  15774. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15775. {
  15776. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15777. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15778. {
  15779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15780. {
  15781. tempIndex = ((gun_index==2) ? 1: 0);
  15782. }
  15783. else
  15784. {
  15785. tempIndex = gun_index;
  15786. }
  15787. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15788. {
  15789. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15790. {
  15791. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15792. }
  15793. }// End of for CHAdeMO_QUANTITY
  15794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15795. }
  15796. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15797. {
  15798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15799. {
  15800. tempIndex = ((gun_index==2) ? 1: 0);
  15801. }
  15802. else
  15803. {
  15804. tempIndex = gun_index;
  15805. }
  15806. for (int index = 0; index < CCS_QUANTITY; index++)
  15807. {
  15808. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15809. {
  15810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15811. }
  15812. }// End of for CCS_QUANTITY
  15813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15814. }
  15815. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15816. {
  15817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15818. {
  15819. tempIndex = ((gun_index==2) ? 1: 0);
  15820. }
  15821. else
  15822. {
  15823. tempIndex = gun_index;
  15824. }
  15825. for (int index = 0; index < GB_QUANTITY; index++)
  15826. {
  15827. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15828. {
  15829. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15830. }
  15831. }// End of for GB_QUANTITY
  15832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15833. }
  15834. else if(gunType[gun_index] == GUN_TYPE_DO)
  15835. {
  15836. tempIndex = gun_index;
  15837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15838. {
  15839. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15840. {
  15841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15842. }
  15843. }
  15844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15845. }
  15846. else
  15847. {
  15848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15849. {
  15850. tempIndex = 2;
  15851. }
  15852. else
  15853. {
  15854. tempIndex = gun_index;
  15855. }
  15856. for (int index = 0; index < AC_QUANTITY; index++)
  15857. {
  15858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15859. {
  15860. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15861. }
  15862. }// End of for AC_QUANTITY
  15863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15864. }
  15865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15868. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15871. }
  15872. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15873. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15874. {
  15875. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15876. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15877. {
  15878. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15879. {
  15880. tempIndex = ((gun_index==2) ? 1: 0);
  15881. }
  15882. else
  15883. {
  15884. tempIndex = gun_index;
  15885. }
  15886. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15887. {
  15888. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15889. {
  15890. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15891. }
  15892. }// END OF CHAdeMO_QUANTITY
  15893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15894. }
  15895. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15896. {
  15897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15898. {
  15899. tempIndex = ((gun_index==2) ? 1: 0);
  15900. }
  15901. else
  15902. {
  15903. tempIndex = gun_index;
  15904. }
  15905. for (int index = 0; index < CCS_QUANTITY; index++)
  15906. {
  15907. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15908. {
  15909. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15910. }
  15911. }// END OF CCS_QUANTITY
  15912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15913. }
  15914. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15915. {
  15916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15917. {
  15918. tempIndex = ((gun_index==2) ? 1: 0);
  15919. }
  15920. else
  15921. {
  15922. tempIndex = gun_index;
  15923. }
  15924. for (int index = 0; index < GB_QUANTITY; index++)
  15925. {
  15926. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15927. {
  15928. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15929. }
  15930. }// END OF GB_QUANTITY
  15931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15932. }
  15933. else if(gunType[gun_index] == GUN_TYPE_DO)
  15934. {
  15935. tempIndex = gun_index;
  15936. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15937. {
  15938. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15939. {
  15940. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15941. }
  15942. }
  15943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15944. }
  15945. else
  15946. {
  15947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15948. {
  15949. tempIndex = 2;
  15950. }
  15951. else
  15952. {
  15953. tempIndex = gun_index;
  15954. }
  15955. for (int index = 0; index < AC_QUANTITY; index++)
  15956. {
  15957. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15958. {
  15959. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15960. }
  15961. }// END OF AC_QUANTITY
  15962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15963. }
  15964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15967. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15970. }
  15971. //2.3====================================== Power.Active.Import =========================================
  15972. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15973. {
  15974. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15975. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15976. {
  15977. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15978. {
  15979. tempIndex = ((gun_index==2) ? 1: 0);
  15980. }
  15981. else
  15982. {
  15983. tempIndex = gun_index;
  15984. }
  15985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15986. {
  15987. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15988. {
  15989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15990. }
  15991. } // End for CHAdeMO_QUANTITY
  15992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15993. }
  15994. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15995. {
  15996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15997. {
  15998. tempIndex = ((gun_index==2) ? 1: 0);
  15999. }
  16000. else
  16001. {
  16002. tempIndex = gun_index;
  16003. }
  16004. for (int index = 0; index < CCS_QUANTITY; index++)
  16005. {
  16006. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16007. {
  16008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16009. }
  16010. } // END for CCS_QUANTITY
  16011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16012. }
  16013. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16014. {
  16015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16016. {
  16017. tempIndex = ((gun_index==2) ? 1: 0);
  16018. }
  16019. else
  16020. {
  16021. tempIndex = gun_index;
  16022. }
  16023. for (int index = 0; index < GB_QUANTITY; index++)
  16024. {
  16025. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16026. {
  16027. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16028. }
  16029. }// END for GB_QUANTITY
  16030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16031. }
  16032. else if(gunType[gun_index] == GUN_TYPE_DO)
  16033. {
  16034. tempIndex = gun_index;
  16035. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16036. {
  16037. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16038. {
  16039. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16040. }
  16041. }
  16042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16043. }
  16044. else
  16045. {
  16046. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16047. {
  16048. tempIndex = 2;
  16049. }
  16050. else
  16051. {
  16052. tempIndex = gun_index;
  16053. }
  16054. for (int index = 0; index < AC_QUANTITY; index++)
  16055. {
  16056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16057. {
  16058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16059. }
  16060. } // END for AC_QUANTITY
  16061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16062. }
  16063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16066. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16069. }
  16070. //2.4====================================== Voltage L1 ====================================================
  16071. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16072. {
  16073. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16074. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16075. {
  16076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16077. {
  16078. tempIndex = ((gun_index==2) ? 1: 0);
  16079. }
  16080. else
  16081. {
  16082. tempIndex = gun_index;
  16083. }
  16084. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16085. {
  16086. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16087. {
  16088. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16089. }
  16090. } // END OF FOR CHAdeMO_QUANTITY
  16091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16092. }
  16093. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16094. {
  16095. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16096. {
  16097. tempIndex = ((gun_index==2) ? 1: 0);
  16098. }
  16099. else
  16100. {
  16101. tempIndex = gun_index;
  16102. }
  16103. for (int index = 0; index < CCS_QUANTITY; index++)
  16104. {
  16105. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16106. {
  16107. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16108. }
  16109. } // END OF FOR CCS_QUANTITY
  16110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16111. }
  16112. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16113. {
  16114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16115. {
  16116. tempIndex = ((gun_index==2) ? 1: 0);
  16117. }
  16118. else
  16119. {
  16120. tempIndex = gun_index;
  16121. }
  16122. for (int index = 0; index < GB_QUANTITY; index++)
  16123. {
  16124. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16125. {
  16126. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16127. }
  16128. } // END OF FOR GB_QUANTITY
  16129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16130. }
  16131. else if(gunType[gun_index] == GUN_TYPE_DO)
  16132. {
  16133. tempIndex = gun_index;
  16134. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16135. {
  16136. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16137. {
  16138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16139. }
  16140. }
  16141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16142. }
  16143. else
  16144. {
  16145. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16146. {
  16147. tempIndex = 2;
  16148. }
  16149. else
  16150. {
  16151. tempIndex = gun_index;
  16152. }
  16153. for (int index = 0; index < AC_QUANTITY; index++)
  16154. {
  16155. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16156. {
  16157. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  16158. }
  16159. } // END OF FOR AC_QUANTITY
  16160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16161. }
  16162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16165. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16168. }
  16169. //2.5============================================== End SoC =========================================================
  16170. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16171. {
  16172. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16173. 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))
  16174. {
  16175. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16176. {
  16177. tempIndex = ((gun_index==2) ? 1: 0);
  16178. }
  16179. else
  16180. {
  16181. tempIndex = gun_index;
  16182. }
  16183. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16184. {
  16185. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16186. {
  16187. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16188. {
  16189. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16190. }
  16191. }
  16192. }
  16193. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16194. {
  16195. for (int index = 0; index < CCS_QUANTITY; index++)
  16196. {
  16197. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16198. {
  16199. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16200. }
  16201. }
  16202. }
  16203. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16204. {
  16205. for (int index = 0; index < GB_QUANTITY; index++)
  16206. {
  16207. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16208. {
  16209. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16210. }
  16211. }
  16212. }
  16213. else if(gunType[gun_index] == GUN_TYPE_DO)
  16214. {
  16215. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16216. {
  16217. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16218. {
  16219. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16220. }
  16221. }
  16222. }
  16223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16224. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16229. } // END FOR DC CASE
  16230. }
  16231. //2.6====================================== Current.Import L2 ==============================================
  16232. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16233. {
  16234. // AC 3 phase L2 current
  16235. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16236. {
  16237. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16238. {
  16239. tempIndex = 2;
  16240. }
  16241. else
  16242. {
  16243. tempIndex = gun_index;
  16244. }
  16245. for (int index = 0; index < AC_QUANTITY; index++)
  16246. {
  16247. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16248. {
  16249. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16250. }
  16251. }// End of for AC_QUANTITY
  16252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16253. }
  16254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16259. }
  16260. //2.7====================================== Current.Import L3 ==============================================
  16261. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16262. {
  16263. // AC 3 phase L3 current
  16264. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16265. {
  16266. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16267. {
  16268. tempIndex = 2;
  16269. }
  16270. else
  16271. {
  16272. tempIndex = gun_index;
  16273. }
  16274. for (int index = 0; index < AC_QUANTITY; index++)
  16275. {
  16276. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16277. {
  16278. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16279. }
  16280. }// End of for AC_QUANTITY
  16281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16282. }
  16283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16288. }
  16289. //2.9====================================== Voltage L2 ====================================================
  16290. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16291. {
  16292. // AC 3 phase L2 volatge
  16293. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16294. {
  16295. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16296. {
  16297. tempIndex = 2;
  16298. }
  16299. else
  16300. {
  16301. tempIndex = gun_index;
  16302. }
  16303. for (int index = 0; index < AC_QUANTITY; index++)
  16304. {
  16305. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16306. {
  16307. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  16308. }
  16309. } // END OF FOR AC_QUANTITY
  16310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16311. }
  16312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16317. }
  16318. //2.10====================================== Voltage L3 ====================================================
  16319. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16320. {
  16321. // AC 3 phase L3 volatge
  16322. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16323. {
  16324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16325. {
  16326. tempIndex = 2;
  16327. }
  16328. else
  16329. {
  16330. tempIndex = gun_index;
  16331. }
  16332. for (int index = 0; index < AC_QUANTITY; index++)
  16333. {
  16334. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16335. {
  16336. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  16337. }
  16338. } // END OF FOR AC_QUANTITY
  16339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16340. }
  16341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16346. }
  16347. //====================== Start SoC ================================
  16348. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16349. {
  16350. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16351. 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))
  16352. {
  16353. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16354. {
  16355. tempIndex = ((gun_index==2) ? 1: 0);
  16356. }
  16357. else
  16358. {
  16359. tempIndex = gun_index;
  16360. }
  16361. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16362. {
  16363. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16364. {
  16365. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16366. {
  16367. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16368. }
  16369. }
  16370. }
  16371. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16372. {
  16373. for (int index = 0; index < CCS_QUANTITY; index++)
  16374. {
  16375. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16376. {
  16377. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16378. }
  16379. }
  16380. }
  16381. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16382. {
  16383. for (int index = 0; index < GB_QUANTITY; index++)
  16384. {
  16385. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16386. {
  16387. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16388. }
  16389. }
  16390. }
  16391. else if(gunType[gun_index] == GUN_TYPE_DO)
  16392. {
  16393. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16394. {
  16395. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16396. {
  16397. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16398. }
  16399. }
  16400. }
  16401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16407. } // END FOR DC CASE
  16408. }
  16409. //======================================== Message create ==============================================
  16410. json_object *StopTransaction = json_object_new_object();
  16411. json_object *transactionDatas = json_object_new_array();
  16412. json_object *sampledValues = json_object_new_array();
  16413. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16414. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16415. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16416. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16417. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16418. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16419. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16420. {
  16421. json_object *transactionData = json_object_new_object();
  16422. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16423. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16424. {
  16425. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16426. {
  16427. json_object *sampledValue = json_object_new_object();
  16428. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16429. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16430. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16431. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16432. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16433. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16434. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16435. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16436. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16437. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16438. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16439. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16440. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16441. json_object_array_add(sampledValues, sampledValue);
  16442. }
  16443. }
  16444. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16445. json_object_array_add(transactionDatas, transactionData);
  16446. }
  16447. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16448. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16449. ,MESSAGE_TYPE_CALL
  16450. ,guid
  16451. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16452. json_object_put(StopTransaction);
  16453. // Check File "TempStopTransaction" Exist
  16454. if((access(TempStopTransaction,F_OK))!=-1)
  16455. {
  16456. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16457. fclose(fopen(TempStopTransaction, "w"));
  16458. }
  16459. else
  16460. {
  16461. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16462. FILE *log = fopen(TempStopTransaction, "w+");
  16463. if(log == NULL)
  16464. {
  16465. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16466. return ;
  16467. }
  16468. else
  16469. {
  16470. fclose(log);
  16471. }
  16472. }
  16473. //Add TempStopTransaction | Update TempStopTransaction
  16474. // open file for writing
  16475. FILE *outfile;
  16476. outfile = fopen (TempStopTransaction, "a");
  16477. //DEBUG_INFO("data = %s\n", queuedata);
  16478. fputs(queuedata, outfile);
  16479. fputs("\n", outfile);
  16480. fclose (outfile);
  16481. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16482. }
  16483. void checkTempStopTransaction(int gun_index)
  16484. {
  16485. FILE *fptr1;
  16486. char ch;
  16487. char str[QUEUE_MESSAGE_LENGTH]={0};
  16488. char guid[37]={0};
  16489. char tempdata[65]={0};
  16490. char connectorStr[2]={0};
  16491. char TempStopTransaction[256];
  16492. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16493. fptr1 = fopen(TempStopTransaction, "r");
  16494. //TempStopTransaction格式: 槍號,StopTransaction封包
  16495. if (!fptr1)
  16496. {
  16497. //printf(" File not found or unable to open the input file!!\n");
  16498. return ;
  16499. }
  16500. ch=fgetc(fptr1);
  16501. //printf(" Now the content of the file %s is : \n",fname);
  16502. rewind(fptr1);
  16503. if(ch!=EOF)
  16504. {
  16505. // copy all contents to the temporary file except the specific line
  16506. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16507. {
  16508. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16509. if(str[0]=='\0')
  16510. {
  16511. break;
  16512. }
  16513. //TempStopTransaction格式: 槍號,StopTransaction封包
  16514. strncpy(connectorStr, str, 1);
  16515. if(atoi(connectorStr) != (gun_index+1))
  16516. {
  16517. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16518. fclose(fptr1);
  16519. return ;
  16520. }
  16521. //random_uuid(guid);
  16522. strncpy(guid, str+6, 36); //copy guid
  16523. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16524. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16525. {
  16526. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16527. }
  16528. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16529. OCPP_insert_transaction_msg(NO, str);
  16530. memset(str,0,ARRAY_SIZE(str));
  16531. }
  16532. }
  16533. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16534. fclose(fptr1);
  16535. remove(TempStopTransaction); // remove the original file
  16536. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16537. }
  16538. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16539. {
  16540. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16541. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16542. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16543. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16544. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16545. }
  16546. int GetWebSocketPingInterval(void)
  16547. {
  16548. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16549. }
  16550. int GetServerSign(void)
  16551. {
  16552. return server_sign;
  16553. }
  16554. uint8_t GetOcppSecurityProfile()
  16555. {
  16556. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16557. }
  16558. void GetOcppChargerBoxId(uint8_t *data)
  16559. {
  16560. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16561. }
  16562. void GetOcppSecurityPassword(uint8_t *data)
  16563. {
  16564. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16565. }
  16566. void SetOcppVersion(uint8_t *version)
  16567. {
  16568. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16569. DEBUG_INFO("ocpp version: %s\n", version);
  16570. if(strstr((char*)version, "ocpp1.6") != NULL)
  16571. {
  16572. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16573. }
  16574. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16575. {
  16576. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16577. system("pkill OcppBackend");
  16578. }
  16579. }
  16580. void SetServerSign(int value)
  16581. {
  16582. server_sign = value;
  16583. }
  16584. int GetBootNotificationInterval(void)
  16585. {
  16586. return BootNotificationInterval;
  16587. }
  16588. int GetInternetConn(void)
  16589. {
  16590. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16591. }
  16592. int GetBackendConnectionTimeout(void)
  16593. {
  16594. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16595. }
  16596. int isConnectorInitMode(int gun_index)
  16597. {
  16598. int tempIndex = 0;
  16599. int result = TRUE;
  16600. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16601. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16602. {
  16603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16604. {
  16605. tempIndex = ((gun_index==2) ? 1: 0);
  16606. }
  16607. else
  16608. {
  16609. tempIndex = gun_index;
  16610. }
  16611. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16612. {
  16613. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16614. {
  16615. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16616. } //end of the same index
  16617. }//end of for CHAdeMO_QUANTITY
  16618. }
  16619. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16620. {
  16621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16622. {
  16623. tempIndex = ((gun_index==2) ? 1: 0);
  16624. }
  16625. else
  16626. {
  16627. tempIndex = gun_index;
  16628. }
  16629. for (int index = 0; index < CCS_QUANTITY; index++)
  16630. {
  16631. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16632. {
  16633. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16634. } //end of the same index
  16635. } // end of for CCS_QUANTITY
  16636. }
  16637. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16638. {
  16639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16640. {
  16641. tempIndex = ((gun_index==2) ? 1: 0);
  16642. }
  16643. else
  16644. {
  16645. tempIndex = gun_index;
  16646. }
  16647. for (int index = 0; index < GB_QUANTITY; index++)
  16648. {
  16649. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16650. {
  16651. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16652. } //end of the same index
  16653. } // end of for GB_QUANTITY
  16654. }
  16655. else if(gunType[gun_index] == GUN_TYPE_DO)
  16656. {
  16657. tempIndex = gun_index;
  16658. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16659. {
  16660. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16661. {
  16662. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16663. } //end of the same index
  16664. }
  16665. }
  16666. else
  16667. {
  16668. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16669. {
  16670. tempIndex = 2;
  16671. }
  16672. else
  16673. {
  16674. tempIndex = gun_index;
  16675. }
  16676. for (int index = 0; index < AC_QUANTITY; index++)
  16677. {
  16678. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16679. {
  16680. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16681. }//end of the same index
  16682. }//end of for AC_QUANTITY
  16683. }
  16684. return result;
  16685. }
  16686. void refreshProcDogTimer()
  16687. {
  16688. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16689. }
  16690. void InitialSystemValue(void)
  16691. {
  16692. int connectorIndex = 0;
  16693. //int valueASCII = 0;
  16694. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16695. gunTotalNumber=0;
  16696. SystemInitial = 0;
  16697. locallistVersion=0;
  16698. BootNotificationInterval = 0;
  16699. authorizeRetryTimes = 0;
  16700. GunStatusInterval = 10;
  16701. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16702. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16703. //Hear Beat
  16704. HeartBeatWithNOResponse = 0;
  16705. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16706. FirstHeartBeat = 0;
  16707. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16708. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16709. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16710. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16711. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16712. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16713. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16714. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16715. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16716. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16717. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16718. memset(gunType, 0, ARRAY_SIZE(gunType));
  16719. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16720. {
  16721. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16722. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16723. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16724. {
  16725. // DO series
  16726. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16727. {
  16728. SystemInitial = SystemInitial + 1;
  16729. gunTotalNumber = gunTotalNumber + 1;
  16730. gunType[connectorIndex] = GUN_TYPE_DO;
  16731. connectorIndex = connectorIndex + 1;
  16732. }
  16733. }
  16734. else
  16735. {
  16736. // DM, DW, DS series
  16737. //check connector / socket type (index: 8, 9, 10)
  16738. for(int index=7; index <10 ; index++)
  16739. {
  16740. if(index != 8)
  16741. {
  16742. // DC Connector
  16743. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16744. {
  16745. SystemInitial = SystemInitial + 1;
  16746. gunTotalNumber = gunTotalNumber + 1;
  16747. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16748. connectorIndex = connectorIndex + 1;
  16749. }
  16750. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16751. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16752. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16753. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16754. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16755. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16756. {
  16757. SystemInitial = SystemInitial + 1;
  16758. gunTotalNumber = gunTotalNumber + 1;
  16759. gunType[connectorIndex] = GUN_TYPE_CCS;
  16760. connectorIndex = connectorIndex + 1;
  16761. }
  16762. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16763. {
  16764. SystemInitial = SystemInitial + 1;
  16765. gunTotalNumber = gunTotalNumber + 1;
  16766. gunType[connectorIndex] = GUN_TYPE_GBT;
  16767. connectorIndex = connectorIndex + 1;
  16768. }
  16769. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16770. {
  16771. SystemInitial = SystemInitial + 1;
  16772. gunTotalNumber = gunTotalNumber + 1;
  16773. gunType[connectorIndex] = GUN_TYPE_DO;
  16774. connectorIndex = connectorIndex + 1;
  16775. }
  16776. }
  16777. else
  16778. {
  16779. // AC Connector
  16780. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16781. {
  16782. SystemInitial = SystemInitial + 1;
  16783. gunTotalNumber = gunTotalNumber + 1;
  16784. gunType[connectorIndex] = GUN_TYPE_AC;
  16785. connectorIndex = connectorIndex + 1;
  16786. }
  16787. }
  16788. }
  16789. }
  16790. //DEBUG_INFO("DC ...\n");
  16791. }
  16792. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16793. {
  16794. //check connector / socket type (index: 8, 9, 10)
  16795. for(int index=7; index <10 ; index++)
  16796. {
  16797. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16798. {
  16799. SystemInitial = SystemInitial + 1;
  16800. gunTotalNumber = gunTotalNumber + 1;
  16801. gunType[connectorIndex] = GUN_TYPE_AC;
  16802. connectorIndex = connectorIndex + 1;
  16803. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16804. }
  16805. }
  16806. }
  16807. //Status && ConnectorPlugIn Setting
  16808. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16809. {
  16810. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16811. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16812. }
  16813. for (int index = 0; index < CCS_QUANTITY; index++)
  16814. {
  16815. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16816. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16817. }
  16818. for (int index = 0; index < GB_QUANTITY; index++)
  16819. {
  16820. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16821. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16822. }
  16823. for (int index = 0; index < AC_QUANTITY; index++)
  16824. {
  16825. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16826. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16827. }
  16828. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16829. {
  16830. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16831. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16832. }
  16833. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16834. {
  16835. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16836. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16837. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16838. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16839. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16840. }
  16841. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16842. clientTime.Heartbeat=time((time_t*)NULL);
  16843. sleep(1);
  16844. }
  16845. void LWS_Send(char *str)
  16846. {
  16847. //=====================================================
  16848. // Check InternetConn 0: disconnected, 1: connected
  16849. //====================================================
  16850. if(GetOcppConnStatus() == 0)
  16851. {
  16852. DEBUG_INFO("offline now !!!\n");
  16853. return;
  16854. }
  16855. // Only disable isWebsocketSendable operation initiated by charger
  16856. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16857. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16858. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16859. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16860. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16861. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16862. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16863. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16864. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16865. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16866. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16867. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16868. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16869. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16870. {
  16871. isWebsocketSendable = 0;
  16872. }
  16873. pthread_mutex_lock(&lock_send);
  16874. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16875. sprintf((char *)SendBuffer, "%s", str);
  16876. SendBufLen = strlen(str);
  16877. pthread_mutex_unlock(&lock_send);
  16878. lws_callback_on_writable(wsi_client);
  16879. //lws_service(context, 0);
  16880. //sleep(1);
  16881. }
  16882. void LWS_SendNow(char *str)
  16883. {
  16884. //=====================================================
  16885. // Check InternetConn 0: disconnected, 1: connected
  16886. //====================================================
  16887. if(GetOcppConnStatus() == 0)
  16888. {
  16889. DEBUG_INFO("offline now !!!\n");
  16890. return;
  16891. }
  16892. // Only disable isWebsocketSendable operation initiated by charger
  16893. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16894. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16895. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16896. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16897. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16898. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16899. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16900. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16901. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16902. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16903. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16904. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16905. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16906. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16907. {
  16908. isWebsocketSendable = 0;
  16909. }
  16910. pthread_mutex_lock(&lock_send);
  16911. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16912. sprintf((char *)SendBuffer, "%s", str);
  16913. SendBufLen = strlen(str);
  16914. pthread_mutex_unlock(&lock_send);
  16915. lws_callback_on_writable(wsi_client);
  16916. lws_service(context, 0);
  16917. //sleep(1);
  16918. }