tool/CommandUpload.cpp
author Florian Pose <fp@igh-essen.com>
Wed, 29 Apr 2009 13:06:38 +0000
changeset 1422 d41e4537b75f
parent 1393 979a7b26036d
child 1804 742607c464c4
permissions -rw-r--r--
Added 'ethercat graph' command.
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
     3
 *  $Id$
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
     4
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
     6
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
     8
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    11
 *  published by the Free Software Foundation.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    12
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    16
 *  Public License for more details.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    17
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    21
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1334
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 ****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <iostream>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <iomanip>
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
using namespace std;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include "CommandUpload.h"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
CommandUpload::CommandUpload():
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
    39
    SdoCommand("upload", "Read an SDO entry from a slave.")
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
/*****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
string CommandUpload::helpString() const
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
    stringstream str;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
    str << getName() << " [OPTIONS] <INDEX> <SUBINDEX>" << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
        << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
        << getBriefDescription() << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
        << endl
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
    53
        << "This command requires a single slave to be selected." << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
    54
    	<< endl
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
    55
        << "The data type of the SDO entry is taken from the SDO" << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
        << "dictionary by default. It can be overridden with the" << endl
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
    57
        << "--type option. If the slave does not support the SDO" << endl
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
    58
        << "information service or the SDO is not in the dictionary," << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
        << "the --type option is mandatory."  << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
        << endl
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
    61
        << "These are the valid SDO entry data types:" << endl
1334
da3d22a27500 merge -c1617 branches/stable-1.4: Added octet_string as an SDO data type.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    62
        << "  int8, int16, int32, uint8, uint16, uint32, string," << endl
da3d22a27500 merge -c1617 branches/stable-1.4: Added octet_string as an SDO data type.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    63
        << "  octet_string." << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
        << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
        << "Arguments:" << endl
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
    66
        << "  INDEX    is the SDO index and must be an unsigned" << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
        << "           16 bit number." << endl
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
    68
        << "  SUBINDEX is the SDO entry subindex and must be an" << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
        << "           unsigned 8 bit number." << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
        << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
        << "Command-specific options:" << endl
1157
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
    72
        << "  --alias    -a <alias>" << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
    73
        << "  --position -p <pos>    Slave selection. See the help of" << endl
04d1c950cf9d Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents: 1155
diff changeset
    74
        << "                         the 'slaves' command." << endl
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
    75
        << "  --type     -t <type>   SDO entry data type (see above)." << endl
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
        << endl
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
        << numericInfo();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
    return str.str();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
/****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
void CommandUpload::execute(MasterDevice &m, const StringVector &args)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
{
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
    86
    SlaveList slaves;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
    stringstream err, strIndex, strSubIndex;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
    ec_ioctl_slave_sdo_upload_t data;
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    89
    const DataType *dataType = NULL;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    unsigned int uval;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    if (args.size() != 2) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
        err << "'" << getName() << "' takes two arguments!";
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
        throwInvalidUsageException(err);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    strIndex << args[0];
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    strIndex
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
        >> resetiosflags(ios::basefield) // guess base from prefix
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
        >> data.sdo_index;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    if (strIndex.fail()) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
   102
        err << "Invalid SDO index '" << args[0] << "'!";
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
        throwInvalidUsageException(err);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    strSubIndex << args[1];
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
    strSubIndex
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
        >> resetiosflags(ios::basefield) // guess base from prefix
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
        >> uval;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    if (strSubIndex.fail() || uval > 0xff) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
   111
        err << "Invalid SDO subindex '" << args[1] << "'!";
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
        throwInvalidUsageException(err);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
    data.sdo_entry_subindex = uval;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   116
    m.open(MasterDevice::Read);
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   117
    slaves = selectedSlaves(m);
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   118
    if (slaves.size() != 1) {
1155
bd4e5b544473 Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents: 1151
diff changeset
   119
        throwSingleSlaveRequired(slaves.size());
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   120
    }
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   121
    data.slave_position = slaves.front().position;
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   122
1166
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
   123
    if (!getDataType().empty()) { // data type specified
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
   124
        if (!(dataType = findDataType(getDataType()))) {
006244d53f68 Removed global variables.
Florian Pose <fp@igh-essen.com>
parents: 1157
diff changeset
   125
            err << "Invalid data type '" << getDataType() << "'!";
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
            throwInvalidUsageException(err);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
        }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
    } else { // no data type specified: fetch from dictionary
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
        ec_ioctl_slave_sdo_entry_t entry;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
        try {
1151
1fc1535dec29 Alias/Position selection.
Florian Pose <fp@igh-essen.com>
parents: 1144
diff changeset
   132
            m.getSdoEntry(&entry, data.slave_position,
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
                    data.sdo_index, data.sdo_entry_subindex);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
        } catch (MasterDeviceException &e) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
   135
            err << "Failed to determine SDO entry data type. "
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
                << "Please specify --type.";
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
            throwCommandException(err);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
        }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
        if (!(dataType = findDataType(entry.data_type))) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
   140
            err << "PDO entry has unknown data type 0x"
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
                << hex << setfill('0') << setw(4) << entry.data_type << "!"
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
                << " Please specify --type.";
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
            throwCommandException(err);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
        }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
    if (dataType->byteSize) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
        data.target_size = dataType->byteSize;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
    } else {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
        data.target_size = DefaultBufferSize;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
    data.target = new uint8_t[data.target_size + 1];
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
	try {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
		m.sdoUpload(&data);
1184
75cd6681eb08 Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
   157
	} catch (MasterDeviceSdoAbortException &e) {
75cd6681eb08 Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
   158
        delete [] data.target;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1254
diff changeset
   159
        err << "SDO transfer aborted with code 0x"
1184
75cd6681eb08 Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
   160
            << setfill('0') << hex << setw(8) << e.abortCode
75cd6681eb08 Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
   161
            << ": " << abortText(e.abortCode);
75cd6681eb08 Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents: 1166
diff changeset
   162
        throwCommandException(err);
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
	} catch (MasterDeviceException &e) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
        delete [] data.target;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
        throw e;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    m.close();
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
    if (dataType->byteSize && data.data_size != dataType->byteSize) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
        err << "Data type mismatch. Expected " << dataType->name
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
            << " with " << dataType->byteSize << " byte, but got "
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
            << data.data_size << " byte.";
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
        throwCommandException(err);
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
    cout << setfill('0');
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
    switch (dataType->coeCode) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
        case 0x0002: // int8
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   180
            {
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   181
                int val = (int) *data.target;
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   182
                cout << "0x" << hex << setw(2) << val
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   183
                    << " " << dec << val << endl;
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   184
            }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
            break;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
        case 0x0003: // int16
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   187
            {
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   188
                int16_t val = le16_to_cpup(data.target);
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   189
                cout << "0x" << hex << setw(4) << val
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   190
                    << " " << dec << val << endl;
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   191
            }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
            break;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
        case 0x0004: // int32
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   194
            {
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   195
                int32_t val = le32_to_cpup(data.target);
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   196
                cout << "0x" << hex << setw(8) << val
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   197
                    << " " << dec << val << endl;
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   198
            }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
            break;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
        case 0x0005: // uint8
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   201
            {
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   202
                unsigned int val = (unsigned int) *data.target;
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   203
                cout << "0x" << hex << setw(2) << val
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   204
                    << " " << dec << val << endl;
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   205
            }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
            break;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
        case 0x0006: // uint16
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   208
            {
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   209
                uint16_t val = le16_to_cpup(data.target);
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   210
                cout << "0x" << hex << setw(4) << val
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   211
                    << " " << dec << val << endl;
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   212
            }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
            break;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
        case 0x0007: // uint32
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   215
            {
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   216
                uint32_t val = le32_to_cpup(data.target);
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   217
                cout << "0x" << hex << setw(8) << val
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   218
                    << " " << dec << val << endl;
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   219
            }
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
            break;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
        case 0x0009: // string
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
            cout << string((const char *) data.target, data.data_size)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
                << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
            break;
1334
da3d22a27500 merge -c1617 branches/stable-1.4: Added octet_string as an SDO data type.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   225
        case 0x000a: // octet_string
da3d22a27500 merge -c1617 branches/stable-1.4: Added octet_string as an SDO data type.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   226
            cout << string((const char *) data.target, data.data_size)
da3d22a27500 merge -c1617 branches/stable-1.4: Added octet_string as an SDO data type.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   227
                << endl;
da3d22a27500 merge -c1617 branches/stable-1.4: Added octet_string as an SDO data type.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   228
            break;
1142
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
        default:
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
            printRawData(data.target, data.data_size); // FIXME
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
            break;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
    delete [] data.target;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
/****************************************************************************/
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
void CommandUpload::printRawData(
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
		const uint8_t *data,
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
		unsigned int size
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
		)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
{
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
    cout << hex << setfill('0');
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
    while (size--) {
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
        cout << "0x" << setw(2) << (unsigned int) *data++;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
        if (size)
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
            cout << " ";
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
    }
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
    cout << endl;
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
}
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
59be91dfcbe1 Redesigned command interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
/*****************************************************************************/