From 5d372b29decb4d25901f6ba3439eb96c2ea5b4cc Mon Sep 17 00:00:00 2001 From: Florian Pose <fp@igh-essen.com> Date: Mon, 25 Oct 2010 10:12:26 +0200 Subject: [PATCH] Implemented drive_no for command-line tool; binary base name is now a parameter of the helpString method. --- TODO | 1 - tool/Command.h | 2 +- tool/CommandAlias.cpp | 4 ++-- tool/CommandAlias.h | 2 +- tool/CommandCStruct.cpp | 4 ++-- tool/CommandCStruct.h | 2 +- tool/CommandConfig.cpp | 4 ++-- tool/CommandConfig.h | 2 +- tool/CommandData.cpp | 4 ++-- tool/CommandData.h | 2 +- tool/CommandDebug.cpp | 4 ++-- tool/CommandDebug.h | 2 +- tool/CommandDomains.cpp | 4 ++-- tool/CommandDomains.h | 2 +- tool/CommandDownload.cpp | 5 ++-- tool/CommandDownload.h | 2 +- tool/CommandEoe.cpp | 4 ++-- tool/CommandEoe.h | 2 +- tool/CommandFoeRead.cpp | 5 ++-- tool/CommandFoeRead.h | 2 +- tool/CommandFoeWrite.cpp | 5 ++-- tool/CommandFoeWrite.h | 2 +- tool/CommandGraph.cpp | 4 ++-- tool/CommandGraph.h | 2 +- tool/CommandMaster.cpp | 4 ++-- tool/CommandMaster.h | 2 +- tool/CommandPdos.cpp | 4 ++-- tool/CommandPdos.h | 2 +- tool/CommandRegRead.cpp | 5 ++-- tool/CommandRegRead.h | 2 +- tool/CommandRegWrite.cpp | 5 ++-- tool/CommandRegWrite.h | 2 +- tool/CommandRescan.cpp | 4 ++-- tool/CommandRescan.h | 2 +- tool/CommandSdos.cpp | 4 ++-- tool/CommandSdos.h | 2 +- tool/CommandSiiRead.cpp | 4 ++-- tool/CommandSiiRead.h | 2 +- tool/CommandSiiWrite.cpp | 5 ++-- tool/CommandSiiWrite.h | 2 +- tool/CommandSlaves.cpp | 4 ++-- tool/CommandSlaves.h | 2 +- tool/CommandSoeRead.cpp | 40 +++++++++++++++++++++++++------ tool/CommandSoeRead.h | 2 +- tool/CommandSoeWrite.cpp | 52 ++++++++++++++++++++++++++++++---------- tool/CommandSoeWrite.h | 2 +- tool/CommandStates.cpp | 4 ++-- tool/CommandStates.h | 2 +- tool/CommandUpload.cpp | 5 ++-- tool/CommandUpload.h | 2 +- tool/CommandVersion.cpp | 4 ++-- tool/CommandVersion.h | 2 +- tool/CommandXml.cpp | 4 ++-- tool/CommandXml.h | 2 +- tool/main.cpp | 4 ++-- 55 files changed, 157 insertions(+), 97 deletions(-) diff --git a/TODO b/TODO index 5a01e11e..0999bffb 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,6 @@ Version 1.5.0: - Output error after usage. - Implement ranges for slaves and domains. * Fix casting away constness during expected WC calculation. -* Include SoE drive_no in ethercat tool. Future issues: diff --git a/tool/Command.h b/tool/Command.h index 14306c53..02d70f45 100644 --- a/tool/Command.h +++ b/tool/Command.h @@ -112,7 +112,7 @@ class Command bool matchesSubstr(const string &) const; bool matchesAbbrev(const string &) const; - virtual string helpString() const = 0; + virtual string helpString(const string &) const = 0; typedef vector<string> StringVector; virtual void execute(const StringVector &) = 0; diff --git a/tool/CommandAlias.cpp b/tool/CommandAlias.cpp index 6c53379e..22eef7f5 100644 --- a/tool/CommandAlias.cpp +++ b/tool/CommandAlias.cpp @@ -45,11 +45,11 @@ CommandAlias::CommandAlias(): /*****************************************************************************/ -string CommandAlias::helpString() const +string CommandAlias::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] <ALIAS>" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS] <ALIAS>" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandAlias.h b/tool/CommandAlias.h index 755d344e..49404e92 100644 --- a/tool/CommandAlias.h +++ b/tool/CommandAlias.h @@ -40,7 +40,7 @@ class CommandAlias: public: CommandAlias(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandCStruct.cpp b/tool/CommandCStruct.cpp index bde1a765..2a3f75b1 100644 --- a/tool/CommandCStruct.cpp +++ b/tool/CommandCStruct.cpp @@ -46,11 +46,11 @@ CommandCStruct::CommandCStruct(): /*****************************************************************************/ -string CommandCStruct::helpString() const +string CommandCStruct::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS]" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandCStruct.h b/tool/CommandCStruct.h index 82ab3129..f277c8f5 100644 --- a/tool/CommandCStruct.h +++ b/tool/CommandCStruct.h @@ -40,7 +40,7 @@ class CommandCStruct: public: CommandCStruct(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandConfig.cpp b/tool/CommandConfig.cpp index 45e61999..749a3df7 100644 --- a/tool/CommandConfig.cpp +++ b/tool/CommandConfig.cpp @@ -47,11 +47,11 @@ CommandConfig::CommandConfig(): /*****************************************************************************/ -string CommandConfig::helpString() const +string CommandConfig::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS]" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandConfig.h b/tool/CommandConfig.h index 75c7612b..e012b82d 100644 --- a/tool/CommandConfig.h +++ b/tool/CommandConfig.h @@ -45,7 +45,7 @@ class CommandConfig: public: CommandConfig(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandData.cpp b/tool/CommandData.cpp index d31307c3..54039636 100644 --- a/tool/CommandData.cpp +++ b/tool/CommandData.cpp @@ -44,11 +44,11 @@ CommandData::CommandData(): /*****************************************************************************/ -string CommandData::helpString() const +string CommandData::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS]" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandData.h b/tool/CommandData.h index b48631b2..9f52e941 100644 --- a/tool/CommandData.h +++ b/tool/CommandData.h @@ -40,7 +40,7 @@ class CommandData: public: CommandData(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandDebug.cpp b/tool/CommandDebug.cpp index df0548e8..53d2a233 100644 --- a/tool/CommandDebug.cpp +++ b/tool/CommandDebug.cpp @@ -45,11 +45,11 @@ CommandDebug::CommandDebug(): /*****************************************************************************/ -string CommandDebug::helpString() const +string CommandDebug::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " <LEVEL>" << endl + str << binaryBaseName << " " << getName() << " <LEVEL>" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandDebug.h b/tool/CommandDebug.h index a9e28438..df82707f 100644 --- a/tool/CommandDebug.h +++ b/tool/CommandDebug.h @@ -40,7 +40,7 @@ class CommandDebug: public: CommandDebug(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff --git a/tool/CommandDomains.cpp b/tool/CommandDomains.cpp index 04a26f2d..1ebece6c 100644 --- a/tool/CommandDomains.cpp +++ b/tool/CommandDomains.cpp @@ -43,11 +43,11 @@ CommandDomains::CommandDomains(): /*****************************************************************************/ -string CommandDomains::helpString() const +string CommandDomains::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS]" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandDomains.h b/tool/CommandDomains.h index 2b471445..6a5e0ffc 100644 --- a/tool/CommandDomains.h +++ b/tool/CommandDomains.h @@ -40,7 +40,7 @@ class CommandDomains: public: CommandDomains(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandDownload.cpp b/tool/CommandDownload.cpp index 7253d0b5..a393f85c 100644 --- a/tool/CommandDownload.cpp +++ b/tool/CommandDownload.cpp @@ -43,11 +43,12 @@ CommandDownload::CommandDownload(): /*****************************************************************************/ -string CommandDownload::helpString() const +string CommandDownload::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] <INDEX> <SUBINDEX> <VALUE>" << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] <INDEX> <SUBINDEX> <VALUE>" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandDownload.h b/tool/CommandDownload.h index 48217877..68c1a54a 100644 --- a/tool/CommandDownload.h +++ b/tool/CommandDownload.h @@ -40,7 +40,7 @@ class CommandDownload: public: CommandDownload(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandEoe.cpp b/tool/CommandEoe.cpp index 67ad0346..501ac28c 100644 --- a/tool/CommandEoe.cpp +++ b/tool/CommandEoe.cpp @@ -45,11 +45,11 @@ CommandEoe::CommandEoe(): /*****************************************************************************/ -string CommandEoe::helpString() const +string CommandEoe::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << endl + str << binaryBaseName << " " << getName() << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandEoe.h b/tool/CommandEoe.h index 479ddacd..d080574d 100644 --- a/tool/CommandEoe.h +++ b/tool/CommandEoe.h @@ -40,7 +40,7 @@ class CommandEoe: public: CommandEoe(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff --git a/tool/CommandFoeRead.cpp b/tool/CommandFoeRead.cpp index 3ab6d913..7221f40b 100644 --- a/tool/CommandFoeRead.cpp +++ b/tool/CommandFoeRead.cpp @@ -46,11 +46,12 @@ CommandFoeRead::CommandFoeRead(): /*****************************************************************************/ -string CommandFoeRead::helpString() const +string CommandFoeRead::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] <SOURCEFILE>" << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] <SOURCEFILE>" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandFoeRead.h b/tool/CommandFoeRead.h index 1410a8ad..0db2ad49 100644 --- a/tool/CommandFoeRead.h +++ b/tool/CommandFoeRead.h @@ -40,7 +40,7 @@ class CommandFoeRead: public: CommandFoeRead(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff --git a/tool/CommandFoeWrite.cpp b/tool/CommandFoeWrite.cpp index 58094e1d..abd6a3fb 100644 --- a/tool/CommandFoeWrite.cpp +++ b/tool/CommandFoeWrite.cpp @@ -48,11 +48,12 @@ CommandFoeWrite::CommandFoeWrite(): /*****************************************************************************/ -string CommandFoeWrite::helpString() const +string CommandFoeWrite::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] <FILENAME>" << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] <FILENAME>" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandFoeWrite.h b/tool/CommandFoeWrite.h index 138eb0a7..3f129e78 100644 --- a/tool/CommandFoeWrite.h +++ b/tool/CommandFoeWrite.h @@ -40,7 +40,7 @@ class CommandFoeWrite: public: CommandFoeWrite(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandGraph.cpp b/tool/CommandGraph.cpp index 951c5d27..a03c7b98 100644 --- a/tool/CommandGraph.cpp +++ b/tool/CommandGraph.cpp @@ -43,11 +43,11 @@ CommandGraph::CommandGraph(): /*****************************************************************************/ -string CommandGraph::helpString() const +string CommandGraph::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS]" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandGraph.h b/tool/CommandGraph.h index a6e8e5ff..bc931d2a 100644 --- a/tool/CommandGraph.h +++ b/tool/CommandGraph.h @@ -40,7 +40,7 @@ class CommandGraph: public: CommandGraph(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff --git a/tool/CommandMaster.cpp b/tool/CommandMaster.cpp index 221cb9bf..7471abe5 100644 --- a/tool/CommandMaster.cpp +++ b/tool/CommandMaster.cpp @@ -45,11 +45,11 @@ CommandMaster::CommandMaster(): /****************************************************************************/ -string CommandMaster::helpString() const +string CommandMaster::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS]" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandMaster.h b/tool/CommandMaster.h index de7976d4..53577d4a 100644 --- a/tool/CommandMaster.h +++ b/tool/CommandMaster.h @@ -40,7 +40,7 @@ class CommandMaster: public: CommandMaster(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); private: diff --git a/tool/CommandPdos.cpp b/tool/CommandPdos.cpp index ccf7d97e..6cf01b17 100644 --- a/tool/CommandPdos.cpp +++ b/tool/CommandPdos.cpp @@ -43,11 +43,11 @@ CommandPdos::CommandPdos(): /*****************************************************************************/ -string CommandPdos::helpString() const +string CommandPdos::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS]" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandPdos.h b/tool/CommandPdos.h index 91539509..a1c0a54b 100644 --- a/tool/CommandPdos.h +++ b/tool/CommandPdos.h @@ -40,7 +40,7 @@ class CommandPdos: public: CommandPdos(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandRegRead.cpp b/tool/CommandRegRead.cpp index 8af9635f..3055ad20 100644 --- a/tool/CommandRegRead.cpp +++ b/tool/CommandRegRead.cpp @@ -43,11 +43,12 @@ CommandRegRead::CommandRegRead(): /*****************************************************************************/ -string CommandRegRead::helpString() const +string CommandRegRead::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] <OFFSET> [LENGTH]" << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] <OFFSET> [LENGTH]" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandRegRead.h b/tool/CommandRegRead.h index 2e8a4a19..8cb39327 100644 --- a/tool/CommandRegRead.h +++ b/tool/CommandRegRead.h @@ -42,7 +42,7 @@ class CommandRegRead: public: CommandRegRead(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff --git a/tool/CommandRegWrite.cpp b/tool/CommandRegWrite.cpp index 964dc1bb..7e1e1bb9 100644 --- a/tool/CommandRegWrite.cpp +++ b/tool/CommandRegWrite.cpp @@ -45,11 +45,12 @@ CommandRegWrite::CommandRegWrite(): /*****************************************************************************/ -string CommandRegWrite::helpString() const +string CommandRegWrite::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] <OFFSET> <DATA>" << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] <OFFSET> <DATA>" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandRegWrite.h b/tool/CommandRegWrite.h index 71a0487e..c8e047be 100644 --- a/tool/CommandRegWrite.h +++ b/tool/CommandRegWrite.h @@ -42,7 +42,7 @@ class CommandRegWrite: public: CommandRegWrite(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); private: diff --git a/tool/CommandRescan.cpp b/tool/CommandRescan.cpp index c3d1cd3b..8fe38802 100644 --- a/tool/CommandRescan.cpp +++ b/tool/CommandRescan.cpp @@ -45,11 +45,11 @@ CommandRescan::CommandRescan(): /*****************************************************************************/ -string CommandRescan::helpString() const +string CommandRescan::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << endl + str << binaryBaseName << " " << getName() << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandRescan.h b/tool/CommandRescan.h index 80c386cf..ee2ea7fa 100644 --- a/tool/CommandRescan.h +++ b/tool/CommandRescan.h @@ -40,7 +40,7 @@ class CommandRescan: public: CommandRescan(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff --git a/tool/CommandSdos.cpp b/tool/CommandSdos.cpp index d194e218..348b7cc6 100644 --- a/tool/CommandSdos.cpp +++ b/tool/CommandSdos.cpp @@ -43,11 +43,11 @@ CommandSdos::CommandSdos(): /*****************************************************************************/ -string CommandSdos::helpString() const +string CommandSdos::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS]" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandSdos.h b/tool/CommandSdos.h index 7aa301f2..cc835945 100644 --- a/tool/CommandSdos.h +++ b/tool/CommandSdos.h @@ -40,7 +40,7 @@ class CommandSdos: public: CommandSdos(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandSiiRead.cpp b/tool/CommandSiiRead.cpp index 24e23ae8..979dd525 100644 --- a/tool/CommandSiiRead.cpp +++ b/tool/CommandSiiRead.cpp @@ -43,11 +43,11 @@ CommandSiiRead::CommandSiiRead(): /*****************************************************************************/ -string CommandSiiRead::helpString() const +string CommandSiiRead::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS]" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandSiiRead.h b/tool/CommandSiiRead.h index 8f797a63..2b4152b2 100644 --- a/tool/CommandSiiRead.h +++ b/tool/CommandSiiRead.h @@ -40,7 +40,7 @@ class CommandSiiRead: public: CommandSiiRead(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandSiiWrite.cpp b/tool/CommandSiiWrite.cpp index de6d0507..22e4663d 100644 --- a/tool/CommandSiiWrite.cpp +++ b/tool/CommandSiiWrite.cpp @@ -45,11 +45,12 @@ CommandSiiWrite::CommandSiiWrite(): /*****************************************************************************/ -string CommandSiiWrite::helpString() const +string CommandSiiWrite::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] <FILENAME>" << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] <FILENAME>" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandSiiWrite.h b/tool/CommandSiiWrite.h index a22b8db6..f40cada5 100644 --- a/tool/CommandSiiWrite.h +++ b/tool/CommandSiiWrite.h @@ -40,7 +40,7 @@ class CommandSiiWrite: public: CommandSiiWrite(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandSlaves.cpp b/tool/CommandSlaves.cpp index fe8cb516..2485bb31 100644 --- a/tool/CommandSlaves.cpp +++ b/tool/CommandSlaves.cpp @@ -45,11 +45,11 @@ CommandSlaves::CommandSlaves(): /*****************************************************************************/ -string CommandSlaves::helpString() const +string CommandSlaves::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS]" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandSlaves.h b/tool/CommandSlaves.h index 1ac5b673..c04ce74a 100644 --- a/tool/CommandSlaves.h +++ b/tool/CommandSlaves.h @@ -40,7 +40,7 @@ class CommandSlaves: public: CommandSlaves(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandSoeRead.cpp b/tool/CommandSoeRead.cpp index 18f1bec9..2ad4c0f8 100644 --- a/tool/CommandSoeRead.cpp +++ b/tool/CommandSoeRead.cpp @@ -28,6 +28,7 @@ ****************************************************************************/ #include <iostream> +#include <iomanip> using namespace std; #include "CommandSoeRead.h" @@ -42,17 +43,22 @@ CommandSoeRead::CommandSoeRead(): /*****************************************************************************/ -string CommandSoeRead::helpString() const +string CommandSoeRead::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] <IDN>" << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] <IDN>" << endl + << binaryBaseName << " " << getName() + << " [OPTIONS] <DRIVE> <IDN>" << endl << endl << getBriefDescription() << endl << endl << "This command requires a single slave to be selected." << endl << endl << "Arguments:" << endl + << " DRIVE is the drive number (0 - 7). If omitted, 0 is assumed." + << endl << " IDN is the IDN and must be either an unsigned" << endl << " 16 bit number acc. to IEC 61800-7-204:" << endl << " Bit 15: (0) Standard data, (1) Product data" << endl @@ -84,18 +90,38 @@ void CommandSoeRead::execute(const StringVector &args) stringstream err; const DataType *dataType = NULL; ec_ioctl_slave_soe_read_t ioctl; + int driveArgIndex = -1, idnArgIndex = -1; - if (args.size() != 1) { - err << "'" << getName() << "' takes one argument!"; + if (args.size() == 1) { + idnArgIndex = 0; + } else if (args.size() == 2) { + driveArgIndex = 0; + idnArgIndex = 1; + } else { + err << "'" << getName() << "' takes eiter 1 or 2 arguments!"; throwInvalidUsageException(err); } - ioctl.drive_no = 0; // FIXME + if (driveArgIndex >= 0) { + stringstream str; + unsigned int number; + str << args[driveArgIndex]; + str + >> resetiosflags(ios::basefield) // guess base from prefix + >> number; + if (str.fail() || number > 7) { + err << "Invalid drive number '" << args[driveArgIndex] << "'!"; + throwInvalidUsageException(err); + } + ioctl.drive_no = number; + } else { + ioctl.drive_no = 0; + } try { - ioctl.idn = parseIdn(args[0]); + ioctl.idn = parseIdn(args[idnArgIndex]); } catch (runtime_error &e) { - err << "Invalid IDN '" << args[0] << "': " << e.what(); + err << "Invalid IDN '" << args[idnArgIndex] << "': " << e.what(); throwInvalidUsageException(err); } diff --git a/tool/CommandSoeRead.h b/tool/CommandSoeRead.h index a6e73d7a..06e0c8e0 100644 --- a/tool/CommandSoeRead.h +++ b/tool/CommandSoeRead.h @@ -42,7 +42,7 @@ class CommandSoeRead: public: CommandSoeRead(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff --git a/tool/CommandSoeWrite.cpp b/tool/CommandSoeWrite.cpp index 16f76ccd..382ba8d6 100644 --- a/tool/CommandSoeWrite.cpp +++ b/tool/CommandSoeWrite.cpp @@ -28,6 +28,7 @@ ****************************************************************************/ #include <iostream> +#include <iomanip> using namespace std; #include "CommandSoeWrite.h" @@ -42,17 +43,22 @@ CommandSoeWrite::CommandSoeWrite(): /*****************************************************************************/ -string CommandSoeWrite::helpString() const +string CommandSoeWrite::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] <IDN> <VALUE>" << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] <IDN> <VALUE>" << endl + << binaryBaseName << " " << getName() + << " [OPTIONS] <DRIVE> <IDN> <VALUE>" << endl << endl << getBriefDescription() << endl << endl << "This command requires a single slave to be selected." << endl << endl << "Arguments:" << endl + << " DRIVE is the drive number (0 - 7). If omitted, 0 is assumed." + << endl << " IDN is the IDN and must be either an unsigned" << endl << " 16 bit number acc. to IEC 61800-7-204:" << endl << " Bit 15: (0) Standard data, (1) Product data" << endl @@ -81,23 +87,45 @@ string CommandSoeWrite::helpString() const void CommandSoeWrite::execute(const StringVector &args) { - stringstream strIdn, err; + stringstream err; const DataType *dataType = NULL; ec_ioctl_slave_soe_write_t ioctl; SlaveList slaves; size_t memSize; - - if (args.size() != 2) { - err << "'" << getName() << "' takes 2 arguments!"; + int driveArgIndex = -1, idnArgIndex = -1, valueArgIndex = -1; + + if (args.size() == 2) { + idnArgIndex = 0; + valueArgIndex = 1; + } else if (args.size() == 3) { + driveArgIndex = 0; + idnArgIndex = 1; + valueArgIndex = 2; + } else { + err << "'" << getName() << "' takes eiter 2 or 3 arguments!"; throwInvalidUsageException(err); } - ioctl.drive_no = 0; // FIXME + if (driveArgIndex >= 0) { + stringstream str; + unsigned int number; + str << args[driveArgIndex]; + str + >> resetiosflags(ios::basefield) // guess base from prefix + >> number; + if (str.fail() || number > 7) { + err << "Invalid drive number '" << args[driveArgIndex] << "'!"; + throwInvalidUsageException(err); + } + ioctl.drive_no = number; + } else { + ioctl.drive_no = 0; + } try { - ioctl.idn = parseIdn(args[0]); + ioctl.idn = parseIdn(args[idnArgIndex]); } catch (runtime_error &e) { - err << "Invalid IDN '" << args[0] << "': " << e.what(); + err << "Invalid IDN '" << args[idnArgIndex] << "': " << e.what(); throwInvalidUsageException(err); } @@ -123,7 +151,7 @@ void CommandSoeWrite::execute(const StringVector &args) memSize = dataType->byteSize; } else { // guess string type size - memSize = args[1].size() + 1; + memSize = args[valueArgIndex].size() + 1; if (!memSize) { err << "Empty argument not allowed."; throwInvalidUsageException(err); @@ -134,13 +162,13 @@ void CommandSoeWrite::execute(const StringVector &args) try { ioctl.data_size = interpretAsType( - dataType, args[1], ioctl.data, memSize); + dataType, args[valueArgIndex], ioctl.data, memSize); } catch (SizeException &e) { delete [] ioctl.data; throwCommandException(e.what()); } catch (ios::failure &e) { delete [] ioctl.data; - err << "Invalid value argument '" << args[1] + err << "Invalid value argument '" << args[valueArgIndex] << "' for type '" << dataType->name << "'!"; throwInvalidUsageException(err); } diff --git a/tool/CommandSoeWrite.h b/tool/CommandSoeWrite.h index f6462c06..f86134c4 100644 --- a/tool/CommandSoeWrite.h +++ b/tool/CommandSoeWrite.h @@ -42,7 +42,7 @@ class CommandSoeWrite: public: CommandSoeWrite(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff --git a/tool/CommandStates.cpp b/tool/CommandStates.cpp index 663979c8..32e710a4 100644 --- a/tool/CommandStates.cpp +++ b/tool/CommandStates.cpp @@ -43,11 +43,11 @@ CommandStates::CommandStates(): /*****************************************************************************/ -string CommandStates::helpString() const +string CommandStates::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] <STATE>" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS] <STATE>" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandStates.h b/tool/CommandStates.h index 305b8347..77f8e6b5 100644 --- a/tool/CommandStates.h +++ b/tool/CommandStates.h @@ -40,7 +40,7 @@ class CommandStates: public: CommandStates(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff --git a/tool/CommandUpload.cpp b/tool/CommandUpload.cpp index 4146ab69..439eeab3 100644 --- a/tool/CommandUpload.cpp +++ b/tool/CommandUpload.cpp @@ -43,11 +43,12 @@ CommandUpload::CommandUpload(): /*****************************************************************************/ -string CommandUpload::helpString() const +string CommandUpload::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] <INDEX> <SUBINDEX>" << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] <INDEX> <SUBINDEX>" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandUpload.h b/tool/CommandUpload.h index 5d99ba4d..f9cdc466 100644 --- a/tool/CommandUpload.h +++ b/tool/CommandUpload.h @@ -40,7 +40,7 @@ class CommandUpload: public: CommandUpload(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/CommandVersion.cpp b/tool/CommandVersion.cpp index c81b8be7..ccf9913d 100644 --- a/tool/CommandVersion.cpp +++ b/tool/CommandVersion.cpp @@ -41,11 +41,11 @@ CommandVersion::CommandVersion(): /****************************************************************************/ -string CommandVersion::helpString() const +string CommandVersion::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS]" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl << endl << getBriefDescription() << endl; diff --git a/tool/CommandVersion.h b/tool/CommandVersion.h index 842db320..0592e2f9 100644 --- a/tool/CommandVersion.h +++ b/tool/CommandVersion.h @@ -40,7 +40,7 @@ class CommandVersion: public: CommandVersion(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff --git a/tool/CommandXml.cpp b/tool/CommandXml.cpp index 28576a85..de5086f4 100644 --- a/tool/CommandXml.cpp +++ b/tool/CommandXml.cpp @@ -44,11 +44,11 @@ CommandXml::CommandXml(): /*****************************************************************************/ -string CommandXml::helpString() const +string CommandXml::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS]" << endl + str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl << endl << getBriefDescription() << endl << endl diff --git a/tool/CommandXml.h b/tool/CommandXml.h index 5e8a2b55..2f7ec6a8 100644 --- a/tool/CommandXml.h +++ b/tool/CommandXml.h @@ -40,7 +40,7 @@ class CommandXml: public: CommandXml(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff --git a/tool/main.cpp b/tool/main.cpp index 0afa35c9..c4fa59d0 100644 --- a/tool/main.cpp +++ b/tool/main.cpp @@ -340,7 +340,7 @@ int main(int argc, char **argv) cmd->execute(commandArgs); } catch (InvalidUsageException &e) { cerr << e.what() << endl << endl; - cerr << binaryBaseName << " " << cmd->helpString(); + cerr << cmd->helpString(binaryBaseName); retval = 1; } catch (CommandException &e) { cerr << e.what() << endl; @@ -350,7 +350,7 @@ int main(int argc, char **argv) retval = 1; } } else { - cout << binaryBaseName << " " << cmd->helpString(); + cout << cmd->helpString(binaryBaseName); } } else { cerr << "Ambiguous command abbreviation! Matching:" << endl; -- GitLab