Made verbosity a master property; added -Wall flag to tools.
This commit is contained in:
parent
6d5328f0c2
commit
77837ebefb
1
TODO
1
TODO
|
|
@ -14,7 +14,6 @@ Version 1.4.0:
|
|||
* Update documentation.
|
||||
* Add -a and -p switches for 'ethercat config' command.
|
||||
* Add a -n (numeric) switch to ethercat command.
|
||||
* Make verbose and quite flags a master property.
|
||||
* File access over EtherCAT (FoE).
|
||||
* Allow master requesting when in ORPHANED phase
|
||||
* Get original driver for r8169.
|
||||
|
|
|
|||
|
|
@ -37,6 +37,6 @@ ethercat_SOURCES = \
|
|||
Master.cpp Master.h \
|
||||
main.cpp
|
||||
|
||||
ethercat_CFLAGS = -I../master
|
||||
ethercat_CXXFLAGS = -I../master -Wall
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ const CoEDataType *findDataType(uint16_t code)
|
|||
Master::Master()
|
||||
{
|
||||
index = 0;
|
||||
verbosity = Normal;
|
||||
fd = -1;
|
||||
}
|
||||
|
||||
|
|
@ -117,6 +118,13 @@ void Master::setIndex(unsigned int i)
|
|||
index = i;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void Master::setVerbosity(Verbosity v)
|
||||
{
|
||||
verbosity = v;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
|
|
@ -128,9 +136,6 @@ void Master::writeAlias(
|
|||
const vector<string> &commandArgs
|
||||
)
|
||||
{
|
||||
ec_ioctl_slave_sii_t data;
|
||||
ec_ioctl_slave_t slave;
|
||||
unsigned int i;
|
||||
uint16_t alias;
|
||||
stringstream err, strAlias;
|
||||
int number;
|
||||
|
|
@ -176,10 +181,10 @@ void Master::writeAlias(
|
|||
|
||||
/** Lists the bus configuration.
|
||||
*/
|
||||
void Master::showConfigs(bool verbose)
|
||||
void Master::showConfigs()
|
||||
{
|
||||
if (verbose) {
|
||||
showConfigs();
|
||||
if (verbosity == Verbose) {
|
||||
showDetailedConfigs();
|
||||
} else {
|
||||
listConfigs();
|
||||
}
|
||||
|
|
@ -312,7 +317,7 @@ void Master::showMaster()
|
|||
|
||||
/****************************************************************************/
|
||||
|
||||
void Master::listPdos(int slavePosition, bool quiet)
|
||||
void Master::listPdos(int slavePosition)
|
||||
{
|
||||
open(Read);
|
||||
|
||||
|
|
@ -320,16 +325,16 @@ void Master::listPdos(int slavePosition, bool quiet)
|
|||
unsigned int numSlaves = slaveCount(), i;
|
||||
|
||||
for (i = 0; i < numSlaves; i++) {
|
||||
listSlavePdos(i, quiet, true);
|
||||
listSlavePdos(i, true);
|
||||
}
|
||||
} else {
|
||||
listSlavePdos(slavePosition, quiet, false);
|
||||
listSlavePdos(slavePosition, false);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void Master::listSdos(int slavePosition, bool quiet)
|
||||
void Master::listSdos(int slavePosition)
|
||||
{
|
||||
open(Read);
|
||||
|
||||
|
|
@ -337,10 +342,10 @@ void Master::listSdos(int slavePosition, bool quiet)
|
|||
unsigned int numSlaves = slaveCount(), i;
|
||||
|
||||
for (i = 0; i < numSlaves; i++) {
|
||||
listSlaveSdos(i, quiet, true);
|
||||
listSlaveSdos(i, true);
|
||||
}
|
||||
} else {
|
||||
listSlaveSdos(slavePosition, quiet, false);
|
||||
listSlaveSdos(slavePosition, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -354,7 +359,7 @@ void Master::sdoDownload(
|
|||
{
|
||||
stringstream strIndex, strSubIndex, strValue, err;
|
||||
ec_ioctl_slave_sdo_download_t data;
|
||||
unsigned int i, number;
|
||||
unsigned int number;
|
||||
const CoEDataType *dataType = NULL;
|
||||
|
||||
if (slavePosition < 0) {
|
||||
|
|
@ -394,7 +399,6 @@ void Master::sdoDownload(
|
|||
}
|
||||
} else { // no data type specified: fetch from dictionary
|
||||
ec_ioctl_slave_sdo_entry_t entry;
|
||||
unsigned int entryByteSize;
|
||||
|
||||
open(ReadWrite);
|
||||
|
||||
|
|
@ -524,7 +528,7 @@ void Master::sdoUpload(
|
|||
stringstream strIndex, strSubIndex;
|
||||
int sval;
|
||||
ec_ioctl_slave_sdo_upload_t data;
|
||||
unsigned int i, uval;
|
||||
unsigned int uval;
|
||||
const CoEDataType *dataType = NULL;
|
||||
|
||||
if (slavePosition < 0) {
|
||||
|
|
@ -569,7 +573,6 @@ void Master::sdoUpload(
|
|||
}
|
||||
} else { // no data type specified: fetch from dictionary
|
||||
ec_ioctl_slave_sdo_entry_t entry;
|
||||
unsigned int entryByteSize;
|
||||
|
||||
open(Read);
|
||||
|
||||
|
|
@ -665,11 +668,11 @@ void Master::sdoUpload(
|
|||
|
||||
/****************************************************************************/
|
||||
|
||||
void Master::showSlaves(int slavePosition, bool verbose)
|
||||
void Master::showSlaves(int slavePosition)
|
||||
{
|
||||
open(Read);
|
||||
|
||||
if (verbose) {
|
||||
if (verbosity == Verbose) {
|
||||
if (slavePosition == -1) {
|
||||
unsigned int numSlaves = slaveCount(), i;
|
||||
|
||||
|
|
@ -975,7 +978,7 @@ void Master::writeSlaveAlias(
|
|||
|
||||
/** Lists the complete bus configuration.
|
||||
*/
|
||||
void Master::showConfigs()
|
||||
void Master::showDetailedConfigs()
|
||||
{
|
||||
ec_ioctl_master_t master;
|
||||
unsigned int i, j, k, l;
|
||||
|
|
@ -1248,7 +1251,6 @@ void Master::showDomain(unsigned int domainIndex)
|
|||
|
||||
void Master::listSlavePdos(
|
||||
uint16_t slavePosition,
|
||||
bool quiet,
|
||||
bool withHeader
|
||||
)
|
||||
{
|
||||
|
|
@ -1287,7 +1289,7 @@ void Master::listSlavePdos(
|
|||
<< setw(4) << pdo.index
|
||||
<< " \"" << pdo.name << "\"" << endl;
|
||||
|
||||
if (quiet)
|
||||
if (verbosity == Quiet)
|
||||
continue;
|
||||
|
||||
for (k = 0; k < pdo.entry_count; k++) {
|
||||
|
|
@ -1308,14 +1310,13 @@ void Master::listSlavePdos(
|
|||
|
||||
void Master::listSlaveSdos(
|
||||
uint16_t slavePosition,
|
||||
bool quiet,
|
||||
bool withHeader
|
||||
)
|
||||
{
|
||||
ec_ioctl_slave_t slave;
|
||||
ec_ioctl_slave_sdo_t sdo;
|
||||
ec_ioctl_slave_sdo_entry_t entry;
|
||||
unsigned int i, j, k;
|
||||
unsigned int i, j;
|
||||
const CoEDataType *d;
|
||||
|
||||
getSlave(&slave, slavePosition);
|
||||
|
|
@ -1331,7 +1332,7 @@ void Master::listSlaveSdos(
|
|||
<< setw(4) << sdo.sdo_index
|
||||
<< ", \"" << sdo.name << "\"" << endl;
|
||||
|
||||
if (quiet)
|
||||
if (verbosity == Quiet)
|
||||
continue;
|
||||
|
||||
for (j = 0; j <= sdo.max_subindex; j++) {
|
||||
|
|
@ -1392,7 +1393,7 @@ void Master::listSlaves(int slavePosition)
|
|||
aliasIndex = 0;
|
||||
}
|
||||
|
||||
if (slavePosition == -1 || i == slavePosition) {
|
||||
if (slavePosition == -1 || i == (unsigned int) slavePosition) {
|
||||
str << dec << i;
|
||||
slaveInfo.pos = str.str();
|
||||
str.clear();
|
||||
|
|
|
|||
|
|
@ -42,17 +42,24 @@ class Master
|
|||
|
||||
void setIndex(unsigned int);
|
||||
|
||||
enum Verbosity {
|
||||
Quiet,
|
||||
Normal,
|
||||
Verbose
|
||||
};
|
||||
void setVerbosity(Verbosity);
|
||||
|
||||
void writeAlias(int, bool, const vector<string> &);
|
||||
void showConfigs(bool);
|
||||
void showConfigs();
|
||||
void outputData(int);
|
||||
void setDebug(const vector<string> &);
|
||||
void showDomains(int);
|
||||
void showMaster();
|
||||
void listPdos(int, bool = false);
|
||||
void listSdos(int, bool = false);
|
||||
void listPdos(int);
|
||||
void listSdos(int);
|
||||
void sdoDownload(int, const string &, const vector<string> &);
|
||||
void sdoUpload(int, const string &, const vector<string> &);
|
||||
void showSlaves(int, bool);
|
||||
void showSlaves(int);
|
||||
void siiRead(int);
|
||||
void siiWrite(int, bool, const vector<string> &);
|
||||
void requestStates(int, const vector<string> &);
|
||||
|
|
@ -64,12 +71,12 @@ class Master
|
|||
void close();
|
||||
|
||||
void writeSlaveAlias(uint16_t, uint16_t);
|
||||
void showConfigs();
|
||||
void showDetailedConfigs();
|
||||
void listConfigs();
|
||||
void outputDomainData(unsigned int);
|
||||
void showDomain(unsigned int);
|
||||
void listSlavePdos(uint16_t, bool = false, bool = false);
|
||||
void listSlaveSdos(uint16_t, bool = false, bool = false);
|
||||
void listSlavePdos(uint16_t, bool = false);
|
||||
void listSlaveSdos(uint16_t, bool = false);
|
||||
void listSlaves(int);
|
||||
void showSlave(uint16_t);
|
||||
void generateSlaveXml(uint16_t);
|
||||
|
|
@ -102,6 +109,7 @@ class Master
|
|||
enum {DefaultBufferSize = 1024};
|
||||
|
||||
unsigned int index;
|
||||
Verbosity verbosity;
|
||||
int fd;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ static int slavePosition = -1;
|
|||
static int domainIndex = -1;
|
||||
static string command;
|
||||
vector<string> commandArgs;
|
||||
static bool quiet = false;
|
||||
static bool verbose = false;
|
||||
static Master::Verbosity verbosity = Master::Normal;
|
||||
string dataTypeStr;
|
||||
bool force = false;
|
||||
|
||||
|
|
@ -141,13 +140,11 @@ void getOptions(int argc, char **argv)
|
|||
break;
|
||||
|
||||
case 'q':
|
||||
quiet = true;
|
||||
verbose = false;
|
||||
verbosity = Master::Quiet;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose = true;
|
||||
quiet = false;
|
||||
verbosity = Master::Verbose;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
|
|
@ -182,13 +179,14 @@ int main(int argc, char **argv)
|
|||
|
||||
getOptions(argc, argv);
|
||||
|
||||
try {
|
||||
master.setIndex(masterIndex);
|
||||
master.setIndex(masterIndex);
|
||||
master.setVerbosity(verbosity);
|
||||
|
||||
try {
|
||||
if (command == "alias") {
|
||||
master.writeAlias(slavePosition, force, commandArgs);
|
||||
} else if (command == "config") {
|
||||
master.showConfigs(verbose);
|
||||
master.showConfigs();
|
||||
} else if (command == "data") {
|
||||
master.outputData(domainIndex);
|
||||
} else if (command == "debug") {
|
||||
|
|
@ -198,16 +196,16 @@ int main(int argc, char **argv)
|
|||
} else if (command == "master") {
|
||||
master.showMaster();
|
||||
} else if (command == "pdos") {
|
||||
master.listPdos(slavePosition, quiet);
|
||||
master.listPdos(slavePosition);
|
||||
} else if (command == "sdos") {
|
||||
master.listSdos(slavePosition, quiet);
|
||||
master.listSdos(slavePosition);
|
||||
} else if (command == "sdo_download" || command == "sd") {
|
||||
master.sdoDownload(slavePosition, dataTypeStr, commandArgs);
|
||||
} else if (command == "sdo_upload" || command == "su") {
|
||||
master.sdoUpload(slavePosition, dataTypeStr, commandArgs);
|
||||
} else if (command == "slave" || command == "slaves"
|
||||
|| command == "list" || command == "ls") {
|
||||
master.showSlaves(slavePosition, verbose);
|
||||
master.showSlaves(slavePosition);
|
||||
} else if (command == "sii_read" || command == "sr") {
|
||||
master.siiRead(slavePosition);
|
||||
} else if (command == "sii_write" || command == "sw") {
|
||||
|
|
|
|||
Loading…
Reference in New Issue