Implemented drive_no for command-line tool; binary base name is now a
parameter of the helpString method.
This commit is contained in:
parent
a7cdeeec13
commit
18f63a581d
1
TODO
1
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:
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandAlias:
|
|||
public:
|
||||
CommandAlias();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandCStruct:
|
|||
public:
|
||||
CommandCStruct();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class CommandConfig:
|
|||
public:
|
||||
CommandConfig();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandData:
|
|||
public:
|
||||
CommandData();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandDebug:
|
|||
public:
|
||||
CommandDebug();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandDomains:
|
|||
public:
|
||||
CommandDomains();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandDownload:
|
|||
public:
|
||||
CommandDownload();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandEoe:
|
|||
public:
|
||||
CommandEoe();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandFoeRead:
|
|||
public:
|
||||
CommandFoeRead();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandFoeWrite:
|
|||
public:
|
||||
CommandFoeWrite();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandGraph:
|
|||
public:
|
||||
CommandGraph();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandMaster:
|
|||
public:
|
||||
CommandMaster();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandPdos:
|
|||
public:
|
||||
CommandPdos();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class CommandRegRead:
|
|||
public:
|
||||
CommandRegRead();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class CommandRegWrite:
|
|||
public:
|
||||
CommandRegWrite();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandRescan:
|
|||
public:
|
||||
CommandRescan();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandSdos:
|
|||
public:
|
||||
CommandSdos();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandSiiRead:
|
|||
public:
|
||||
CommandSiiRead();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandSiiWrite:
|
|||
public:
|
||||
CommandSiiWrite();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandSlaves:
|
|||
public:
|
||||
CommandSlaves();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class CommandSoeRead:
|
|||
public:
|
||||
CommandSoeRead();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
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 @@ 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class CommandSoeWrite:
|
|||
public:
|
||||
CommandSoeWrite();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandStates:
|
|||
public:
|
||||
CommandStates();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandUpload:
|
|||
public:
|
||||
CommandUpload();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandVersion:
|
|||
public:
|
||||
CommandVersion();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class CommandXml:
|
|||
public:
|
||||
CommandXml();
|
||||
|
||||
string helpString() const;
|
||||
string helpString(const string &) const;
|
||||
void execute(const StringVector &);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue