Added getSingleMasterIndex() for command-line tool.
This commit is contained in:
parent
ddaee8a1fc
commit
aa0b667b4f
|
|
@ -209,6 +209,19 @@ Command::MasterIndexList Command::getMasterIndices() const
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned int Command::getSingleMasterIndex() const
|
||||
{
|
||||
MasterIndexList masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
stringstream err;
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
return masterIndices.front();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
Command::SlaveList Command::selectedSlaves(MasterDevice &m)
|
||||
{
|
||||
ec_ioctl_master_t master;
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ class Command
|
|||
typedef list<unsigned int> MasterIndexList;
|
||||
void setMasters(const string &);
|
||||
MasterIndexList getMasterIndices() const;
|
||||
unsigned int getSingleMasterIndex() const;
|
||||
|
||||
enum Verbosity {
|
||||
Quiet,
|
||||
|
|
|
|||
|
|
@ -81,7 +81,6 @@ void CommandAlias::execute(const StringVector &args)
|
|||
uint16_t alias;
|
||||
stringstream err, strAlias;
|
||||
int number;
|
||||
MasterIndexList masterIndices;
|
||||
SlaveList slaves;
|
||||
SlaveList::const_iterator si;
|
||||
|
||||
|
|
@ -100,12 +99,7 @@ void CommandAlias::execute(const StringVector &args)
|
|||
}
|
||||
alias = number;
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
m.open(MasterDevice::ReadWrite);
|
||||
slaves = selectedSlaves(m);
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,6 @@ string CommandDownload::helpString() const
|
|||
void CommandDownload::execute(const StringVector &args)
|
||||
{
|
||||
stringstream strIndex, strSubIndex, err;
|
||||
MasterIndexList masterIndices;
|
||||
ec_ioctl_slave_sdo_download_t data;
|
||||
unsigned int number;
|
||||
const DataType *dataType = NULL;
|
||||
|
|
@ -115,12 +114,7 @@ void CommandDownload::execute(const StringVector &args)
|
|||
}
|
||||
data.sdo_entry_subindex = number;
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
m.open(MasterDevice::ReadWrite);
|
||||
slaves = selectedSlaves(m);
|
||||
if (slaves.size() != 1) {
|
||||
|
|
|
|||
|
|
@ -76,7 +76,6 @@ string CommandFoeRead::helpString() const
|
|||
|
||||
void CommandFoeRead::execute(const StringVector &args)
|
||||
{
|
||||
MasterIndexList masterIndices;
|
||||
SlaveList slaves;
|
||||
ec_ioctl_slave_t *slave;
|
||||
ec_ioctl_slave_foe_t data;
|
||||
|
|
@ -88,12 +87,7 @@ void CommandFoeRead::execute(const StringVector &args)
|
|||
throwInvalidUsageException(err);
|
||||
}
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
m.open(MasterDevice::Read);
|
||||
slaves = selectedSlaves(m);
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,6 @@ string CommandFoeWrite::helpString() const
|
|||
|
||||
void CommandFoeWrite::execute(const StringVector &args)
|
||||
{
|
||||
MasterIndexList masterIndices;
|
||||
stringstream err;
|
||||
ec_ioctl_slave_foe_t data;
|
||||
ifstream file;
|
||||
|
|
@ -94,13 +93,6 @@ void CommandFoeWrite::execute(const StringVector &args)
|
|||
throwInvalidUsageException(err);
|
||||
}
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
|
||||
if (args[0] == "-") {
|
||||
loadFoeData(&data, cin);
|
||||
if (getOutputFile().empty()) {
|
||||
|
|
@ -128,6 +120,7 @@ void CommandFoeWrite::execute(const StringVector &args)
|
|||
}
|
||||
}
|
||||
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
try {
|
||||
m.open(MasterDevice::ReadWrite);
|
||||
} catch (MasterDeviceException &e) {
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ string CommandGraph::helpString() const
|
|||
|
||||
void CommandGraph::execute(const StringVector &args)
|
||||
{
|
||||
MasterIndexList masterIndices;
|
||||
ec_ioctl_master_t master;
|
||||
unsigned int i;
|
||||
typedef vector<ec_ioctl_slave_t> SlaveVector;
|
||||
|
|
@ -91,13 +90,7 @@ void CommandGraph::execute(const StringVector &args)
|
|||
throwInvalidUsageException(err);
|
||||
}
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
stringstream err;
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
m.open(MasterDevice::Read);
|
||||
m.getMaster(&master);
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,6 @@ string CommandRegRead::helpString() const
|
|||
|
||||
void CommandRegRead::execute(const StringVector &args)
|
||||
{
|
||||
MasterIndexList masterIndices;
|
||||
SlaveList slaves;
|
||||
ec_ioctl_slave_reg_t data;
|
||||
stringstream strOffset, err;
|
||||
|
|
@ -141,12 +140,7 @@ void CommandRegRead::execute(const StringVector &args)
|
|||
throwInvalidUsageException(err);
|
||||
}
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
m.open(MasterDevice::Read);
|
||||
slaves = selectedSlaves(m);
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,6 @@ string CommandRegWrite::helpString() const
|
|||
|
||||
void CommandRegWrite::execute(const StringVector &args)
|
||||
{
|
||||
MasterIndexList masterIndices;
|
||||
stringstream strOffset, err;
|
||||
ec_ioctl_slave_reg_t data;
|
||||
ifstream file;
|
||||
|
|
@ -101,13 +100,6 @@ void CommandRegWrite::execute(const StringVector &args)
|
|||
throwInvalidUsageException(err);
|
||||
}
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
|
||||
if (getDataType().empty()) {
|
||||
if (args[1] == "-") {
|
||||
loadRegData(&data, cin);
|
||||
|
|
@ -157,6 +149,7 @@ void CommandRegWrite::execute(const StringVector &args)
|
|||
throwInvalidUsageException(err);
|
||||
}
|
||||
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
try {
|
||||
m.open(MasterDevice::ReadWrite);
|
||||
} catch (MasterDeviceException &e) {
|
||||
|
|
|
|||
|
|
@ -76,7 +76,6 @@ string CommandSiiRead::helpString() const
|
|||
|
||||
void CommandSiiRead::execute(const StringVector &args)
|
||||
{
|
||||
MasterIndexList masterIndices;
|
||||
SlaveList slaves;
|
||||
ec_ioctl_slave_t *slave;
|
||||
ec_ioctl_slave_sii_t data;
|
||||
|
|
@ -90,12 +89,7 @@ void CommandSiiRead::execute(const StringVector &args)
|
|||
throwInvalidUsageException(err);
|
||||
}
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
m.open(MasterDevice::Read);
|
||||
slaves = selectedSlaves(m);
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,6 @@ string CommandSiiWrite::helpString() const
|
|||
|
||||
void CommandSiiWrite::execute(const StringVector &args)
|
||||
{
|
||||
MasterIndexList masterIndices;
|
||||
stringstream err;
|
||||
ec_ioctl_slave_sii_t data;
|
||||
ifstream file;
|
||||
|
|
@ -89,13 +88,6 @@ void CommandSiiWrite::execute(const StringVector &args)
|
|||
throwInvalidUsageException(err);
|
||||
}
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
|
||||
if (args[0] == "-") {
|
||||
loadSiiData(&data, cin);
|
||||
} else {
|
||||
|
|
@ -117,6 +109,7 @@ void CommandSiiWrite::execute(const StringVector &args)
|
|||
}
|
||||
}
|
||||
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
try {
|
||||
m.open(MasterDevice::ReadWrite);
|
||||
} catch (MasterDeviceException &e) {
|
||||
|
|
|
|||
|
|
@ -78,7 +78,6 @@ string CommandSoeRead::helpString() const
|
|||
|
||||
void CommandSoeRead::execute(const StringVector &args)
|
||||
{
|
||||
MasterIndexList masterIndices;
|
||||
SlaveList slaves;
|
||||
stringstream err;
|
||||
const DataType *dataType = NULL;
|
||||
|
|
@ -96,12 +95,7 @@ void CommandSoeRead::execute(const StringVector &args)
|
|||
throwInvalidUsageException(err);
|
||||
}
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
m.open(MasterDevice::Read);
|
||||
slaves = selectedSlaves(m);
|
||||
if (slaves.size() != 1) {
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ string CommandSoeWrite::helpString() const
|
|||
|
||||
void CommandSoeWrite::execute(const StringVector &args)
|
||||
{
|
||||
MasterIndexList masterIndices;
|
||||
stringstream strIdn, err;
|
||||
const DataType *dataType = NULL;
|
||||
ec_ioctl_slave_soe_write_t ioctl;
|
||||
|
|
@ -99,12 +98,7 @@ void CommandSoeWrite::execute(const StringVector &args)
|
|||
throwInvalidUsageException(err);
|
||||
}
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
m.open(MasterDevice::ReadWrite);
|
||||
slaves = selectedSlaves(m);
|
||||
if (slaves.size() != 1) {
|
||||
|
|
|
|||
|
|
@ -82,7 +82,6 @@ string CommandUpload::helpString() const
|
|||
|
||||
void CommandUpload::execute(const StringVector &args)
|
||||
{
|
||||
MasterIndexList masterIndices;
|
||||
SlaveList slaves;
|
||||
stringstream err, strIndex, strSubIndex;
|
||||
ec_ioctl_slave_sdo_upload_t data;
|
||||
|
|
@ -113,12 +112,7 @@ void CommandUpload::execute(const StringVector &args)
|
|||
}
|
||||
data.sdo_entry_subindex = uval;
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
m.open(MasterDevice::Read);
|
||||
slaves = selectedSlaves(m);
|
||||
if (slaves.size() != 1) {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,6 @@ string CommandXml::helpString() const
|
|||
|
||||
void CommandXml::execute(const StringVector &args)
|
||||
{
|
||||
MasterIndexList masterIndices;
|
||||
SlaveList slaves;
|
||||
SlaveList::const_iterator si;
|
||||
|
||||
|
|
@ -81,13 +80,7 @@ void CommandXml::execute(const StringVector &args)
|
|||
throwInvalidUsageException(err);
|
||||
}
|
||||
|
||||
masterIndices = getMasterIndices();
|
||||
if (masterIndices.size() != 1) {
|
||||
stringstream err;
|
||||
err << getName() << " requires to select a single master!";
|
||||
throwInvalidUsageException(err);
|
||||
}
|
||||
MasterDevice m(masterIndices.front());
|
||||
MasterDevice m(getSingleMasterIndex());
|
||||
m.open(MasterDevice::Read);
|
||||
slaves = selectedSlaves(m);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue