Skip to content
Snippets Groups Projects
Commit c19f0c6d authored by Florian Pose's avatar Florian Pose
Browse files

Added multi-slave support.

parent 902865c3
No related branches found
No related tags found
No related merge requests found
...@@ -98,6 +98,21 @@ void Master::listSlaves() ...@@ -98,6 +98,21 @@ void Master::listSlaves()
/****************************************************************************/ /****************************************************************************/
void Master::listPdos(int slavePosition) 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_slave_t slave;
ec_ioctl_sync_t sync; ec_ioctl_sync_t sync;
...@@ -107,6 +122,9 @@ void Master::listPdos(int slavePosition) ...@@ -107,6 +122,9 @@ void Master::listPdos(int slavePosition)
getSlave(&slave, slavePosition); getSlave(&slave, slavePosition);
if (printSlave)
cout << "=== Slave " << slavePosition << " ===" << endl;
for (i = 0; i < slave.sync_count; i++) { for (i = 0; i < slave.sync_count; i++) {
getSync(&sync, slavePosition, i); getSync(&sync, slavePosition, i);
......
...@@ -44,6 +44,7 @@ class Master ...@@ -44,6 +44,7 @@ class Master
void listPdos(int); void listPdos(int);
protected: protected:
void listSlavePdos(uint16_t, bool = false);
unsigned int slaveCount(); unsigned int slaveCount();
void slaveSyncs(uint16_t); void slaveSyncs(uint16_t);
void getSlave(ec_ioctl_slave_t *, uint16_t); void getSlave(ec_ioctl_slave_t *, uint16_t);
......
...@@ -16,10 +16,10 @@ using namespace std; ...@@ -16,10 +16,10 @@ using namespace std;
#define DEFAULT_MASTER 0 #define DEFAULT_MASTER 0
#define DEFAULT_COMMAND "slaves" #define DEFAULT_COMMAND "slaves"
#define DEFAULT_SLAVESPEC "" #define DEFAULT_SLAVEPOSITION -1
static unsigned int masterIndex = DEFAULT_MASTER; static unsigned int masterIndex = DEFAULT_MASTER;
static int slavePosition = -1; static int slavePosition = DEFAULT_SLAVEPOSITION;
static string command = DEFAULT_COMMAND; static string command = DEFAULT_COMMAND;
/*****************************************************************************/ /*****************************************************************************/
...@@ -34,8 +34,10 @@ void printUsage() ...@@ -34,8 +34,10 @@ void printUsage()
<< "Global options:" << endl << "Global options:" << endl
<< " --master -m <master> Index of the master to use. Default: " << " --master -m <master> Index of the master to use. Default: "
<< DEFAULT_MASTER << endl << DEFAULT_MASTER << endl
<< " --slave -s <slave> Numerical ring position. Default: All " << " --slave -s <slave> Positive numerical ring position,"
"slaves." << endl << endl
<< " or 'all' for all slaves. Default: 'all'."
<< endl
<< " --help -h Show this help." << endl; << " --help -h Show this help." << endl;
} }
...@@ -69,14 +71,19 @@ void getOptions(int argc, char **argv) ...@@ -69,14 +71,19 @@ void getOptions(int argc, char **argv)
break; break;
case 's': case 's':
number = strtoul(optarg, &remainder, 0); if (!strcmp(optarg, "all")) {
if (remainder == optarg || *remainder slavePosition = -1;
|| number < 0 || number > 0xFFFF) { } else {
cerr << "Invalid slave position " << optarg << "!" << endl; number = strtoul(optarg, &remainder, 0);
printUsage(); if (remainder == optarg || *remainder
exit(1); || number < 0 || number > 0xFFFF) {
cerr << "Invalid slave position "
<< optarg << "!" << endl;
printUsage();
exit(1);
}
slavePosition = number;
} }
slavePosition = number;
break; break;
case 'h': case 'h':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment