Skip to content

Commit

Permalink
Adding processing of source id filter option -s
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Ains committed Jun 25, 2019
1 parent ef5bae5 commit 0b177e1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
10 changes: 6 additions & 4 deletions src/example/CAppDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>& sourceIdList) :
dongle(i_timer_factory, this),
zb_messaging(dongle, i_timer_factory),
zb_nwk(dongle, zb_messaging),
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/example/CAppDemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>& sourceIdList={});

/**
* Callback
Expand Down
60 changes: 36 additions & 24 deletions src/example/mainEzspTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main(int argc, char **argv) {
int optionIndex=0;
int c;
bool debugEnabled = false;
std::vector<std::string> sourceIdList;
std::vector<uint32_t> sourceIdList;
unsigned int resetToChannel = 0;
std::string serialPort("/dev/ttyUSB0");

Expand All @@ -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<static_cast<uint32_t>(-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
Expand All @@ -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;
Expand Down

0 comments on commit 0b177e1

Please sign in to comment.