diff --git a/tools/Master.cpp b/tools/Master.cpp index d0bc9da3f8695f82318d2079bd29afd30db5fa74..3e3a71dd085741c9cedfc1730884c8e844a81709 100644 --- a/tools/Master.cpp +++ b/tools/Master.cpp @@ -98,6 +98,21 @@ void Master::listSlaves() /****************************************************************************/ void Master::listPdos(int slavePosition) +{ + if (slavePosition == -1) { + unsigned int numSlaves = slaveCount(), i; + + for (i = 0; i < numSlaves; i++) { + listSlavePdos(i, true); + } + } else { + listSlavePdos(slavePosition, false); + } +} + +/****************************************************************************/ + +void Master::listSlavePdos(uint16_t slavePosition, bool printSlave) { ec_ioctl_slave_t slave; ec_ioctl_sync_t sync; @@ -107,6 +122,9 @@ void Master::listPdos(int slavePosition) getSlave(&slave, slavePosition); + if (printSlave) + cout << "=== Slave " << slavePosition << " ===" << endl; + for (i = 0; i < slave.sync_count; i++) { getSync(&sync, slavePosition, i); diff --git a/tools/Master.h b/tools/Master.h index f96f5c211d53f8add14587badc8a8de6107577ba..6a589f4c8bf9ec7be38e148bfa148ca2041d2fc1 100644 --- a/tools/Master.h +++ b/tools/Master.h @@ -44,6 +44,7 @@ class Master void listPdos(int); protected: + void listSlavePdos(uint16_t, bool = false); unsigned int slaveCount(); void slaveSyncs(uint16_t); void getSlave(ec_ioctl_slave_t *, uint16_t); diff --git a/tools/main.cpp b/tools/main.cpp index 6e32e5caed009de7d4c8b7882e1eebaa9a961c13..7267ace6c3a72fc286562bd0947c24e61c9a953a 100644 --- a/tools/main.cpp +++ b/tools/main.cpp @@ -16,10 +16,10 @@ using namespace std; #define DEFAULT_MASTER 0 #define DEFAULT_COMMAND "slaves" -#define DEFAULT_SLAVESPEC "" +#define DEFAULT_SLAVEPOSITION -1 static unsigned int masterIndex = DEFAULT_MASTER; -static int slavePosition = -1; +static int slavePosition = DEFAULT_SLAVEPOSITION; static string command = DEFAULT_COMMAND; /*****************************************************************************/ @@ -34,8 +34,10 @@ void printUsage() << "Global options:" << endl << " --master -m <master> Index of the master to use. Default: " << DEFAULT_MASTER << endl - << " --slave -s <slave> Numerical ring position. Default: All " - "slaves." << endl + << " --slave -s <slave> Positive numerical ring position," + << endl + << " or 'all' for all slaves. Default: 'all'." + << endl << " --help -h Show this help." << endl; } @@ -69,14 +71,19 @@ void getOptions(int argc, char **argv) break; case 's': - number = strtoul(optarg, &remainder, 0); - if (remainder == optarg || *remainder - || number < 0 || number > 0xFFFF) { - cerr << "Invalid slave position " << optarg << "!" << endl; - printUsage(); - exit(1); + if (!strcmp(optarg, "all")) { + slavePosition = -1; + } else { + number = strtoul(optarg, &remainder, 0); + if (remainder == optarg || *remainder + || number < 0 || number > 0xFFFF) { + cerr << "Invalid slave position " + << optarg << "!" << endl; + printUsage(); + exit(1); + } + slavePosition = number; } - slavePosition = number; break; case 'h':