United 'ethercat slaves' and 'ethercat list' with a verbose flag.
This commit is contained in:
parent
be9e9fd07d
commit
5e4ed4b154
205
tools/Master.cpp
205
tools/Master.cpp
|
|
@ -334,97 +334,6 @@ void Master::showDomains(int domainIndex)
|
|||
|
||||
/****************************************************************************/
|
||||
|
||||
struct SlaveInfo {
|
||||
string pos;
|
||||
string alias;
|
||||
string relPos;
|
||||
string state;
|
||||
string flag;
|
||||
string name;
|
||||
};
|
||||
|
||||
void Master::listSlaves()
|
||||
{
|
||||
unsigned int numSlaves, i;
|
||||
ec_ioctl_slave_t slave;
|
||||
uint16_t lastAlias, aliasIndex;
|
||||
SlaveInfo slaveInfo;
|
||||
typedef list<SlaveInfo> SlaveInfoList;
|
||||
SlaveInfoList slaveInfoList;
|
||||
SlaveInfoList::const_iterator iter;
|
||||
stringstream str;
|
||||
unsigned int maxPosWidth = 0, maxAliasWidth = 0,
|
||||
maxRelPosWidth = 0, maxStateWidth = 0;
|
||||
|
||||
open(Read);
|
||||
|
||||
numSlaves = slaveCount();
|
||||
|
||||
lastAlias = 0;
|
||||
aliasIndex = 0;
|
||||
for (i = 0; i < numSlaves; i++) {
|
||||
getSlave(&slave, i);
|
||||
|
||||
str << dec << i;
|
||||
slaveInfo.pos = str.str();
|
||||
str.clear();
|
||||
str.str("");
|
||||
|
||||
if (slave.alias) {
|
||||
lastAlias = slave.alias;
|
||||
aliasIndex = 0;
|
||||
}
|
||||
if (lastAlias) {
|
||||
str << "#" << hex << lastAlias;
|
||||
slaveInfo.alias = str.str();
|
||||
str.str("");
|
||||
str << ":" << dec << aliasIndex;
|
||||
slaveInfo.relPos = str.str();
|
||||
str.str("");
|
||||
aliasIndex++;
|
||||
} else {
|
||||
slaveInfo.alias = "";
|
||||
slaveInfo.relPos = "";
|
||||
}
|
||||
|
||||
slaveInfo.state = slaveState(slave.state);
|
||||
slaveInfo.flag = (slave.error_flag ? 'E' : '+');
|
||||
|
||||
if (strlen(slave.name)) {
|
||||
slaveInfo.name = slave.name;
|
||||
} else {
|
||||
str << hex << setfill('0')
|
||||
<< setw(8) << slave.vendor_id << ":"
|
||||
<< setw(8) << slave.product_code;
|
||||
slaveInfo.name = str.str();
|
||||
str.str("");
|
||||
}
|
||||
|
||||
slaveInfoList.push_back(slaveInfo);
|
||||
if (slaveInfo.pos.length() > maxPosWidth)
|
||||
maxPosWidth = slaveInfo.pos.length();
|
||||
if (slaveInfo.alias.length() > maxAliasWidth)
|
||||
maxAliasWidth = slaveInfo.alias.length();
|
||||
if (slaveInfo.relPos.length() > maxRelPosWidth)
|
||||
maxRelPosWidth = slaveInfo.relPos.length();
|
||||
if (slaveInfo.state.length() > maxStateWidth)
|
||||
maxStateWidth = slaveInfo.state.length();
|
||||
}
|
||||
|
||||
for (iter = slaveInfoList.begin(); iter != slaveInfoList.end(); iter++) {
|
||||
cout << setfill(' ') << right
|
||||
<< setw(maxPosWidth) << iter->pos << " "
|
||||
<< setw(maxAliasWidth) << iter->alias
|
||||
<< left
|
||||
<< setw(maxRelPosWidth) << iter->relPos << " "
|
||||
<< setw(maxStateWidth) << iter->state << " "
|
||||
<< iter->flag << " "
|
||||
<< iter->name << endl;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void Master::showMaster()
|
||||
{
|
||||
ec_ioctl_master_t data;
|
||||
|
|
@ -821,18 +730,22 @@ void Master::sdoUpload(
|
|||
|
||||
/****************************************************************************/
|
||||
|
||||
void Master::showSlaves(int slavePosition)
|
||||
void Master::showSlaves(int slavePosition, bool verbose)
|
||||
{
|
||||
open(Read);
|
||||
|
||||
if (slavePosition == -1) {
|
||||
unsigned int numSlaves = slaveCount(), i;
|
||||
if (verbose) {
|
||||
if (slavePosition == -1) {
|
||||
unsigned int numSlaves = slaveCount(), i;
|
||||
|
||||
for (i = 0; i < numSlaves; i++) {
|
||||
showSlave(i);
|
||||
for (i = 0; i < numSlaves; i++) {
|
||||
showSlave(i);
|
||||
}
|
||||
} else {
|
||||
showSlave(slavePosition);
|
||||
}
|
||||
} else {
|
||||
showSlave(slavePosition);
|
||||
listSlaves(slavePosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1325,6 +1238,104 @@ void Master::listSlaveSdos(
|
|||
|
||||
/****************************************************************************/
|
||||
|
||||
struct SlaveInfo {
|
||||
string pos;
|
||||
string alias;
|
||||
string relPos;
|
||||
string state;
|
||||
string flag;
|
||||
string name;
|
||||
};
|
||||
|
||||
void Master::listSlaves(int slavePosition)
|
||||
{
|
||||
unsigned int numSlaves, i;
|
||||
ec_ioctl_slave_t slave;
|
||||
uint16_t lastAlias, aliasIndex;
|
||||
SlaveInfo slaveInfo;
|
||||
typedef list<SlaveInfo> SlaveInfoList;
|
||||
SlaveInfoList slaveInfoList;
|
||||
SlaveInfoList::const_iterator iter;
|
||||
stringstream str;
|
||||
unsigned int maxPosWidth = 0, maxAliasWidth = 0,
|
||||
maxRelPosWidth = 0, maxStateWidth = 0;
|
||||
|
||||
open(Read);
|
||||
|
||||
numSlaves = slaveCount();
|
||||
|
||||
lastAlias = 0;
|
||||
aliasIndex = 0;
|
||||
for (i = 0; i < numSlaves; i++) {
|
||||
getSlave(&slave, i);
|
||||
|
||||
if (slave.alias) {
|
||||
lastAlias = slave.alias;
|
||||
aliasIndex = 0;
|
||||
}
|
||||
|
||||
if (slavePosition == -1 || i == slavePosition) {
|
||||
str << dec << i;
|
||||
slaveInfo.pos = str.str();
|
||||
str.clear();
|
||||
str.str("");
|
||||
|
||||
if (lastAlias) {
|
||||
str << "#" << hex << lastAlias;
|
||||
slaveInfo.alias = str.str();
|
||||
str.str("");
|
||||
str << ":" << dec << aliasIndex;
|
||||
slaveInfo.relPos = str.str();
|
||||
str.str("");
|
||||
} else {
|
||||
slaveInfo.alias = "";
|
||||
slaveInfo.relPos = "";
|
||||
}
|
||||
|
||||
slaveInfo.state = slaveState(slave.state);
|
||||
slaveInfo.flag = (slave.error_flag ? 'E' : '+');
|
||||
|
||||
if (strlen(slave.name)) {
|
||||
slaveInfo.name = slave.name;
|
||||
} else {
|
||||
str << hex << setfill('0')
|
||||
<< setw(8) << slave.vendor_id << ":"
|
||||
<< setw(8) << slave.product_code;
|
||||
slaveInfo.name = str.str();
|
||||
str.str("");
|
||||
}
|
||||
|
||||
|
||||
slaveInfoList.push_back(slaveInfo);
|
||||
|
||||
if (slaveInfo.pos.length() > maxPosWidth)
|
||||
maxPosWidth = slaveInfo.pos.length();
|
||||
if (slaveInfo.alias.length() > maxAliasWidth)
|
||||
maxAliasWidth = slaveInfo.alias.length();
|
||||
if (slaveInfo.relPos.length() > maxRelPosWidth)
|
||||
maxRelPosWidth = slaveInfo.relPos.length();
|
||||
if (slaveInfo.state.length() > maxStateWidth)
|
||||
maxStateWidth = slaveInfo.state.length();
|
||||
}
|
||||
|
||||
if (lastAlias)
|
||||
aliasIndex++;
|
||||
}
|
||||
|
||||
for (iter = slaveInfoList.begin(); iter != slaveInfoList.end(); iter++) {
|
||||
cout << setfill(' ') << right
|
||||
<< setw(maxPosWidth) << iter->pos << " "
|
||||
<< setw(maxAliasWidth) << iter->alias
|
||||
<< left
|
||||
<< setw(maxRelPosWidth) << iter->relPos << " "
|
||||
<< setw(maxStateWidth) << iter->state << " "
|
||||
<< iter->flag << " "
|
||||
<< iter->name << endl;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void Master::showSlave(uint16_t slavePosition)
|
||||
{
|
||||
ec_ioctl_slave_t slave;
|
||||
|
|
|
|||
|
|
@ -47,13 +47,12 @@ class Master
|
|||
void outputData(int);
|
||||
void setDebug(const vector<string> &);
|
||||
void showDomains(int);
|
||||
void listSlaves();
|
||||
void showMaster();
|
||||
void listPdos(int, bool = false);
|
||||
void listSdos(int, bool = false);
|
||||
void sdoDownload(int, const string &, const vector<string> &);
|
||||
void sdoUpload(int, const string &, const vector<string> &);
|
||||
void showSlaves(int);
|
||||
void showSlaves(int, bool);
|
||||
void siiRead(int);
|
||||
void siiWrite(int, bool, const vector<string> &);
|
||||
void requestStates(int, const vector<string> &);
|
||||
|
|
@ -69,6 +68,7 @@ class Master
|
|||
void showDomain(unsigned int);
|
||||
void listSlavePdos(uint16_t, bool = false, bool = false);
|
||||
void listSlaveSdos(uint16_t, bool = false, bool = false);
|
||||
void listSlaves(int);
|
||||
void showSlave(uint16_t);
|
||||
void generateSlaveXml(uint16_t);
|
||||
unsigned int slaveCount();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ static int domainIndex = -1;
|
|||
static string command;
|
||||
vector<string> commandArgs;
|
||||
static bool quiet = false;
|
||||
static bool verbose = false;
|
||||
string dataTypeStr;
|
||||
bool force = false;
|
||||
|
||||
|
|
@ -33,22 +34,21 @@ void printUsage()
|
|||
cerr
|
||||
<< "Usage: ethercat <COMMAND> [OPTIONS]" << endl
|
||||
<< "Commands:" << endl
|
||||
<< " alias Write alias address(es)." << endl
|
||||
<< " config Show slave configurations." << endl
|
||||
<< " data Output binary domain process data." << endl
|
||||
<< " debug Set the master debug level." << endl
|
||||
<< " domain Show domain information." << endl
|
||||
<< " list (ls) List all slaves (former 'lsec')." << endl
|
||||
<< " master Show master information." << endl
|
||||
<< " pdos List Pdo mapping." << endl
|
||||
<< " sdos List Sdo dictionaries." << endl
|
||||
<< " sdo_download (sd) Write an Sdo entry." << endl
|
||||
<< " sdo_upload (su) Read an Sdo entry." << endl
|
||||
<< " slave Show slave information." << endl
|
||||
<< " sii_read (sr) Output a slave's SII contents." << endl
|
||||
<< " sii_write (sw) Write slave's SII contents." << endl
|
||||
<< " state Request slave states." << endl
|
||||
<< " xml Generate slave information xmls." << endl
|
||||
<< " alias Write alias addresses." << endl
|
||||
<< " config Show bus configuration." << endl
|
||||
<< " data Output binary domain process data." << endl
|
||||
<< " debug Set the master's debug level." << endl
|
||||
<< " domain Show domain information." << endl
|
||||
<< " master Show master information." << endl
|
||||
<< " pdos List Pdo assignment/mapping." << endl
|
||||
<< " sdo_download Write an Sdo entry." << endl
|
||||
<< " sdos List Sdo dictionaries." << endl
|
||||
<< " sdo_upload Read an Sdo entry." << endl
|
||||
<< " sii_read Output a slave's SII contents." << endl
|
||||
<< " sii_write Write slave's SII contents." << endl
|
||||
<< " slaves Show slaves." << endl
|
||||
<< " state Request slave states." << endl
|
||||
<< " xml Generate slave information xmls." << endl
|
||||
<< "Global options:" << endl
|
||||
<< " --master -m <master> Index of the master to use. Default: "
|
||||
<< DEFAULT_MASTER << endl
|
||||
|
|
@ -62,7 +62,8 @@ void printUsage()
|
|||
<< endl
|
||||
<< " --type -t <type> Forced Sdo data type." << endl
|
||||
<< " --force -f Force action." << endl
|
||||
<< " --quiet -q Show less output." << endl
|
||||
<< " --quiet -q Output less information." << endl
|
||||
<< " --verbose -v Output more information." << endl
|
||||
<< " --help -h Show this help." << endl;
|
||||
}
|
||||
|
||||
|
|
@ -74,19 +75,20 @@ void getOptions(int argc, char **argv)
|
|||
char *remainder;
|
||||
|
||||
static struct option longOptions[] = {
|
||||
//name, has_arg, flag, val
|
||||
{"master", required_argument, NULL, 'm'},
|
||||
{"slave", required_argument, NULL, 's'},
|
||||
{"domain", required_argument, NULL, 'd'},
|
||||
{"type", required_argument, NULL, 't'},
|
||||
{"force", no_argument, NULL, 'f'},
|
||||
{"quiet", no_argument, NULL, 'q'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
//name, has_arg, flag, val
|
||||
{"master", required_argument, NULL, 'm'},
|
||||
{"slave", required_argument, NULL, 's'},
|
||||
{"domain", required_argument, NULL, 'd'},
|
||||
{"type", required_argument, NULL, 't'},
|
||||
{"force", no_argument, NULL, 'f'},
|
||||
{"quiet", no_argument, NULL, 'q'},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{}
|
||||
};
|
||||
|
||||
do {
|
||||
c = getopt_long(argc, argv, "m:s:d:t:fqh", longOptions, &optionIndex);
|
||||
c = getopt_long(argc, argv, "m:s:d:t:fqvh", longOptions, &optionIndex);
|
||||
|
||||
switch (c) {
|
||||
case 'm':
|
||||
|
|
@ -140,6 +142,12 @@ void getOptions(int argc, char **argv)
|
|||
|
||||
case 'q':
|
||||
quiet = true;
|
||||
verbose = false;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose = true;
|
||||
quiet = false;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
|
|
@ -187,8 +195,6 @@ int main(int argc, char **argv)
|
|||
master.setDebug(commandArgs);
|
||||
} else if (command == "domain") {
|
||||
master.showDomains(domainIndex);
|
||||
} else if (command == "list" || command == "ls") {
|
||||
master.listSlaves();
|
||||
} else if (command == "master") {
|
||||
master.showMaster();
|
||||
} else if (command == "pdos") {
|
||||
|
|
@ -199,8 +205,9 @@ int main(int argc, char **argv)
|
|||
master.sdoDownload(slavePosition, dataTypeStr, commandArgs);
|
||||
} else if (command == "sdo_upload" || command == "su") {
|
||||
master.sdoUpload(slavePosition, dataTypeStr, commandArgs);
|
||||
} else if (command == "slave") {
|
||||
master.showSlaves(slavePosition);
|
||||
} else if (command == "slave" || command == "slaves"
|
||||
|| command == "list" || command == "ls") {
|
||||
master.showSlaves(slavePosition, verbose);
|
||||
} else if (command == "sii_read" || command == "sr") {
|
||||
master.siiRead(slavePosition);
|
||||
} else if (command == "sii_write" || command == "sw") {
|
||||
|
|
|
|||
Loading…
Reference in New Issue