# HG changeset patch # User Florian Pose # Date 1215417341 0 # Node ID eb8d16507d8833edff4251385c957d0fb31e1891 # Parent ff5b1722581c091b10777607d1612108bcb858ca Made verbosity a master property; added -Wall flag to tools. diff -r ff5b1722581c -r eb8d16507d88 TODO --- a/TODO Mon Jul 07 07:38:10 2008 +0000 +++ b/TODO Mon Jul 07 07:55:41 2008 +0000 @@ -14,7 +14,6 @@ * 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. diff -r ff5b1722581c -r eb8d16507d88 tools/Makefile.am --- a/tools/Makefile.am Mon Jul 07 07:38:10 2008 +0000 +++ b/tools/Makefile.am Mon Jul 07 07:55:41 2008 +0000 @@ -37,6 +37,6 @@ Master.cpp Master.h \ main.cpp -ethercat_CFLAGS = -I../master +ethercat_CXXFLAGS = -I../master -Wall #------------------------------------------------------------------------------ diff -r ff5b1722581c -r eb8d16507d88 tools/Master.cpp --- a/tools/Master.cpp Mon Jul 07 07:38:10 2008 +0000 +++ b/tools/Master.cpp Mon Jul 07 07:55:41 2008 +0000 @@ -100,6 +100,7 @@ Master::Master() { index = 0; + verbosity = Normal; fd = -1; } @@ -117,6 +118,13 @@ index = i; } +/****************************************************************************/ + +void Master::setVerbosity(Verbosity v) +{ + verbosity = v; +} + /*****************************************************************************/ /** @@ -128,9 +136,6 @@ const vector &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 @@ /** Lists the bus configuration. */ -void Master::showConfigs(bool verbose) -{ - if (verbose) { - showConfigs(); +void Master::showConfigs() +{ + if (verbosity == Verbose) { + showDetailedConfigs(); } else { listConfigs(); } @@ -312,7 +317,7 @@ /****************************************************************************/ -void Master::listPdos(int slavePosition, bool quiet) +void Master::listPdos(int slavePosition) { open(Read); @@ -320,16 +325,16 @@ unsigned int numSlaves = slaveCount(), i; for (i = 0; i < numSlaves; i++) { - listSlavePdos(i, quiet, true); + listSlavePdos(i, true); } } else { - listSlavePdos(slavePosition, quiet, false); - } -} - -/****************************************************************************/ - -void Master::listSdos(int slavePosition, bool quiet) + listSlavePdos(slavePosition, false); + } +} + +/****************************************************************************/ + +void Master::listSdos(int slavePosition) { open(Read); @@ -337,10 +342,10 @@ 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 @@ { 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 @@ } } else { // no data type specified: fetch from dictionary ec_ioctl_slave_sdo_entry_t entry; - unsigned int entryByteSize; open(ReadWrite); @@ -524,7 +528,7 @@ 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 @@ } } 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::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 @@ /** 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::listSlavePdos( uint16_t slavePosition, - bool quiet, bool withHeader ) { @@ -1287,7 +1289,7 @@ << 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::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 @@ << 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 @@ aliasIndex = 0; } - if (slavePosition == -1 || i == slavePosition) { + if (slavePosition == -1 || i == (unsigned int) slavePosition) { str << dec << i; slaveInfo.pos = str.str(); str.clear(); diff -r ff5b1722581c -r eb8d16507d88 tools/Master.h --- a/tools/Master.h Mon Jul 07 07:38:10 2008 +0000 +++ b/tools/Master.h Mon Jul 07 07:55:41 2008 +0000 @@ -42,17 +42,24 @@ void setIndex(unsigned int); + enum Verbosity { + Quiet, + Normal, + Verbose + }; + void setVerbosity(Verbosity); + void writeAlias(int, bool, const vector &); - void showConfigs(bool); + void showConfigs(); void outputData(int); void setDebug(const vector &); 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 &); void sdoUpload(int, const string &, const vector &); - void showSlaves(int, bool); + void showSlaves(int); void siiRead(int); void siiWrite(int, bool, const vector &); void requestStates(int, const vector &); @@ -64,12 +71,12 @@ 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 @@ enum {DefaultBufferSize = 1024}; unsigned int index; + Verbosity verbosity; int fd; }; diff -r ff5b1722581c -r eb8d16507d88 tools/main.cpp --- a/tools/main.cpp Mon Jul 07 07:38:10 2008 +0000 +++ b/tools/main.cpp Mon Jul 07 07:55:41 2008 +0000 @@ -22,8 +22,7 @@ static int domainIndex = -1; static string command; vector commandArgs; -static bool quiet = false; -static bool verbose = false; +static Master::Verbosity verbosity = Master::Normal; string dataTypeStr; bool force = false; @@ -141,13 +140,11 @@ 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 @@ getOptions(argc, argv); + master.setIndex(masterIndex); + master.setVerbosity(verbosity); + try { - master.setIndex(masterIndex); - 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 @@ } 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") {