From 0b177e161c2b536c51babc7f170f707f4e071877 Mon Sep 17 00:00:00 2001 From: Lionel Ains Date: Tue, 25 Jun 2019 17:21:11 +0200 Subject: [PATCH] Adding processing of source id filter option -s --- src/example/CAppDemo.cpp | 10 +++--- src/example/CAppDemo.h | 2 +- src/example/mainEzspTest.cpp | 60 +++++++++++++++++++++--------------- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/example/CAppDemo.cpp b/src/example/CAppDemo.cpp index d0c12d5a..f4d74faa 100644 --- a/src/example/CAppDemo.cpp +++ b/src/example/CAppDemo.cpp @@ -17,7 +17,7 @@ #include "../domain/byte-manip.h" -CAppDemo::CAppDemo(IUartDriver& uartDriver, ITimerFactory &i_timer_factory, bool reset, unsigned int networkChannel) : +CAppDemo::CAppDemo(IUartDriver& uartDriver, ITimerFactory &i_timer_factory, bool reset, unsigned int networkChannel, const std::vector& sourceIdList) : dongle(i_timer_factory, this), zb_messaging(dongle, i_timer_factory), zb_nwk(dongle, zb_messaging), @@ -34,12 +34,14 @@ CAppDemo::CAppDemo(IUartDriver& uartDriver, ITimerFactory &i_timer_factory, bool clogE << "Invalid channel: " << channel << ". Using 11 instead\n"; channel = 11; } - if( dongle.open(&uartDriver) ) - { + if( dongle.open(&uartDriver) ) { clogI << "CAppDemo open success !" << std::endl; dongle.registerObserver(this); gp_sink.registerObserver(this); - gp_sink.registerGpd(0xffffffaa); + for (auto i : sourceIdList) { + clogD << "Watching source ID 0x" << std::hex << std::setw(8) << std::setfill('0') << i << "\n"; + gp_sink.registerGpd(i); + } setAppState(APP_INIT_IN_PROGRESS); } // save parameter diff --git a/src/example/CAppDemo.h b/src/example/CAppDemo.h index 41c87918..ab007a68 100644 --- a/src/example/CAppDemo.h +++ b/src/example/CAppDemo.h @@ -26,7 +26,7 @@ typedef enum class CAppDemo : public CEzspDongleObserver, CGpObserver { public: - CAppDemo(IUartDriver& uartDriver, ITimerFactory &i_timer_factory, bool reset=false, unsigned int networkChannel=11); + CAppDemo(IUartDriver& uartDriver, ITimerFactory &i_timer_factory, bool reset=false, unsigned int networkChannel=11, const std::vector& sourceIdList={}); /** * Callback diff --git a/src/example/mainEzspTest.cpp b/src/example/mainEzspTest.cpp index 26174176..5fcb428d 100644 --- a/src/example/mainEzspTest.cpp +++ b/src/example/mainEzspTest.cpp @@ -54,7 +54,7 @@ int main(int argc, char **argv) { int optionIndex=0; int c; bool debugEnabled = false; - std::vector sourceIdList; + std::vector sourceIdList; unsigned int resetToChannel = 0; std::string serialPort("/dev/ttyUSB0"); @@ -67,28 +67,40 @@ int main(int argc, char **argv) { {0, 0, 0, 0} }; while ( (c = getopt_long(argc, argv, "dhs:u:r:", longOptions, &optionIndex)) != -1) { - switch (c) { - case 's': - sourceIdList.push_back(std::string(optarg)); - break; - case 'u': - serialPort = optarg; - break; - case 'r': - stringstream(optarg) >> resetToChannel; - break; - case 'd': - debugEnabled = true; - break; - case 'h': - writeUsage(argv[0], stdout); - exit(0); - case '?': - default: - std::cerr << "Unknown command-line option\n"; - writeUsage(argv[0], stdout); - exit(1); - } + switch (c) { + case 's': + { + stringstream sourceId; + sourceId << std::hex << optarg; + unsigned int sourceIdValue; + sourceId >> sourceIdValue; + if (sourceIdValue(-1)) { /* Protection against overflow */ + sourceIdList.push_back(sourceIdValue); + } + else { + clogE << "Invalid source ID: " << optarg << "\n"; + } + + } + break; + case 'u': + serialPort = optarg; + break; + case 'r': + stringstream(optarg) >> resetToChannel; + break; + case 'd': + debugEnabled = true; + break; + case 'h': + writeUsage(argv[0], stdout); + exit(0); + case '?': + default: + std::cerr << "Unsupported command-line option. Exitting\n"; + writeUsage(argv[0], stdout); + exit(1); + } } #ifdef USE_RARITAN @@ -99,7 +111,7 @@ int main(int argc, char **argv) { uartDriver.open(serialPort, 57600); - CAppDemo app(uartDriver, timerFactory, (resetToChannel!=0), resetToChannel); /* If a channel was provided, reset the network and recreate it on the provided channel */ + CAppDemo app(uartDriver, timerFactory, (resetToChannel!=0), resetToChannel, sourceIdList); /* If a channel was provided, reset the network and recreate it on the provided channel */ #ifdef USE_SERIALCPP std::string line;