From 9bec4838a86b2c8d95923081d897db7cc98a3d8f Mon Sep 17 00:00:00 2001 From: Florian Pose <fp@igh-essen.com> Date: Fri, 6 Jun 2008 09:34:20 +0000 Subject: [PATCH] Added -q flag (quiet). --- tools/Master.cpp | 30 ++++++++++++++++++++++-------- tools/Master.h | 8 ++++---- tools/main.cpp | 13 ++++++++++--- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/tools/Master.cpp b/tools/Master.cpp index 1ec25455..3be29309 100644 --- a/tools/Master.cpp +++ b/tools/Master.cpp @@ -209,31 +209,31 @@ void Master::showMaster() /****************************************************************************/ -void Master::listPdos(int slavePosition) +void Master::listPdos(int slavePosition, bool quiet) { if (slavePosition == -1) { unsigned int numSlaves = slaveCount(), i; for (i = 0; i < numSlaves; i++) { - listSlavePdos(i, true); + listSlavePdos(i, quiet, true); } } else { - listSlavePdos(slavePosition, false); + listSlavePdos(slavePosition, quiet, false); } } /****************************************************************************/ -void Master::listSdos(int slavePosition) +void Master::listSdos(int slavePosition, bool quiet) { if (slavePosition == -1) { unsigned int numSlaves = slaveCount(), i; for (i = 0; i < numSlaves; i++) { - listSlaveSdos(i, true); + listSlaveSdos(i, quiet, true); } } else { - listSlaveSdos(slavePosition, false); + listSlaveSdos(slavePosition, quiet, false); } } @@ -390,7 +390,11 @@ void Master::showDomain(unsigned int domainIndex) /****************************************************************************/ -void Master::listSlavePdos(uint16_t slavePosition, bool withHeader) +void Master::listSlavePdos( + uint16_t slavePosition, + bool quiet, + bool withHeader + ) { ec_ioctl_slave_t slave; ec_ioctl_sync_t sync; @@ -424,6 +428,9 @@ void Master::listSlavePdos(uint16_t slavePosition, bool withHeader) << hex << setfill('0') << setw(4) << pdo.index << " \"" << pdo.name << "\"" << endl; + if (quiet) + continue; + for (k = 0; k < pdo.entry_count; k++) { getPdoEntry(&entry, slavePosition, i, j, k); @@ -440,7 +447,11 @@ void Master::listSlavePdos(uint16_t slavePosition, bool withHeader) /****************************************************************************/ -void Master::listSlaveSdos(uint16_t slavePosition, bool withHeader) +void Master::listSlaveSdos( + uint16_t slavePosition, + bool quiet, + bool withHeader + ) { ec_ioctl_slave_t slave; ec_ioctl_sdo_t sdo; @@ -459,6 +470,9 @@ void Master::listSlaveSdos(uint16_t slavePosition, bool withHeader) << hex << setfill('0') << setw(4) << sdo.sdo_index << ", \"" << sdo.name << "\"" << endl; + if (quiet) + continue; + for (j = 0; j <= sdo.max_subindex; j++) { getSdoEntry(&entry, slavePosition, i, j); diff --git a/tools/Master.h b/tools/Master.h index 84a59cc3..9c90b11f 100644 --- a/tools/Master.h +++ b/tools/Master.h @@ -47,16 +47,16 @@ class Master void showDomains(int); void listSlaves(); void showMaster(); - void listPdos(int); - void listSdos(int); + void listPdos(int, bool = false); + void listSdos(int, bool = false); void requestStates(int, const vector<string> &); void generateXml(int); protected: void outputDomainData(unsigned int); void showDomain(unsigned int); - void listSlavePdos(uint16_t, bool = false); - void listSlaveSdos(uint16_t, bool = false); + void listSlavePdos(uint16_t, bool = false, bool = false); + void listSlaveSdos(uint16_t, bool = false, bool = false); void generateSlaveXml(uint16_t); unsigned int domainCount(); unsigned int slaveCount(); diff --git a/tools/main.cpp b/tools/main.cpp index 504daa01..4e1b60ce 100644 --- a/tools/main.cpp +++ b/tools/main.cpp @@ -25,6 +25,7 @@ static int slavePosition = DEFAULT_SLAVEPOSITION; static int domainIndex = DEFAULT_DOMAININDEX; static string command = DEFAULT_COMMAND; vector<string> commandArgs; +static bool quiet = false; /*****************************************************************************/ @@ -53,6 +54,7 @@ void printUsage() << endl << " or 'all' for all domains (default)." << endl + << " --quiet -q Show less output." << endl << " --help -h Show this help." << endl; } @@ -68,12 +70,13 @@ void getOptions(int argc, char **argv) {"master", required_argument, NULL, 'm'}, {"slave", required_argument, NULL, 's'}, {"domain", required_argument, NULL, 'd'}, + {"quiet", no_argument, NULL, 'q'}, {"help", no_argument, NULL, 'h'}, {} }; do { - c = getopt_long(argc, argv, "m:s:d:h", longOptions, &optionIndex); + c = getopt_long(argc, argv, "m:s:d:qh", longOptions, &optionIndex); switch (c) { case 'm': @@ -117,6 +120,10 @@ void getOptions(int argc, char **argv) } break; + case 'q': + quiet = true; + break; + case 'h': case '?': printUsage(); @@ -163,9 +170,9 @@ int main(int argc, char **argv) } else if (command == "master") { master.showMaster(); } else if (command == "pdos") { - master.listPdos(slavePosition); + master.listPdos(slavePosition, quiet); } else if (command == "sdos") { - master.listSdos(slavePosition); + master.listSdos(slavePosition, quiet); } else if (command == "state") { master.requestStates(slavePosition, commandArgs); } else if (command == "xml") { -- GitLab