diff --git a/TODO b/TODO index 492c4280..b2dc796c 100644 --- a/TODO +++ b/TODO @@ -14,7 +14,6 @@ Version 1.4.0: * Get original driver for r8169. * Race in jiffies frame timeout? * ethercat tool: - - Single message for unambiguous slave in SiiRead/Write and Up/Download. - Implement Alias/Position selection for configs. - Update help for --alias and --position. - Show Pdos in 'ethercat slave -v'. diff --git a/tool/Command.cpp b/tool/Command.cpp index 76eafe1e..407357bb 100644 --- a/tool/Command.cpp +++ b/tool/Command.cpp @@ -80,20 +80,32 @@ string Command::numericInfo() /*****************************************************************************/ -void Command::throwInvalidUsageException(const stringstream &s) +void Command::throwInvalidUsageException(const stringstream &s) const { throw InvalidUsageException(s); } /*****************************************************************************/ -void Command::throwCommandException(const stringstream &s) +void Command::throwCommandException(const stringstream &s) const { throw CommandException(s); } /*****************************************************************************/ +void Command::throwSingleSlaveRequired(unsigned int size) const +{ + stringstream err; + + err << "The slave selection matches " << size << "slaves. '" + << name << "' requires a single slave."; + + throwInvalidUsageException(err); +} + +/*****************************************************************************/ + Command::SlaveList Command::selectedSlaves(MasterDevice &m) { unsigned int numSlaves = m.slaveCount(), i, aliasIndex; diff --git a/tool/Command.h b/tool/Command.h index 0d86580f..dae6b09e 100644 --- a/tool/Command.h +++ b/tool/Command.h @@ -85,8 +85,9 @@ class Command protected: enum {BreakAfterBytes = 16}; - void throwInvalidUsageException(const stringstream &); - void throwCommandException(const stringstream &); + void throwInvalidUsageException(const stringstream &) const; + void throwCommandException(const stringstream &) const; + void throwSingleSlaveRequired(unsigned int) const; typedef list SlaveList; SlaveList selectedSlaves(MasterDevice &); diff --git a/tool/CommandDownload.cpp b/tool/CommandDownload.cpp index 03445e40..62e63e90 100644 --- a/tool/CommandDownload.cpp +++ b/tool/CommandDownload.cpp @@ -93,8 +93,7 @@ void CommandDownload::execute(MasterDevice &m, const StringVector &args) m.open(MasterDevice::ReadWrite); slaves = selectedSlaves(m); if (slaves.size() != 1) { - err << slaves.size() << " slaves selected, single slave required!"; - throwInvalidUsageException(err); + throwSingleSlaveRequired(slaves.size()); } data.slave_position = slaves.front().position; diff --git a/tool/CommandSiiRead.cpp b/tool/CommandSiiRead.cpp index 01aa66f3..4f6347ae 100644 --- a/tool/CommandSiiRead.cpp +++ b/tool/CommandSiiRead.cpp @@ -62,9 +62,7 @@ void CommandSiiRead::execute(MasterDevice &m, const StringVector &args) slaves = selectedSlaves(m); if (slaves.size() != 1) { - err << "'" << getName() << "' requires a single slave (" - << slaves.size() << " selected)."; - throwInvalidUsageException(err); + throwSingleSlaveRequired(slaves.size()); } slave = &slaves.front(); data.slave_position = slave->position; diff --git a/tool/CommandSiiWrite.cpp b/tool/CommandSiiWrite.cpp index 824ff352..5456513c 100644 --- a/tool/CommandSiiWrite.cpp +++ b/tool/CommandSiiWrite.cpp @@ -63,9 +63,7 @@ void CommandSiiWrite::execute(MasterDevice &m, const StringVector &args) slaves = selectedSlaves(m); if (slaves.size() != 1) { - err << "'" << getName() << "' requires a single slave (" - << slaves.size() << " selected)."; - throwInvalidUsageException(err); + throwSingleSlaveRequired(slaves.size()); } data.slave_position = slaves.front().position; diff --git a/tool/CommandUpload.cpp b/tool/CommandUpload.cpp index a29f2ed2..5882f88c 100644 --- a/tool/CommandUpload.cpp +++ b/tool/CommandUpload.cpp @@ -92,8 +92,7 @@ void CommandUpload::execute(MasterDevice &m, const StringVector &args) m.open(MasterDevice::Read); slaves = selectedSlaves(m); if (slaves.size() != 1) { - err << slaves.size() << " slaves selected, single slave required!"; - throwInvalidUsageException(err); + throwSingleSlaveRequired(slaves.size()); } data.slave_position = slaves.front().position;