Implemented drive_no for command-line tool; binary base name is now a
authorFlorian Pose <fp@igh-essen.com>
Mon, 25 Oct 2010 10:12:26 +0200
changeset 1968 4f682084c643
parent 1967 c41b4f4af645
child 1969 9b0260a60c28
Implemented drive_no for command-line tool; binary base name is now a
parameter of the helpString method.
TODO
tool/Command.h
tool/CommandAlias.cpp
tool/CommandAlias.h
tool/CommandCStruct.cpp
tool/CommandCStruct.h
tool/CommandConfig.cpp
tool/CommandConfig.h
tool/CommandData.cpp
tool/CommandData.h
tool/CommandDebug.cpp
tool/CommandDebug.h
tool/CommandDomains.cpp
tool/CommandDomains.h
tool/CommandDownload.cpp
tool/CommandDownload.h
tool/CommandEoe.cpp
tool/CommandEoe.h
tool/CommandFoeRead.cpp
tool/CommandFoeRead.h
tool/CommandFoeWrite.cpp
tool/CommandFoeWrite.h
tool/CommandGraph.cpp
tool/CommandGraph.h
tool/CommandMaster.cpp
tool/CommandMaster.h
tool/CommandPdos.cpp
tool/CommandPdos.h
tool/CommandRegRead.cpp
tool/CommandRegRead.h
tool/CommandRegWrite.cpp
tool/CommandRegWrite.h
tool/CommandRescan.cpp
tool/CommandRescan.h
tool/CommandSdos.cpp
tool/CommandSdos.h
tool/CommandSiiRead.cpp
tool/CommandSiiRead.h
tool/CommandSiiWrite.cpp
tool/CommandSiiWrite.h
tool/CommandSlaves.cpp
tool/CommandSlaves.h
tool/CommandSoeRead.cpp
tool/CommandSoeRead.h
tool/CommandSoeWrite.cpp
tool/CommandSoeWrite.h
tool/CommandStates.cpp
tool/CommandStates.h
tool/CommandUpload.cpp
tool/CommandUpload.h
tool/CommandVersion.cpp
tool/CommandVersion.h
tool/CommandXml.cpp
tool/CommandXml.h
tool/main.cpp
--- 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:
 
--- 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<string> StringVector;
         virtual void execute(const StringVector &) = 0;
--- 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] <ALIAS>" << endl
+    str << binaryBaseName << " " << getName() << " [OPTIONS] <ALIAS>" << endl
         << endl
         << getBriefDescription() << endl
         << endl
--- 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:
--- 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
--- 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:
--- 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
--- 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:
--- 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
--- 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:
--- 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() << " <LEVEL>" << endl
+    str << binaryBaseName << " " << getName() << " <LEVEL>" << endl
         << endl
         << getBriefDescription() << endl
         << endl
--- 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 &);
 };
 
--- 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
--- 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:
--- 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] <INDEX> <SUBINDEX> <VALUE>" << endl
+    str << binaryBaseName << " " << getName()
+        << " [OPTIONS] <INDEX> <SUBINDEX> <VALUE>" << endl
         << endl
         << getBriefDescription() << endl
         << endl
--- 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:
--- 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
--- 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 &);
 };
 
--- 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] <SOURCEFILE>" << endl
+    str << binaryBaseName << " " << getName()
+        << " [OPTIONS] <SOURCEFILE>" << endl
         << endl
         << getBriefDescription() << endl
         << endl
--- 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 &);
 };
 
--- 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] <FILENAME>" << endl
+    str << binaryBaseName << " " << getName()
+        << " [OPTIONS] <FILENAME>" << endl
         << endl
         << getBriefDescription() << endl
         << endl
--- 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:
--- 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
--- 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 &);
 };
 
--- 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
--- 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:
--- 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
--- 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:
--- 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] <OFFSET> [LENGTH]" << endl
+    str << binaryBaseName << " " << getName()
+        << " [OPTIONS] <OFFSET> [LENGTH]" << endl
         << endl
         << getBriefDescription() << endl
         << endl
--- 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 &);
 };
 
--- 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] <OFFSET> <DATA>" << endl
+    str << binaryBaseName << " " << getName()
+        << " [OPTIONS] <OFFSET> <DATA>" << endl
         << endl 
         << getBriefDescription() << endl
         << endl
--- 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:
--- 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
--- 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 &);
 };
 
--- 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
--- 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:
--- 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
--- 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:
--- 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] <FILENAME>" << endl
+    str << binaryBaseName << " " << getName()
+        << " [OPTIONS] <FILENAME>" << endl
         << endl 
         << getBriefDescription() << endl
         << endl
--- 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:
--- 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
--- 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:
--- 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 <iostream>
+#include <iomanip>
 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] <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 @@
     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);
     }
 
--- 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 &);
 };
 
--- 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 <iostream>
+#include <iomanip>
 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] <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 @@
 
 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);
     }
--- 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 &);
 };
 
--- 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] <STATE>" << endl
+    str << binaryBaseName << " " << getName() << " [OPTIONS] <STATE>" << endl
         << endl
         << getBriefDescription() << endl
         << endl
--- 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 &);
 };
 
--- 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] <INDEX> <SUBINDEX>" << endl
+    str << binaryBaseName << " " << getName()
+        << " [OPTIONS] <INDEX> <SUBINDEX>" << endl
         << endl
         << getBriefDescription() << endl
         << endl
--- 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:
--- 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;
 
--- 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 &);
 };
 
--- 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
--- 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:
--- 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;