# HG changeset patch # User Florian Pose # Date 1212404929 0 # Node ID 30fddfce8db6acb27273f1efc8af4d9b86989b33 # Parent b954e9d91ea5132123a04d55086a5c80f7f9e7b2 Added multi-slave support. diff -r b954e9d91ea5 -r 30fddfce8db6 tools/Master.cpp --- 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); diff -r b954e9d91ea5 -r 30fddfce8db6 tools/Master.h --- 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); diff -r b954e9d91ea5 -r 30fddfce8db6 tools/main.cpp --- 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 Index of the master to use. Default: " << DEFAULT_MASTER << endl - << " --slave -s Numerical ring position. Default: All " - "slaves." << endl + << " --slave -s 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':