diff --git a/tool/Command.cpp b/tool/Command.cpp index 82590d13a9fe59672e79d5407a18ae0bfe052c0f..8b9da9b7a96850dbd9a5f3c68cf7914e0695820a 100644 --- a/tool/Command.cpp +++ b/tool/Command.cpp @@ -29,6 +29,21 @@ #include "Command.h" #include "MasterDevice.h" +#include "NumberListParser.h" + +/*****************************************************************************/ + +class MasterIndexParser: + public NumberListParser +{ + unsigned int getMax() + { + MasterDevice dev; + dev.setIndex(0U); + dev.open(MasterDevice::Read); + return dev.getMasterCount() - 1; + }; +}; /*****************************************************************************/ @@ -47,9 +62,9 @@ Command::~Command() /*****************************************************************************/ -void Command::setMasterIndices(const MasterIndexList &indices) +void Command::setMasters(const string &m) { - masterIndices = indices; + masters = m; }; /*****************************************************************************/ @@ -172,6 +187,28 @@ void Command::throwSingleSlaveRequired(unsigned int size) const /*****************************************************************************/ +Command::MasterIndexList Command::getMasterIndices() const +{ + MasterIndexList indices; + + try { + MasterIndexParser p; + indices = p.parse(masters.c_str()); + } catch (MasterDeviceException &e) { + stringstream err; + err << "Failed to obtain number of masters: " << e.what(); + throwCommandException(err); + } catch (runtime_error &e) { + stringstream err; + err << "Invalid master argument '" << masters << "': " << e.what(); + throwInvalidUsageException(err); + } + + return indices; +} + +/*****************************************************************************/ + Command::SlaveList Command::selectedSlaves(MasterDevice &m) { ec_ioctl_master_t master; diff --git a/tool/Command.h b/tool/Command.h index a51aa171d29afc4b24637053c2826957ab175541..b98001f89698d36398e746f776b0f97c0ccb4a82 100644 --- a/tool/Command.h +++ b/tool/Command.h @@ -85,8 +85,9 @@ class Command const string &getBriefDescription() const; typedef list<unsigned int> MasterIndexList; - void setMasterIndices(const MasterIndexList &); - const MasterIndexList &getMasterIndices() const; + void setMasters(const string &); + MasterIndexList getMasterIndices() const; + enum Verbosity { Quiet, Normal, @@ -137,7 +138,7 @@ class Command private: string name; string briefDesc; - MasterIndexList masterIndices; + string masters; Verbosity verbosity; int alias; int position; @@ -165,13 +166,6 @@ inline const string &Command::getBriefDescription() const /****************************************************************************/ -inline const Command::MasterIndexList &Command::getMasterIndices() const -{ - return masterIndices; -} - -/****************************************************************************/ - inline Command::Verbosity Command::getVerbosity() const { return verbosity; diff --git a/tool/CommandAlias.cpp b/tool/CommandAlias.cpp index cd7fd8bdf6584f6ec18f5352b5a03e12267459e7..c6d588f336354b26d57b36da908884d192be5ccb 100644 --- a/tool/CommandAlias.cpp +++ b/tool/CommandAlias.cpp @@ -81,6 +81,7 @@ void CommandAlias::execute(const StringVector &args) uint16_t alias; stringstream err, strAlias; int number; + MasterIndexList masterIndices; SlaveList slaves; SlaveList::const_iterator si; @@ -99,11 +100,12 @@ void CommandAlias::execute(const StringVector &args) } alias = number; - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); m.open(MasterDevice::ReadWrite); slaves = selectedSlaves(m); diff --git a/tool/CommandCStruct.cpp b/tool/CommandCStruct.cpp index b49b72e05b76a50a506791b0861667e5a2e59794..a223df20b0dfbe5b46a4bf591ab2a250fd91ab27 100644 --- a/tool/CommandCStruct.cpp +++ b/tool/CommandCStruct.cpp @@ -70,6 +70,7 @@ string CommandCStruct::helpString() const void CommandCStruct::execute(const StringVector &args) { + MasterIndexList masterIndices; SlaveList slaves; SlaveList::const_iterator si; @@ -79,9 +80,10 @@ void CommandCStruct::execute(const StringVector &args) throwInvalidUsageException(err); } + masterIndices = getMasterIndices(); MasterIndexList::const_iterator mi; - for (mi = getMasterIndices().begin(); - mi != getMasterIndices().end(); mi++) { + for (mi = masterIndices.begin(); + mi != masterIndices.end(); mi++) { MasterDevice m(*mi); m.open(MasterDevice::Read); slaves = selectedSlaves(m); diff --git a/tool/CommandConfig.cpp b/tool/CommandConfig.cpp index 6ee8dec42b8fb4a09a89ac9bb69379b6d32b44a8..4cf901b2555c4a9843dd03d36b5d7b67bde1021b 100644 --- a/tool/CommandConfig.cpp +++ b/tool/CommandConfig.cpp @@ -104,8 +104,9 @@ string CommandConfig::helpString() const */ void CommandConfig::execute(const StringVector &args) { - ConfigList configs; + MasterIndexList masterIndices; bool doIndent; + ConfigList configs; if (args.size()) { stringstream err; @@ -113,10 +114,11 @@ void CommandConfig::execute(const StringVector &args) throwInvalidUsageException(err); } - doIndent = getMasterIndices().size() > 1; + masterIndices = getMasterIndices(); + doIndent = masterIndices.size() > 1; MasterIndexList::const_iterator mi; - for (mi = getMasterIndices().begin(); - mi != getMasterIndices().end(); mi++) { + for (mi = masterIndices.begin(); + mi != masterIndices.end(); mi++) { MasterDevice m(*mi); m.open(MasterDevice::Read); configs = selectedConfigs(m); diff --git a/tool/CommandData.cpp b/tool/CommandData.cpp index f7e3952e788d27211a1048c2a530dae03da8e37c..c172a9765de02accd4613299f4119225bae95c4b 100644 --- a/tool/CommandData.cpp +++ b/tool/CommandData.cpp @@ -66,6 +66,7 @@ string CommandData::helpString() const void CommandData::execute(const StringVector &args) { + MasterIndexList masterIndices; DomainList domains; DomainList::const_iterator di; @@ -75,9 +76,10 @@ void CommandData::execute(const StringVector &args) throwInvalidUsageException(err); } + masterIndices = getMasterIndices(); MasterIndexList::const_iterator mi; - for (mi = getMasterIndices().begin(); - mi != getMasterIndices().end(); mi++) { + for (mi = masterIndices.begin(); + mi != masterIndices.end(); mi++) { MasterDevice m(*mi); m.open(MasterDevice::Read); domains = selectedDomains(m); diff --git a/tool/CommandDebug.cpp b/tool/CommandDebug.cpp index ea0582cf833dc88a4638cff536d5ae7a949d3866..0d31441e1df9f8cda630235a22d2be99bb177838 100644 --- a/tool/CommandDebug.cpp +++ b/tool/CommandDebug.cpp @@ -68,6 +68,7 @@ string CommandDebug::helpString() const void CommandDebug::execute(const StringVector &args) { + MasterIndexList masterIndices; stringstream str; int debugLevel; @@ -87,9 +88,10 @@ void CommandDebug::execute(const StringVector &args) throwInvalidUsageException(err); } + masterIndices = getMasterIndices(); MasterIndexList::const_iterator mi; - for (mi = getMasterIndices().begin(); - mi != getMasterIndices().end(); mi++) { + for (mi = masterIndices.begin(); + mi != masterIndices.end(); mi++) { MasterDevice m(*mi); m.open(MasterDevice::ReadWrite); m.setDebug(debugLevel); diff --git a/tool/CommandDomains.cpp b/tool/CommandDomains.cpp index 09b612be40cd5e9f079dc149d579d6247c6af3a7..738868a1a03475487ca25836127fbe83359e9991 100644 --- a/tool/CommandDomains.cpp +++ b/tool/CommandDomains.cpp @@ -92,9 +92,10 @@ string CommandDomains::helpString() const void CommandDomains::execute(const StringVector &args) { + MasterIndexList masterIndices; + bool doIndent; DomainList domains; DomainList::const_iterator di; - bool doIndent; if (args.size()) { stringstream err; @@ -102,10 +103,11 @@ void CommandDomains::execute(const StringVector &args) throwInvalidUsageException(err); } - doIndent = getMasterIndices().size() > 1; + masterIndices = getMasterIndices(); + doIndent = masterIndices.size() > 1; MasterIndexList::const_iterator mi; - for (mi = getMasterIndices().begin(); - mi != getMasterIndices().end(); mi++) { + for (mi = masterIndices.begin(); + mi != masterIndices.end(); mi++) { MasterDevice m(*mi); m.open(MasterDevice::Read); domains = selectedDomains(m); diff --git a/tool/CommandDownload.cpp b/tool/CommandDownload.cpp index ee008f139dcaad1134532b21310b408a399e5d02..fbbfcb44a8abc8c64c1730edba2080917df6d709 100644 --- a/tool/CommandDownload.cpp +++ b/tool/CommandDownload.cpp @@ -85,6 +85,7 @@ 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; @@ -114,11 +115,12 @@ void CommandDownload::execute(const StringVector &args) } data.sdo_entry_subindex = number; - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); m.open(MasterDevice::ReadWrite); slaves = selectedSlaves(m); if (slaves.size() != 1) { diff --git a/tool/CommandEoe.cpp b/tool/CommandEoe.cpp index d972de3928f7a52668c24c62b64cb78091eec1e8..67ad0346a905d8efe14298fd1942cf8576ddc817 100644 --- a/tool/CommandEoe.cpp +++ b/tool/CommandEoe.cpp @@ -63,6 +63,7 @@ string CommandEoe::helpString() const void CommandEoe::execute(const StringVector &args) { + MasterIndexList masterIndices; ec_ioctl_master_t master; unsigned int i; ec_ioctl_eoe_handler_t eoe; @@ -75,11 +76,12 @@ void CommandEoe::execute(const StringVector &args) throwInvalidUsageException(err); } - doIndent = getMasterIndices().size(); + masterIndices = getMasterIndices(); + doIndent = masterIndices.size(); indent = doIndent ? " " : ""; MasterIndexList::const_iterator mi; - for (mi = getMasterIndices().begin(); - mi != getMasterIndices().end(); mi++) { + for (mi = masterIndices.begin(); + mi != masterIndices.end(); mi++) { MasterDevice m(*mi); m.open(MasterDevice::Read); m.getMaster(&master); diff --git a/tool/CommandFoeRead.cpp b/tool/CommandFoeRead.cpp index ab4b5041b93c75430eaa5466acbc54168b2e2748..1afc78551c2dc321ed4e6911f9a87dd36122c786 100644 --- a/tool/CommandFoeRead.cpp +++ b/tool/CommandFoeRead.cpp @@ -76,6 +76,7 @@ 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; @@ -87,11 +88,12 @@ void CommandFoeRead::execute(const StringVector &args) throwInvalidUsageException(err); } - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); m.open(MasterDevice::Read); slaves = selectedSlaves(m); diff --git a/tool/CommandFoeWrite.cpp b/tool/CommandFoeWrite.cpp index 11f0fedb865c94952c21ebb92798a788bdc5b7f5..c1c3139ba5a62de942311a10823e4c84359b8383 100644 --- a/tool/CommandFoeWrite.cpp +++ b/tool/CommandFoeWrite.cpp @@ -82,6 +82,7 @@ string CommandFoeWrite::helpString() const void CommandFoeWrite::execute(const StringVector &args) { + MasterIndexList masterIndices; stringstream err; ec_ioctl_slave_foe_t data; ifstream file; @@ -93,11 +94,12 @@ void CommandFoeWrite::execute(const StringVector &args) throwInvalidUsageException(err); } - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); if (args[0] == "-") { loadFoeData(&data, cin); diff --git a/tool/CommandGraph.cpp b/tool/CommandGraph.cpp index 639c4dd67710f85ef64d613efae7a9f31aeec4ea..78cf2b2f23841c5264238229e9ca10a2208f0b0f 100644 --- a/tool/CommandGraph.cpp +++ b/tool/CommandGraph.cpp @@ -67,6 +67,7 @@ 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; @@ -90,12 +91,13 @@ void CommandGraph::execute(const StringVector &args) throwInvalidUsageException(err); } - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { stringstream err; err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); m.open(MasterDevice::Read); m.getMaster(&master); diff --git a/tool/CommandMaster.cpp b/tool/CommandMaster.cpp index 2a406e6b80740ac9dbb52ca39493271d5b787cdb..fb545437f9a1bf614beaca24dffed6664c7ad4b2 100644 --- a/tool/CommandMaster.cpp +++ b/tool/CommandMaster.cpp @@ -67,6 +67,7 @@ string CommandMaster::helpString() const void CommandMaster::execute(const StringVector &args) { + MasterIndexList masterIndices; ec_ioctl_master_t data; stringstream err; unsigned int i, j; @@ -79,9 +80,10 @@ void CommandMaster::execute(const StringVector &args) throwInvalidUsageException(err); } + masterIndices = getMasterIndices(); MasterIndexList::const_iterator mi; - for (mi = getMasterIndices().begin(); - mi != getMasterIndices().end(); mi++) { + for (mi = masterIndices.begin(); + mi != masterIndices.end(); mi++) { MasterDevice m(*mi); m.open(MasterDevice::Read); m.getMaster(&data); diff --git a/tool/CommandPdos.cpp b/tool/CommandPdos.cpp index 13098c7719f74fba21b7c1f9ee6dfbbcce69f7dc..ccf7d97e4899e5b434c38e0a7d4ccf54b66f2f07 100644 --- a/tool/CommandPdos.cpp +++ b/tool/CommandPdos.cpp @@ -91,6 +91,7 @@ string CommandPdos::helpString() const void CommandPdos::execute(const StringVector &args) { + MasterIndexList masterIndices; SlaveList slaves; SlaveList::const_iterator si; bool showHeader, multiMaster; @@ -101,10 +102,11 @@ void CommandPdos::execute(const StringVector &args) throwInvalidUsageException(err); } - multiMaster = getMasterIndices().size() > 1; + masterIndices = getMasterIndices(); + multiMaster = masterIndices.size() > 1; MasterIndexList::const_iterator mi; - for (mi = getMasterIndices().begin(); - mi != getMasterIndices().end(); mi++) { + for (mi = masterIndices.begin(); + mi != masterIndices.end(); mi++) { MasterDevice m(*mi); m.open(MasterDevice::Read); slaves = selectedSlaves(m); diff --git a/tool/CommandRegRead.cpp b/tool/CommandRegRead.cpp index 8847ba7bcd9becb2c3e63fbb8273e4bae1f85766..65851865352689a7dfd120cfc498a8d92df33ae9 100644 --- a/tool/CommandRegRead.cpp +++ b/tool/CommandRegRead.cpp @@ -79,6 +79,7 @@ string CommandRegRead::helpString() const void CommandRegRead::execute(const StringVector &args) { + MasterIndexList masterIndices; SlaveList slaves; ec_ioctl_slave_reg_t data; stringstream strOffset, err; @@ -140,11 +141,12 @@ void CommandRegRead::execute(const StringVector &args) throwInvalidUsageException(err); } - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); m.open(MasterDevice::Read); slaves = selectedSlaves(m); diff --git a/tool/CommandRegWrite.cpp b/tool/CommandRegWrite.cpp index 0c6ed51292d8648a469475a75a0ac2cfe64014df..6de5034ec526a8e1d736357633a6707bd86b903b 100644 --- a/tool/CommandRegWrite.cpp +++ b/tool/CommandRegWrite.cpp @@ -81,6 +81,7 @@ string CommandRegWrite::helpString() const void CommandRegWrite::execute(const StringVector &args) { + MasterIndexList masterIndices; stringstream strOffset, err; ec_ioctl_slave_reg_t data; ifstream file; @@ -100,11 +101,12 @@ void CommandRegWrite::execute(const StringVector &args) throwInvalidUsageException(err); } - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); if (getDataType().empty()) { if (args[1] == "-") { diff --git a/tool/CommandSdos.cpp b/tool/CommandSdos.cpp index 772c306e833b277610267ab9a9824528f0de5d2d..d194e218d124a42ee07f7a0a34733484a4d327be 100644 --- a/tool/CommandSdos.cpp +++ b/tool/CommandSdos.cpp @@ -89,6 +89,7 @@ string CommandSdos::helpString() const void CommandSdos::execute(const StringVector &args) { + MasterIndexList masterIndices; SlaveList slaves; SlaveList::const_iterator si; bool showHeader, multiMaster; @@ -99,10 +100,11 @@ void CommandSdos::execute(const StringVector &args) throwInvalidUsageException(err); } - multiMaster = getMasterIndices().size() > 1; + masterIndices = getMasterIndices(); + multiMaster = masterIndices.size() > 1; MasterIndexList::const_iterator mi; - for (mi = getMasterIndices().begin(); - mi != getMasterIndices().end(); mi++) { + for (mi = masterIndices.begin(); + mi != masterIndices.end(); mi++) { MasterDevice m(*mi); m.open(MasterDevice::Read); slaves = selectedSlaves(m); diff --git a/tool/CommandSiiRead.cpp b/tool/CommandSiiRead.cpp index 611d6558f24f165b8d9e0dc5d128a46446190903..368b2e598adbe4ddf9867ad5f69ffc68df432a7f 100644 --- a/tool/CommandSiiRead.cpp +++ b/tool/CommandSiiRead.cpp @@ -76,6 +76,7 @@ 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; @@ -89,11 +90,12 @@ void CommandSiiRead::execute(const StringVector &args) throwInvalidUsageException(err); } - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); m.open(MasterDevice::Read); slaves = selectedSlaves(m); diff --git a/tool/CommandSiiWrite.cpp b/tool/CommandSiiWrite.cpp index 2f3a2dd1c07324227eb0acbfa94f090d48a6ddba..4aa3eddd8113beb88a5b08f705bdd7c266a66d7e 100644 --- a/tool/CommandSiiWrite.cpp +++ b/tool/CommandSiiWrite.cpp @@ -78,6 +78,7 @@ string CommandSiiWrite::helpString() const void CommandSiiWrite::execute(const StringVector &args) { + MasterIndexList masterIndices; stringstream err; ec_ioctl_slave_sii_t data; ifstream file; @@ -88,11 +89,12 @@ void CommandSiiWrite::execute(const StringVector &args) throwInvalidUsageException(err); } - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); if (args[0] == "-") { loadSiiData(&data, cin); diff --git a/tool/CommandSlaves.cpp b/tool/CommandSlaves.cpp index 8e4f6bc30d2f8f45ba8bab06660f441b78670cab..fe8cb516f451a7f045923fe027fd34e504db5899 100644 --- a/tool/CommandSlaves.cpp +++ b/tool/CommandSlaves.cpp @@ -108,6 +108,7 @@ string CommandSlaves::helpString() const void CommandSlaves::execute(const StringVector &args) { + MasterIndexList masterIndices; SlaveList slaves; bool doIndent; @@ -117,10 +118,11 @@ void CommandSlaves::execute(const StringVector &args) throwInvalidUsageException(err); } - doIndent = getMasterIndices().size() > 1; + masterIndices = getMasterIndices(); + doIndent = masterIndices.size() > 1; MasterIndexList::const_iterator mi; - for (mi = getMasterIndices().begin(); - mi != getMasterIndices().end(); mi++) { + for (mi = masterIndices.begin(); + mi != masterIndices.end(); mi++) { MasterDevice m(*mi); m.open(MasterDevice::Read); slaves = selectedSlaves(m); diff --git a/tool/CommandSoeRead.cpp b/tool/CommandSoeRead.cpp index 6edb894d3ef9054f2d6cd299127c9fc29c87cea4..d46999a065d48c0c94bda98a38d73baced75547a 100644 --- a/tool/CommandSoeRead.cpp +++ b/tool/CommandSoeRead.cpp @@ -78,6 +78,7 @@ string CommandSoeRead::helpString() const void CommandSoeRead::execute(const StringVector &args) { + MasterIndexList masterIndices; SlaveList slaves; stringstream err; const DataType *dataType = NULL; @@ -95,11 +96,12 @@ void CommandSoeRead::execute(const StringVector &args) throwInvalidUsageException(err); } - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); m.open(MasterDevice::Read); slaves = selectedSlaves(m); if (slaves.size() != 1) { diff --git a/tool/CommandSoeWrite.cpp b/tool/CommandSoeWrite.cpp index a67345b42ce73aa95eac343b94a905df46c766f7..6c348521ae6d4ee372973caf3b8da64702cc95c0 100644 --- a/tool/CommandSoeWrite.cpp +++ b/tool/CommandSoeWrite.cpp @@ -80,6 +80,7 @@ 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; @@ -98,11 +99,12 @@ void CommandSoeWrite::execute(const StringVector &args) throwInvalidUsageException(err); } - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); m.open(MasterDevice::ReadWrite); slaves = selectedSlaves(m); if (slaves.size() != 1) { diff --git a/tool/CommandStates.cpp b/tool/CommandStates.cpp index 24f248bacdcc4ed8998b98aff4c68a80a4504bdc..663979c897b580025ce7684d78d7509dd72aa33b 100644 --- a/tool/CommandStates.cpp +++ b/tool/CommandStates.cpp @@ -68,6 +68,7 @@ string CommandStates::helpString() const void CommandStates::execute(const StringVector &args) { + MasterIndexList masterIndices; SlaveList slaves; SlaveList::const_iterator si; stringstream err; @@ -98,9 +99,10 @@ void CommandStates::execute(const StringVector &args) throwInvalidUsageException(err); } + masterIndices = getMasterIndices(); MasterIndexList::const_iterator mi; - for (mi = getMasterIndices().begin(); - mi != getMasterIndices().end(); mi++) { + for (mi = masterIndices.begin(); + mi != masterIndices.end(); mi++) { MasterDevice m(*mi); m.open(MasterDevice::ReadWrite); slaves = selectedSlaves(m); diff --git a/tool/CommandUpload.cpp b/tool/CommandUpload.cpp index 7a186f54c8c85b7aeab7ed93f8b753c501c986cb..38d3fbf7517e454f01015116baf9a85a203f7f53 100644 --- a/tool/CommandUpload.cpp +++ b/tool/CommandUpload.cpp @@ -82,6 +82,7 @@ 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; @@ -112,11 +113,12 @@ void CommandUpload::execute(const StringVector &args) } data.sdo_entry_subindex = uval; - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); m.open(MasterDevice::Read); slaves = selectedSlaves(m); if (slaves.size() != 1) { diff --git a/tool/CommandXml.cpp b/tool/CommandXml.cpp index 8682fe574ad3c2f6641454cd43ca2afa8e034298..4969fa59045edf86b437cc8c21f49d9f6f61c9ce 100644 --- a/tool/CommandXml.cpp +++ b/tool/CommandXml.cpp @@ -71,6 +71,7 @@ string CommandXml::helpString() const void CommandXml::execute(const StringVector &args) { + MasterIndexList masterIndices; SlaveList slaves; SlaveList::const_iterator si; @@ -80,12 +81,13 @@ void CommandXml::execute(const StringVector &args) throwInvalidUsageException(err); } - if (getMasterIndices().size() != 1) { + masterIndices = getMasterIndices(); + if (masterIndices.size() != 1) { stringstream err; err << getName() << " requires to select a single master!"; throwInvalidUsageException(err); } - MasterDevice m(getMasterIndices().front()); + MasterDevice m(masterIndices.front()); m.open(MasterDevice::Read); slaves = selectedSlaves(m); diff --git a/tool/main.cpp b/tool/main.cpp index 7ccce7b14da15c70fa281aa918485656f7cac0d5..c823fcad8ca0f049e75f62ca525dfaa00eb58f4e 100644 --- a/tool/main.cpp +++ b/tool/main.cpp @@ -63,7 +63,6 @@ using namespace std; #include "CommandVersion.h" #include "CommandXml.h" -#include "NumberListParser.h" #include "MasterDevice.h" /*****************************************************************************/ @@ -76,8 +75,7 @@ string commandName; Command::StringVector commandArgs; // option variables -list<unsigned int> masterIndices; -string masterIndexList = "-"; // all masters +string masters = "-"; // all masters int slavePosition = -1; int slaveAlias = -1; int domainIndex = -1; @@ -113,7 +111,10 @@ string usage() str << endl << "Global options:" << endl - << " --master -m <master> Index of the master to use. Default: 0." + << " --master -m <master> Comma separated list of masters" << endl + << " to select, ranges are allowed." << endl + << " Examples: '1,3', '5-7,9', '-3'." << endl + << " Default: '-' (all)." << endl << " --force -f Force a command." << endl << " --quiet -q Output less information." << endl @@ -132,20 +133,6 @@ string usage() /*****************************************************************************/ -class MasterIndexParser: - public NumberListParser -{ - unsigned int getMax() - { - MasterDevice dev; - dev.setIndex(0U); - dev.open(MasterDevice::Read); - return dev.getMasterCount() - 1; - }; -}; - -/*****************************************************************************/ - void getOptions(int argc, char **argv) { int c, argCount; @@ -171,7 +158,7 @@ void getOptions(int argc, char **argv) switch (c) { case 'm': - masterIndexList = optarg; + masters = optarg; break; case 'a': @@ -261,19 +248,6 @@ void getOptions(int argc, char **argv) } } - try { - MasterIndexParser p; - masterIndices = p.parse(masterIndexList.c_str()); - } catch (MasterDeviceException &e) { - cerr << "Failed to obtain number of masters: " << e.what() << endl; - exit(1); - } catch (runtime_error &e) { - cerr << "Invalid master argument " << masterIndexList - << ": " << e.what() << endl - << endl << usage(); - exit(1); - } - commandName = argv[optind]; while (++optind < argc) commandArgs.push_back(string(argv[optind])); @@ -348,18 +322,12 @@ int main(int argc, char **argv) matchingCommands = getMatchingCommands(commandName); - if (masterIndices.empty()) { - cerr << "List of master indices may not be empty!" << endl - << endl << usage(); - exit(1); - } - if (matchingCommands.size()) { if (matchingCommands.size() == 1) { cmd = matchingCommands.front(); if (!helpRequested) { try { - cmd->setMasterIndices(masterIndices); + cmd->setMasters(masters); cmd->setVerbosity(verbosity); cmd->setAlias(slaveAlias); cmd->setPosition(slavePosition);