Added multi-slave support.
--- a/tools/Master.cpp Mon Jun 02 10:51:31 2008 +0000
+++ b/tools/Master.cpp Mon Jun 02 11:08:49 2008 +0000
@@ -99,6 +99,21 @@
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;
ec_ioctl_pdo_t pdo;
@@ -107,6 +122,9 @@
getSlave(&slave, slavePosition);
+ if (printSlave)
+ cout << "=== Slave " << slavePosition << " ===" << endl;
+
for (i = 0; i < slave.sync_count; i++) {
getSync(&sync, slavePosition, i);
--- a/tools/Master.h Mon Jun 02 10:51:31 2008 +0000
+++ b/tools/Master.h Mon Jun 02 11:08:49 2008 +0000
@@ -44,6 +44,7 @@
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);
--- a/tools/main.cpp Mon Jun 02 10:51:31 2008 +0000
+++ b/tools/main.cpp Mon Jun 02 11:08:49 2008 +0000
@@ -16,10 +16,10 @@
#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 @@
<< "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 @@
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':