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); }