# HG changeset patch # User Florian Pose # Date 1287994346 -7200 # Node ID 4f682084c643024ec2ed6e67443643b1764d303c # Parent c41b4f4af64588a6bbec71f3bebb3989cb5c6fbb Implemented drive_no for command-line tool; binary base name is now a parameter of the helpString method. diff -r c41b4f4af645 -r 4f682084c643 TODO --- a/TODO Mon Oct 25 09:57:37 2010 +0200 +++ b/TODO Mon Oct 25 10:12:26 2010 +0200 @@ -17,7 +17,6 @@ - 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 -r c41b4f4af645 -r 4f682084c643 tool/Command.h --- a/tool/Command.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/Command.h Mon Oct 25 10:12:26 2010 +0200 @@ -112,7 +112,7 @@ bool matchesSubstr(const string &) const; bool matchesAbbrev(const string &) const; - virtual string helpString() const = 0; + virtual string helpString(const string &) const = 0; typedef vector StringVector; virtual void execute(const StringVector &) = 0; diff -r c41b4f4af645 -r 4f682084c643 tool/CommandAlias.cpp --- a/tool/CommandAlias.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandAlias.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -45,11 +45,11 @@ /*****************************************************************************/ -string CommandAlias::helpString() const +string CommandAlias::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] " << endl + str << binaryBaseName << " " << getName() << " [OPTIONS] " << endl << endl << getBriefDescription() << endl << endl diff -r c41b4f4af645 -r 4f682084c643 tool/CommandAlias.h --- a/tool/CommandAlias.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandAlias.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandAlias(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandCStruct.cpp --- a/tool/CommandCStruct.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandCStruct.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -46,11 +46,11 @@ /*****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandCStruct.h --- a/tool/CommandCStruct.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandCStruct.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandCStruct(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandConfig.cpp --- a/tool/CommandConfig.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandConfig.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -47,11 +47,11 @@ /*****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandConfig.h --- a/tool/CommandConfig.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandConfig.h Mon Oct 25 10:12:26 2010 +0200 @@ -45,7 +45,7 @@ public: CommandConfig(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandData.cpp --- a/tool/CommandData.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandData.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -44,11 +44,11 @@ /*****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandData.h --- a/tool/CommandData.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandData.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandData(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandDebug.cpp --- a/tool/CommandDebug.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandDebug.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -45,11 +45,11 @@ /*****************************************************************************/ -string CommandDebug::helpString() const +string CommandDebug::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " " << endl + str << binaryBaseName << " " << getName() << " " << endl << endl << getBriefDescription() << endl << endl diff -r c41b4f4af645 -r 4f682084c643 tool/CommandDebug.h --- a/tool/CommandDebug.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandDebug.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandDebug(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff -r c41b4f4af645 -r 4f682084c643 tool/CommandDomains.cpp --- a/tool/CommandDomains.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandDomains.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -43,11 +43,11 @@ /*****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandDomains.h --- a/tool/CommandDomains.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandDomains.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandDomains(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandDownload.cpp --- a/tool/CommandDownload.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandDownload.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -43,11 +43,12 @@ /*****************************************************************************/ -string CommandDownload::helpString() const +string CommandDownload::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] " << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] " << endl << endl << getBriefDescription() << endl << endl diff -r c41b4f4af645 -r 4f682084c643 tool/CommandDownload.h --- a/tool/CommandDownload.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandDownload.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandDownload(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandEoe.cpp --- a/tool/CommandEoe.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandEoe.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -45,11 +45,11 @@ /*****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandEoe.h --- a/tool/CommandEoe.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandEoe.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandEoe(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff -r c41b4f4af645 -r 4f682084c643 tool/CommandFoeRead.cpp --- a/tool/CommandFoeRead.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandFoeRead.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -46,11 +46,12 @@ /*****************************************************************************/ -string CommandFoeRead::helpString() const +string CommandFoeRead::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] " << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] " << endl << endl << getBriefDescription() << endl << endl diff -r c41b4f4af645 -r 4f682084c643 tool/CommandFoeRead.h --- a/tool/CommandFoeRead.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandFoeRead.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandFoeRead(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff -r c41b4f4af645 -r 4f682084c643 tool/CommandFoeWrite.cpp --- a/tool/CommandFoeWrite.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandFoeWrite.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -48,11 +48,12 @@ /*****************************************************************************/ -string CommandFoeWrite::helpString() const +string CommandFoeWrite::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] " << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] " << endl << endl << getBriefDescription() << endl << endl diff -r c41b4f4af645 -r 4f682084c643 tool/CommandFoeWrite.h --- a/tool/CommandFoeWrite.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandFoeWrite.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandFoeWrite(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandGraph.cpp --- a/tool/CommandGraph.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandGraph.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -43,11 +43,11 @@ /*****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandGraph.h --- a/tool/CommandGraph.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandGraph.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandGraph(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff -r c41b4f4af645 -r 4f682084c643 tool/CommandMaster.cpp --- a/tool/CommandMaster.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandMaster.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -45,11 +45,11 @@ /****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandMaster.h --- a/tool/CommandMaster.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandMaster.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandMaster(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); private: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandPdos.cpp --- a/tool/CommandPdos.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandPdos.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -43,11 +43,11 @@ /*****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandPdos.h --- a/tool/CommandPdos.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandPdos.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandPdos(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandRegRead.cpp --- a/tool/CommandRegRead.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandRegRead.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -43,11 +43,12 @@ /*****************************************************************************/ -string CommandRegRead::helpString() const +string CommandRegRead::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] [LENGTH]" << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] [LENGTH]" << endl << endl << getBriefDescription() << endl << endl diff -r c41b4f4af645 -r 4f682084c643 tool/CommandRegRead.h --- a/tool/CommandRegRead.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandRegRead.h Mon Oct 25 10:12:26 2010 +0200 @@ -42,7 +42,7 @@ public: CommandRegRead(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff -r c41b4f4af645 -r 4f682084c643 tool/CommandRegWrite.cpp --- a/tool/CommandRegWrite.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandRegWrite.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -45,11 +45,12 @@ /*****************************************************************************/ -string CommandRegWrite::helpString() const +string CommandRegWrite::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] " << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] " << endl << endl << getBriefDescription() << endl << endl diff -r c41b4f4af645 -r 4f682084c643 tool/CommandRegWrite.h --- a/tool/CommandRegWrite.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandRegWrite.h Mon Oct 25 10:12:26 2010 +0200 @@ -42,7 +42,7 @@ public: CommandRegWrite(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); private: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandRescan.cpp --- a/tool/CommandRescan.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandRescan.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -45,11 +45,11 @@ /*****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandRescan.h --- a/tool/CommandRescan.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandRescan.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandRescan(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff -r c41b4f4af645 -r 4f682084c643 tool/CommandSdos.cpp --- a/tool/CommandSdos.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandSdos.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -43,11 +43,11 @@ /*****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandSdos.h --- a/tool/CommandSdos.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandSdos.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandSdos(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandSiiRead.cpp --- a/tool/CommandSiiRead.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandSiiRead.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -43,11 +43,11 @@ /*****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandSiiRead.h --- a/tool/CommandSiiRead.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandSiiRead.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandSiiRead(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandSiiWrite.cpp --- a/tool/CommandSiiWrite.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandSiiWrite.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -45,11 +45,12 @@ /*****************************************************************************/ -string CommandSiiWrite::helpString() const +string CommandSiiWrite::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] " << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] " << endl << endl << getBriefDescription() << endl << endl diff -r c41b4f4af645 -r 4f682084c643 tool/CommandSiiWrite.h --- a/tool/CommandSiiWrite.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandSiiWrite.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandSiiWrite(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandSlaves.cpp --- a/tool/CommandSlaves.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandSlaves.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -45,11 +45,11 @@ /*****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandSlaves.h --- a/tool/CommandSlaves.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandSlaves.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandSlaves(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandSoeRead.cpp --- a/tool/CommandSoeRead.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandSoeRead.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -28,6 +28,7 @@ ****************************************************************************/ #include +#include using namespace std; #include "CommandSoeRead.h" @@ -42,17 +43,22 @@ /*****************************************************************************/ -string CommandSoeRead::helpString() const +string CommandSoeRead::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] " << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] " << endl + << binaryBaseName << " " << getName() + << " [OPTIONS] " << 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 @@ 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 -r c41b4f4af645 -r 4f682084c643 tool/CommandSoeRead.h --- a/tool/CommandSoeRead.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandSoeRead.h Mon Oct 25 10:12:26 2010 +0200 @@ -42,7 +42,7 @@ public: CommandSoeRead(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff -r c41b4f4af645 -r 4f682084c643 tool/CommandSoeWrite.cpp --- a/tool/CommandSoeWrite.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandSoeWrite.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -28,6 +28,7 @@ ****************************************************************************/ #include +#include using namespace std; #include "CommandSoeWrite.h" @@ -42,17 +43,22 @@ /*****************************************************************************/ -string CommandSoeWrite::helpString() const +string CommandSoeWrite::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] " << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] " << endl + << binaryBaseName << " " << getName() + << " [OPTIONS] " << 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 @@ 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; + int driveArgIndex = -1, idnArgIndex = -1, valueArgIndex = -1; - if (args.size() != 2) { - err << "'" << getName() << "' takes 2 arguments!"; + 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 @@ 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 @@ 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 -r c41b4f4af645 -r 4f682084c643 tool/CommandSoeWrite.h --- a/tool/CommandSoeWrite.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandSoeWrite.h Mon Oct 25 10:12:26 2010 +0200 @@ -42,7 +42,7 @@ public: CommandSoeWrite(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff -r c41b4f4af645 -r 4f682084c643 tool/CommandStates.cpp --- a/tool/CommandStates.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandStates.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -43,11 +43,11 @@ /*****************************************************************************/ -string CommandStates::helpString() const +string CommandStates::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] " << endl + str << binaryBaseName << " " << getName() << " [OPTIONS] " << endl << endl << getBriefDescription() << endl << endl diff -r c41b4f4af645 -r 4f682084c643 tool/CommandStates.h --- a/tool/CommandStates.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandStates.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandStates(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff -r c41b4f4af645 -r 4f682084c643 tool/CommandUpload.cpp --- a/tool/CommandUpload.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandUpload.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -43,11 +43,12 @@ /*****************************************************************************/ -string CommandUpload::helpString() const +string CommandUpload::helpString(const string &binaryBaseName) const { stringstream str; - str << getName() << " [OPTIONS] " << endl + str << binaryBaseName << " " << getName() + << " [OPTIONS] " << endl << endl << getBriefDescription() << endl << endl diff -r c41b4f4af645 -r 4f682084c643 tool/CommandUpload.h --- a/tool/CommandUpload.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandUpload.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandUpload(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/CommandVersion.cpp --- a/tool/CommandVersion.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandVersion.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -41,11 +41,11 @@ /****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandVersion.h --- a/tool/CommandVersion.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandVersion.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandVersion(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); }; diff -r c41b4f4af645 -r 4f682084c643 tool/CommandXml.cpp --- a/tool/CommandXml.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandXml.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -44,11 +44,11 @@ /*****************************************************************************/ -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 -r c41b4f4af645 -r 4f682084c643 tool/CommandXml.h --- a/tool/CommandXml.h Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/CommandXml.h Mon Oct 25 10:12:26 2010 +0200 @@ -40,7 +40,7 @@ public: CommandXml(); - string helpString() const; + string helpString(const string &) const; void execute(const StringVector &); protected: diff -r c41b4f4af645 -r 4f682084c643 tool/main.cpp --- a/tool/main.cpp Mon Oct 25 09:57:37 2010 +0200 +++ b/tool/main.cpp Mon Oct 25 10:12:26 2010 +0200 @@ -340,7 +340,7 @@ 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 @@ retval = 1; } } else { - cout << binaryBaseName << " " << cmd->helpString(); + cout << cmd->helpString(binaryBaseName); } } else { cerr << "Ambiguous command abbreviation! Matching:" << endl;