Renamed sdo_download command to download. Same with upload.
--- a/tool/Makefile.am Wed Jul 23 07:24:22 2008 +0000
+++ b/tool/Makefile.am Wed Jul 23 07:26:19 2008 +0000
@@ -45,8 +45,8 @@
cmd_master.cpp \
cmd_pdos.cpp \
cmd_sdos.cpp \
- cmd_sdo_download.cpp \
- cmd_sdo_upload.cpp \
+ cmd_download.cpp \
+ cmd_upload.cpp \
cmd_slaves.cpp \
cmd_sii_read.cpp \
cmd_sii_write.cpp \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tool/cmd_download.cpp Wed Jul 23 07:26:19 2008 +0000
@@ -0,0 +1,181 @@
+/*****************************************************************************
+ *
+ * $Id$
+ *
+ ****************************************************************************/
+
+#include <iostream>
+#include <iomanip>
+using namespace std;
+
+#include "globals.h"
+#include "coe_datatypes.h"
+
+/****************************************************************************/
+
+// FIXME
+const char *help_download =
+ "[OPTIONS]\n"
+ "\n"
+ "\n"
+ "Command-specific options:\n";
+
+/****************************************************************************/
+
+void command_download(void)
+{
+ stringstream strIndex, strSubIndex, strValue, err;
+ ec_ioctl_slave_sdo_download_t data;
+ unsigned int number;
+ const CoEDataType *dataType = NULL;
+
+ if (slavePosition < 0) {
+ err << "'sdo_download' requires a slave! Please specify --slave.";
+ throw MasterDeviceException(err.str());
+ }
+ data.slave_position = slavePosition;
+
+ if (commandArgs.size() != 3) {
+ err << "'sdo_download' takes 3 arguments!";
+ throw MasterDeviceException(err.str());
+ }
+
+ strIndex << commandArgs[0];
+ strIndex
+ >> resetiosflags(ios::basefield) // guess base from prefix
+ >> data.sdo_index;
+ if (strIndex.fail()) {
+ err << "Invalid Sdo index '" << commandArgs[0] << "'!";
+ throw MasterDeviceException(err.str());
+ }
+
+ strSubIndex << commandArgs[1];
+ strSubIndex
+ >> resetiosflags(ios::basefield) // guess base from prefix
+ >> number;
+ if (strSubIndex.fail() || number > 0xff) {
+ err << "Invalid Sdo subindex '" << commandArgs[1] << "'!";
+ throw MasterDeviceException(err.str());
+ }
+ data.sdo_entry_subindex = number;
+
+ if (dataTypeStr != "") { // data type specified
+ if (!(dataType = findDataType(dataTypeStr))) {
+ err << "Invalid data type '" << dataTypeStr << "'!";
+ throw MasterDeviceException(err.str());
+ }
+ } else { // no data type specified: fetch from dictionary
+ ec_ioctl_slave_sdo_entry_t entry;
+
+ masterDev.open(MasterDevice::ReadWrite);
+
+ try {
+ masterDev.getSdoEntry(&entry, slavePosition,
+ data.sdo_index, data.sdo_entry_subindex);
+ } catch (MasterDeviceException &e) {
+ err << "Failed to determine Sdo entry data type. "
+ << "Please specify --type.";
+ throw ExecutionFailureException(err);
+ }
+ if (!(dataType = findDataType(entry.data_type))) {
+ err << "Pdo entry has unknown data type 0x"
+ << hex << setfill('0') << setw(4) << entry.data_type << "!"
+ << " Please specify --type.";
+ throw ExecutionFailureException(err);
+ }
+ }
+
+ if (dataType->byteSize) {
+ data.data_size = dataType->byteSize;
+ } else {
+ data.data_size = DefaultBufferSize;
+ }
+
+ data.data = new uint8_t[data.data_size + 1];
+
+ strValue << commandArgs[2];
+ strValue >> resetiosflags(ios::basefield); // guess base from prefix
+ strValue.exceptions(ios::failbit);
+
+ try {
+ switch (dataType->coeCode) {
+ case 0x0002: // int8
+ {
+ int16_t val; // uint8_t is interpreted as char
+ strValue >> val;
+ if (val > 127 || val < -128)
+ throw ios::failure("Value out of range");
+ *data.data = val;
+ break;
+ }
+ case 0x0003: // int16
+ {
+ int16_t val;
+ strValue >> val;
+ *(int16_t *) data.data = cputole16(val);
+ break;
+ }
+ case 0x0004: // int32
+ {
+ int32_t val;
+ strValue >> val;
+ *(int32_t *) data.data = cputole32(val);
+ break;
+ }
+ case 0x0005: // uint8
+ {
+ uint16_t val; // uint8_t is interpreted as char
+ strValue >> val;
+ if (val > 0xff)
+ throw ios::failure("Value out of range");
+ *data.data = val;
+ break;
+ }
+ case 0x0006: // uint16
+ {
+ uint16_t val;
+ strValue >> val;
+ *(uint16_t *) data.data = cputole16(val);
+ break;
+ }
+ case 0x0007: // uint32
+ {
+ uint32_t val;
+ strValue >> val;
+ *(uint32_t *) data.data = cputole32(val);
+ break;
+ }
+ case 0x0009: // string
+ if (strValue.str().size() >= data.data_size) {
+ err << "String too large";
+ throw MasterDeviceException(err.str());
+ }
+ data.data_size = strValue.str().size();
+ strValue >> (char *) data.data;
+ break;
+
+ default:
+ delete [] data.data;
+ err << "Unknown data type 0x" << hex << dataType->coeCode;
+ throw MasterDeviceException(err.str());
+ }
+ } catch (ios::failure &e) {
+ delete [] data.data;
+ err << "Invalid value argument '" << commandArgs[2]
+ << "' for type '" << dataType->name << "'!";
+ throw MasterDeviceException(err.str());
+ }
+
+ masterDev.open(MasterDevice::ReadWrite);
+
+ try {
+ masterDev.sdoDownload(&data);
+ } catch(MasterDeviceException &e) {
+ delete [] data.data;
+ throw e;
+ }
+
+ delete [] data.data;
+}
+
+/*****************************************************************************/
--- a/tool/cmd_sdo_download.cpp Wed Jul 23 07:24:22 2008 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,181 +0,0 @@
-/*****************************************************************************
- *
- * $Id$
- *
- ****************************************************************************/
-
-#include <iostream>
-#include <iomanip>
-using namespace std;
-
-#include "globals.h"
-#include "coe_datatypes.h"
-
-/****************************************************************************/
-
-// FIXME
-const char *help_sdo_download =
- "[OPTIONS]\n"
- "\n"
- "\n"
- "Command-specific options:\n";
-
-/****************************************************************************/
-
-void command_sdo_download(void)
-{
- stringstream strIndex, strSubIndex, strValue, err;
- ec_ioctl_slave_sdo_download_t data;
- unsigned int number;
- const CoEDataType *dataType = NULL;
-
- if (slavePosition < 0) {
- err << "'sdo_download' requires a slave! Please specify --slave.";
- throw MasterDeviceException(err.str());
- }
- data.slave_position = slavePosition;
-
- if (commandArgs.size() != 3) {
- err << "'sdo_download' takes 3 arguments!";
- throw MasterDeviceException(err.str());
- }
-
- strIndex << commandArgs[0];
- strIndex
- >> resetiosflags(ios::basefield) // guess base from prefix
- >> data.sdo_index;
- if (strIndex.fail()) {
- err << "Invalid Sdo index '" << commandArgs[0] << "'!";
- throw MasterDeviceException(err.str());
- }
-
- strSubIndex << commandArgs[1];
- strSubIndex
- >> resetiosflags(ios::basefield) // guess base from prefix
- >> number;
- if (strSubIndex.fail() || number > 0xff) {
- err << "Invalid Sdo subindex '" << commandArgs[1] << "'!";
- throw MasterDeviceException(err.str());
- }
- data.sdo_entry_subindex = number;
-
- if (dataTypeStr != "") { // data type specified
- if (!(dataType = findDataType(dataTypeStr))) {
- err << "Invalid data type '" << dataTypeStr << "'!";
- throw MasterDeviceException(err.str());
- }
- } else { // no data type specified: fetch from dictionary
- ec_ioctl_slave_sdo_entry_t entry;
-
- masterDev.open(MasterDevice::ReadWrite);
-
- try {
- masterDev.getSdoEntry(&entry, slavePosition,
- data.sdo_index, data.sdo_entry_subindex);
- } catch (MasterDeviceException &e) {
- err << "Failed to determine Sdo entry data type. "
- << "Please specify --type.";
- throw ExecutionFailureException(err);
- }
- if (!(dataType = findDataType(entry.data_type))) {
- err << "Pdo entry has unknown data type 0x"
- << hex << setfill('0') << setw(4) << entry.data_type << "!"
- << " Please specify --type.";
- throw ExecutionFailureException(err);
- }
- }
-
- if (dataType->byteSize) {
- data.data_size = dataType->byteSize;
- } else {
- data.data_size = DefaultBufferSize;
- }
-
- data.data = new uint8_t[data.data_size + 1];
-
- strValue << commandArgs[2];
- strValue >> resetiosflags(ios::basefield); // guess base from prefix
- strValue.exceptions(ios::failbit);
-
- try {
- switch (dataType->coeCode) {
- case 0x0002: // int8
- {
- int16_t val; // uint8_t is interpreted as char
- strValue >> val;
- if (val > 127 || val < -128)
- throw ios::failure("Value out of range");
- *data.data = val;
- break;
- }
- case 0x0003: // int16
- {
- int16_t val;
- strValue >> val;
- *(int16_t *) data.data = cputole16(val);
- break;
- }
- case 0x0004: // int32
- {
- int32_t val;
- strValue >> val;
- *(int32_t *) data.data = cputole32(val);
- break;
- }
- case 0x0005: // uint8
- {
- uint16_t val; // uint8_t is interpreted as char
- strValue >> val;
- if (val > 0xff)
- throw ios::failure("Value out of range");
- *data.data = val;
- break;
- }
- case 0x0006: // uint16
- {
- uint16_t val;
- strValue >> val;
- *(uint16_t *) data.data = cputole16(val);
- break;
- }
- case 0x0007: // uint32
- {
- uint32_t val;
- strValue >> val;
- *(uint32_t *) data.data = cputole32(val);
- break;
- }
- case 0x0009: // string
- if (strValue.str().size() >= data.data_size) {
- err << "String too large";
- throw MasterDeviceException(err.str());
- }
- data.data_size = strValue.str().size();
- strValue >> (char *) data.data;
- break;
-
- default:
- delete [] data.data;
- err << "Unknown data type 0x" << hex << dataType->coeCode;
- throw MasterDeviceException(err.str());
- }
- } catch (ios::failure &e) {
- delete [] data.data;
- err << "Invalid value argument '" << commandArgs[2]
- << "' for type '" << dataType->name << "'!";
- throw MasterDeviceException(err.str());
- }
-
- masterDev.open(MasterDevice::ReadWrite);
-
- try {
- masterDev.sdoDownload(&data);
- } catch(MasterDeviceException &e) {
- delete [] data.data;
- throw e;
- }
-
- delete [] data.data;
-}
-
-/*****************************************************************************/
--- a/tool/cmd_sdo_upload.cpp Wed Jul 23 07:24:22 2008 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,161 +0,0 @@
-/*****************************************************************************
- *
- * $Id$
- *
- ****************************************************************************/
-
-#include <iostream>
-#include <iomanip>
-using namespace std;
-
-#include "globals.h"
-#include "coe_datatypes.h"
-
-/****************************************************************************/
-
-// FIXME
-const char *help_sdo_upload =
- "[OPTIONS]\n"
- "\n"
- "\n"
- "Command-specific options:\n";
-
-/****************************************************************************/
-
-void command_sdo_upload(void)
-{
- stringstream strIndex, strSubIndex;
- int sval;
- ec_ioctl_slave_sdo_upload_t data;
- unsigned int uval;
- const CoEDataType *dataType = NULL;
-
- if (slavePosition < 0) {
- stringstream err;
- err << "'sdo_upload' requires a slave! Please specify --slave.";
- throw MasterDeviceException(err.str());
- }
- data.slave_position = slavePosition;
-
- if (commandArgs.size() != 2) {
- stringstream err;
- err << "'sdo_upload' takes two arguments!";
- throw MasterDeviceException(err.str());
- }
-
- strIndex << commandArgs[0];
- strIndex
- >> resetiosflags(ios::basefield) // guess base from prefix
- >> data.sdo_index;
- if (strIndex.fail()) {
- stringstream err;
- err << "Invalid Sdo index '" << commandArgs[0] << "'!";
- throw MasterDeviceException(err.str());
- }
-
- strSubIndex << commandArgs[1];
- strSubIndex
- >> resetiosflags(ios::basefield) // guess base from prefix
- >> uval;
- if (strSubIndex.fail() || uval > 0xff) {
- stringstream err;
- err << "Invalid Sdo subindex '" << commandArgs[1] << "'!";
- throw MasterDeviceException(err.str());
- }
- data.sdo_entry_subindex = uval;
-
- if (dataTypeStr != "") { // data type specified
- if (!(dataType = findDataType(dataTypeStr))) {
- stringstream err;
- err << "Invalid data type '" << dataTypeStr << "'!";
- throw MasterDeviceException(err.str());
- }
- } else { // no data type specified: fetch from dictionary
- ec_ioctl_slave_sdo_entry_t entry;
-
- masterDev.open(MasterDevice::Read);
-
- try {
- masterDev.getSdoEntry(&entry, slavePosition,
- data.sdo_index, data.sdo_entry_subindex);
- } catch (MasterDeviceException &e) {
- stringstream err;
- err << "Failed to determine Sdo entry data type. "
- << "Please specify --type.";
- throw ExecutionFailureException(err);
- }
- if (!(dataType = findDataType(entry.data_type))) {
- stringstream err;
- err << "Pdo entry has unknown data type 0x"
- << hex << setfill('0') << setw(4) << entry.data_type << "!"
- << " Please specify --type.";
- throw ExecutionFailureException(err);
- }
- }
-
- if (dataType->byteSize) {
- data.target_size = dataType->byteSize;
- } else {
- data.target_size = DefaultBufferSize;
- }
-
- data.target = new uint8_t[data.target_size + 1];
-
- masterDev.open(MasterDevice::Read);
-
- try {
- masterDev.sdoUpload(&data);
- } catch (MasterDeviceException &e) {
- delete [] data.target;
- throw e;
- }
-
- masterDev.close();
-
- if (dataType->byteSize && data.data_size != dataType->byteSize) {
- stringstream err;
- err << "Data type mismatch. Expected " << dataType->name
- << " with " << dataType->byteSize << " byte, but got "
- << data.data_size << " byte.";
- throw MasterDeviceException(err.str());
- }
-
- cout << setfill('0');
- switch (dataType->coeCode) {
- case 0x0002: // int8
- sval = *(int8_t *) data.target;
- cout << sval << " 0x" << hex << setw(2) << sval << endl;
- break;
- case 0x0003: // int16
- sval = le16tocpu(*(int16_t *) data.target);
- cout << sval << " 0x" << hex << setw(4) << sval << endl;
- break;
- case 0x0004: // int32
- sval = le32tocpu(*(int32_t *) data.target);
- cout << sval << " 0x" << hex << setw(8) << sval << endl;
- break;
- case 0x0005: // uint8
- uval = (unsigned int) *(uint8_t *) data.target;
- cout << uval << " 0x" << hex << setw(2) << uval << endl;
- break;
- case 0x0006: // uint16
- uval = le16tocpu(*(uint16_t *) data.target);
- cout << uval << " 0x" << hex << setw(4) << uval << endl;
- break;
- case 0x0007: // uint32
- uval = le32tocpu(*(uint32_t *) data.target);
- cout << uval << " 0x" << hex << setw(8) << uval << endl;
- break;
- case 0x0009: // string
- cout << string((const char *) data.target, data.data_size)
- << endl;
- break;
- default:
- printRawData(data.target, data.data_size);
- break;
- }
-
- delete [] data.target;
-}
-
-/*****************************************************************************/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tool/cmd_upload.cpp Wed Jul 23 07:26:19 2008 +0000
@@ -0,0 +1,161 @@
+/*****************************************************************************
+ *
+ * $Id$
+ *
+ ****************************************************************************/
+
+#include <iostream>
+#include <iomanip>
+using namespace std;
+
+#include "globals.h"
+#include "coe_datatypes.h"
+
+/****************************************************************************/
+
+// FIXME
+const char *help_upload =
+ "[OPTIONS]\n"
+ "\n"
+ "\n"
+ "Command-specific options:\n";
+
+/****************************************************************************/
+
+void command_upload(void)
+{
+ stringstream strIndex, strSubIndex;
+ int sval;
+ ec_ioctl_slave_sdo_upload_t data;
+ unsigned int uval;
+ const CoEDataType *dataType = NULL;
+
+ if (slavePosition < 0) {
+ stringstream err;
+ err << "'sdo_upload' requires a slave! Please specify --slave.";
+ throw MasterDeviceException(err.str());
+ }
+ data.slave_position = slavePosition;
+
+ if (commandArgs.size() != 2) {
+ stringstream err;
+ err << "'sdo_upload' takes two arguments!";
+ throw MasterDeviceException(err.str());
+ }
+
+ strIndex << commandArgs[0];
+ strIndex
+ >> resetiosflags(ios::basefield) // guess base from prefix
+ >> data.sdo_index;
+ if (strIndex.fail()) {
+ stringstream err;
+ err << "Invalid Sdo index '" << commandArgs[0] << "'!";
+ throw MasterDeviceException(err.str());
+ }
+
+ strSubIndex << commandArgs[1];
+ strSubIndex
+ >> resetiosflags(ios::basefield) // guess base from prefix
+ >> uval;
+ if (strSubIndex.fail() || uval > 0xff) {
+ stringstream err;
+ err << "Invalid Sdo subindex '" << commandArgs[1] << "'!";
+ throw MasterDeviceException(err.str());
+ }
+ data.sdo_entry_subindex = uval;
+
+ if (dataTypeStr != "") { // data type specified
+ if (!(dataType = findDataType(dataTypeStr))) {
+ stringstream err;
+ err << "Invalid data type '" << dataTypeStr << "'!";
+ throw MasterDeviceException(err.str());
+ }
+ } else { // no data type specified: fetch from dictionary
+ ec_ioctl_slave_sdo_entry_t entry;
+
+ masterDev.open(MasterDevice::Read);
+
+ try {
+ masterDev.getSdoEntry(&entry, slavePosition,
+ data.sdo_index, data.sdo_entry_subindex);
+ } catch (MasterDeviceException &e) {
+ stringstream err;
+ err << "Failed to determine Sdo entry data type. "
+ << "Please specify --type.";
+ throw ExecutionFailureException(err);
+ }
+ if (!(dataType = findDataType(entry.data_type))) {
+ stringstream err;
+ err << "Pdo entry has unknown data type 0x"
+ << hex << setfill('0') << setw(4) << entry.data_type << "!"
+ << " Please specify --type.";
+ throw ExecutionFailureException(err);
+ }
+ }
+
+ if (dataType->byteSize) {
+ data.target_size = dataType->byteSize;
+ } else {
+ data.target_size = DefaultBufferSize;
+ }
+
+ data.target = new uint8_t[data.target_size + 1];
+
+ masterDev.open(MasterDevice::Read);
+
+ try {
+ masterDev.sdoUpload(&data);
+ } catch (MasterDeviceException &e) {
+ delete [] data.target;
+ throw e;
+ }
+
+ masterDev.close();
+
+ if (dataType->byteSize && data.data_size != dataType->byteSize) {
+ stringstream err;
+ err << "Data type mismatch. Expected " << dataType->name
+ << " with " << dataType->byteSize << " byte, but got "
+ << data.data_size << " byte.";
+ throw MasterDeviceException(err.str());
+ }
+
+ cout << setfill('0');
+ switch (dataType->coeCode) {
+ case 0x0002: // int8
+ sval = *(int8_t *) data.target;
+ cout << sval << " 0x" << hex << setw(2) << sval << endl;
+ break;
+ case 0x0003: // int16
+ sval = le16tocpu(*(int16_t *) data.target);
+ cout << sval << " 0x" << hex << setw(4) << sval << endl;
+ break;
+ case 0x0004: // int32
+ sval = le32tocpu(*(int32_t *) data.target);
+ cout << sval << " 0x" << hex << setw(8) << sval << endl;
+ break;
+ case 0x0005: // uint8
+ uval = (unsigned int) *(uint8_t *) data.target;
+ cout << uval << " 0x" << hex << setw(2) << uval << endl;
+ break;
+ case 0x0006: // uint16
+ uval = le16tocpu(*(uint16_t *) data.target);
+ cout << uval << " 0x" << hex << setw(4) << uval << endl;
+ break;
+ case 0x0007: // uint32
+ uval = le32tocpu(*(uint32_t *) data.target);
+ cout << uval << " 0x" << hex << setw(8) << uval << endl;
+ break;
+ case 0x0009: // string
+ cout << string((const char *) data.target, data.data_size)
+ << endl;
+ break;
+ default:
+ printRawData(data.target, data.data_size);
+ break;
+ }
+
+ delete [] data.target;
+}
+
+/*****************************************************************************/
--- a/tool/main.cpp Wed Jul 23 07:24:22 2008 +0000
+++ b/tool/main.cpp Wed Jul 23 07:26:19 2008 +0000
@@ -61,8 +61,8 @@
DEFINE_EXTERN_COMMAND(master);
DEFINE_EXTERN_COMMAND(pdos);
DEFINE_EXTERN_COMMAND(sdos);
-DEFINE_EXTERN_COMMAND(sdo_download);
-DEFINE_EXTERN_COMMAND(sdo_upload);
+DEFINE_EXTERN_COMMAND(download);
+DEFINE_EXTERN_COMMAND(upload);
DEFINE_EXTERN_COMMAND(slaves);
DEFINE_EXTERN_COMMAND(sii_read);
DEFINE_EXTERN_COMMAND(sii_write);
@@ -78,8 +78,8 @@
INIT_COMMAND(master, "Show master information."),
INIT_COMMAND(pdos, "List Pdo assignment/mapping."),
INIT_COMMAND(sdos, "List Sdo dictionaries."),
- INIT_COMMAND(sdo_download, "Write an Sdo entry."),
- INIT_COMMAND(sdo_upload, "Read an Sdo entry."),
+ INIT_COMMAND(download, "Write an Sdo entry."),
+ INIT_COMMAND(upload, "Read an Sdo entry."),
INIT_COMMAND(slaves, "Show slaves."),
INIT_COMMAND(sii_read, "Output a slave's SII contents."),
INIT_COMMAND(sii_write, "Write slave's SII contents."),
@@ -113,7 +113,7 @@
}
cerr
- << "Commands can be generously abbreviated." << endl
+ << "Commands can be abbreviated." << endl
<< "Global options:" << endl
<< " --master -m <master> Index of the master to use. Default: 0"
<< endl
@@ -121,8 +121,6 @@
<< endl
<< " or 'all' for all slaves (default)."
<< endl
- << " or 'all' for all domains (default)."
- << endl
<< " --type -t <type> Forced Sdo data type." << endl
<< " --force -f Force action." << endl
<< " --quiet -q Output less information." << endl