# HG changeset patch # User Florian Pose # Date 1217234728 0 # Node ID bd4e5b544473e0a0ceeb932ff4eeda1f08610fa5 # Parent 04bcd38cf8dc7e89d9674ac1edfb919f3b19de4a Common message for single slave selections. diff -r 04bcd38cf8dc -r bd4e5b544473 TODO --- a/TODO Mon Jul 28 08:28:42 2008 +0000 +++ b/TODO Mon Jul 28 08:45:28 2008 +0000 @@ -14,7 +14,6 @@ * 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 -r 04bcd38cf8dc -r bd4e5b544473 tool/Command.cpp --- a/tool/Command.cpp Mon Jul 28 08:28:42 2008 +0000 +++ b/tool/Command.cpp Mon Jul 28 08:45:28 2008 +0000 @@ -80,20 +80,32 @@ /*****************************************************************************/ -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 -r 04bcd38cf8dc -r bd4e5b544473 tool/Command.h --- a/tool/Command.h Mon Jul 28 08:28:42 2008 +0000 +++ b/tool/Command.h Mon Jul 28 08:45:28 2008 +0000 @@ -85,8 +85,9 @@ 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 -r 04bcd38cf8dc -r bd4e5b544473 tool/CommandDownload.cpp --- a/tool/CommandDownload.cpp Mon Jul 28 08:28:42 2008 +0000 +++ b/tool/CommandDownload.cpp Mon Jul 28 08:45:28 2008 +0000 @@ -93,8 +93,7 @@ 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 -r 04bcd38cf8dc -r bd4e5b544473 tool/CommandSiiRead.cpp --- a/tool/CommandSiiRead.cpp Mon Jul 28 08:28:42 2008 +0000 +++ b/tool/CommandSiiRead.cpp Mon Jul 28 08:45:28 2008 +0000 @@ -62,9 +62,7 @@ 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 -r 04bcd38cf8dc -r bd4e5b544473 tool/CommandSiiWrite.cpp --- a/tool/CommandSiiWrite.cpp Mon Jul 28 08:28:42 2008 +0000 +++ b/tool/CommandSiiWrite.cpp Mon Jul 28 08:45:28 2008 +0000 @@ -63,9 +63,7 @@ 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 -r 04bcd38cf8dc -r bd4e5b544473 tool/CommandUpload.cpp --- a/tool/CommandUpload.cpp Mon Jul 28 08:28:42 2008 +0000 +++ b/tool/CommandUpload.cpp Mon Jul 28 08:45:28 2008 +0000 @@ -92,8 +92,7 @@ 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;