Added multi-slave support.

This commit is contained in:
Florian Pose 2008-06-02 11:08:49 +00:00
parent fd77ad604d
commit d2971535c9
3 changed files with 37 additions and 11 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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':