tool/cmd_upload.cpp
author Florian Pose <fp@igh-essen.com>
Thu, 24 Jul 2008 07:40:45 +0000
changeset 1139 074caa25365e
parent 1137 a73c0f54be42
permissions -rw-r--r--
Output requested help to stdout, help on invalid usage to stderr.
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 * $Id$
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 ****************************************************************************/
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#include <iostream>
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
#include <iomanip>
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
using namespace std;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
#include "globals.h"
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
#include "coe_datatypes.h"
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
/****************************************************************************/
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
const char *help_upload =
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    17
    "[OPTIONS] <INDEX> <SUBINDEX>\n"
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
    "\n"
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    19
    "Upload an Sdo entry from a slave.\n"
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
    "\n"
1137
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    21
    "The data type of the Sdo entry is taken from the Sdo dictionary by\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    22
    "default. It can be overridden with the --type option. If the slave\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    23
    "does not support the Sdo information service or the Sdo is not in the\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    24
    "dictionary, the --type option is mandatory.\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    25
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    26
    "These are the valid Sdo entry data types:\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    27
    "  int8, int16, int32, uint8, uint16, uint32, string.\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    28
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    29
    "Arguments:\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    30
    "  INDEX    is the Sdo index and must be an unsigned 16 bit number.\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    31
    "  SUBINDEX is the Sdo entry subindex and must be an unsigned 8 bit\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    32
    "           number.\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    33
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    34
    "Command-specific options:\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    35
    "  --slave -s <index>  Positive numerical ring position (mandatory).\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    36
    "  --type  -t <type>   Forced Sdo entry data type (see above).\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    37
    "\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    38
    "Numerical values can be specified either with decimal (no prefix),\n"
a73c0f54be42 Added command-line help for every ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
    39
    "octal (prefix '0') or hexadecimal (prefix '0x') base.\n";
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
/****************************************************************************/
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
void command_upload(void)
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
{
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1134
diff changeset
    45
    stringstream err, strIndex, strSubIndex;
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
    int sval;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
    ec_ioctl_slave_sdo_upload_t data;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
    unsigned int uval;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
    const CoEDataType *dataType = NULL;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
    if (slavePosition < 0) {
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1134
diff changeset
    52
        err << "'" << commandName << "' requires a slave! "
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1134
diff changeset
    53
            << "Please specify --slave.";
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1134
diff changeset
    54
        throw InvalidUsageException(err);
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
    }
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
    data.slave_position = slavePosition;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
    if (commandArgs.size() != 2) {
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1134
diff changeset
    59
        err << "'" << commandName << "' takes two arguments!";
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1134
diff changeset
    60
        throw InvalidUsageException(err);
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
    }
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    strIndex << commandArgs[0];
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
    strIndex
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
        >> resetiosflags(ios::basefield) // guess base from prefix
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
        >> data.sdo_index;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    if (strIndex.fail()) {
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
        err << "Invalid Sdo index '" << commandArgs[0] << "'!";
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1134
diff changeset
    69
        throw InvalidUsageException(err);
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    }
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    strSubIndex << commandArgs[1];
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    strSubIndex
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
        >> resetiosflags(ios::basefield) // guess base from prefix
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
        >> uval;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    if (strSubIndex.fail() || uval > 0xff) {
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
        err << "Invalid Sdo subindex '" << commandArgs[1] << "'!";
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1134
diff changeset
    78
        throw InvalidUsageException(err);
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
    }
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    data.sdo_entry_subindex = uval;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    if (dataTypeStr != "") { // data type specified
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
        if (!(dataType = findDataType(dataTypeStr))) {
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
            err << "Invalid data type '" << dataTypeStr << "'!";
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1134
diff changeset
    85
            throw InvalidUsageException(err);
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
        }
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
    } else { // no data type specified: fetch from dictionary
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
        ec_ioctl_slave_sdo_entry_t entry;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
        masterDev.open(MasterDevice::Read);
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
        try {
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
            masterDev.getSdoEntry(&entry, slavePosition,
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
                    data.sdo_index, data.sdo_entry_subindex);
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
        } catch (MasterDeviceException &e) {
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
            err << "Failed to determine Sdo entry data type. "
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
                << "Please specify --type.";
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1134
diff changeset
    98
            throw CommandException(err);
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
        }
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
        if (!(dataType = findDataType(entry.data_type))) {
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
            err << "Pdo entry has unknown data type 0x"
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
                << hex << setfill('0') << setw(4) << entry.data_type << "!"
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
                << " Please specify --type.";
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1134
diff changeset
   104
            throw CommandException(err);
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
        }
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    }
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    if (dataType->byteSize) {
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
        data.target_size = dataType->byteSize;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    } else {
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
        data.target_size = DefaultBufferSize;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    }
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
    data.target = new uint8_t[data.target_size + 1];
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    masterDev.open(MasterDevice::Read);
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
	try {
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
		masterDev.sdoUpload(&data);
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
	} catch (MasterDeviceException &e) {
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
        delete [] data.target;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
        throw e;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
    }
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
    masterDev.close();
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    if (dataType->byteSize && data.data_size != dataType->byteSize) {
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
        err << "Data type mismatch. Expected " << dataType->name
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
            << " with " << dataType->byteSize << " byte, but got "
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
            << data.data_size << " byte.";
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1134
diff changeset
   131
        throw CommandException(err);
1134
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
    }
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
    cout << setfill('0');
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
    switch (dataType->coeCode) {
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
        case 0x0002: // int8
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
            sval = *(int8_t *) data.target;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
            cout << sval << " 0x" << hex << setw(2) << sval << endl;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
            break;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
        case 0x0003: // int16
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
            sval = le16tocpu(*(int16_t *) data.target);
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
            cout << sval << " 0x" << hex << setw(4) << sval << endl;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
            break;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
        case 0x0004: // int32
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
            sval = le32tocpu(*(int32_t *) data.target);
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
            cout << sval << " 0x" << hex << setw(8) << sval << endl;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
            break;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
        case 0x0005: // uint8
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
            uval = (unsigned int) *(uint8_t *) data.target;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
            cout << uval << " 0x" << hex << setw(2) << uval << endl;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
            break;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
        case 0x0006: // uint16
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
            uval = le16tocpu(*(uint16_t *) data.target);
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
            cout << uval << " 0x" << hex << setw(4) << uval << endl;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
            break;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
        case 0x0007: // uint32
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
            uval = le32tocpu(*(uint32_t *) data.target);
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
            cout << uval << " 0x" << hex << setw(8) << uval << endl;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
            break;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
        case 0x0009: // string
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
            cout << string((const char *) data.target, data.data_size)
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
                << endl;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
            break;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
        default:
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
            printRawData(data.target, data.data_size);
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
            break;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    }
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
    delete [] data.target;
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
}
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
3356141fa2f8 Renamed sdo_download command to download. Same with upload.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
/*****************************************************************************/