tools/Master.cpp
author Florian Pose <fp@igh-essen.com>
Fri, 06 Jun 2008 15:16:37 +0000
changeset 969 e259df107c92
parent 968 b0e894257743
child 970 b7cbff36bc01
permissions -rw-r--r--
process Sdo requests even with error_flag set.
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 * $Id$
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 ****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#include <sys/types.h>
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
#include <sys/stat.h>
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
#include <fcntl.h>
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
#include <errno.h>
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
#include <sys/ioctl.h>
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
#include <iostream>
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
#include <iomanip>
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
#include <sstream>
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
    16
#include <cctype> // toupper()
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
using namespace std;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
#include "Master.h"
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    21
#if __BYTE_ORDER == __LITTLE_ENDIAN
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    22
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    23
#define le16tocpu(x) x
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    24
#define le32tocpu(x) x
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    25
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    26
#elif __BYTE_ORDER == __BIG_ENDIAN
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    27
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    28
#define le16tocpu(x) \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    29
        ((uint16_t)( \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    30
        (((uint16_t)(x) & 0x00ffU) << 8) | \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    31
        (((uint16_t)(x) & 0xff00U) >> 8) ))
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    32
#define le32tocpu(x) \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    33
        ((uint32_t)( \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    34
        (((uint32_t)(x) & 0x000000ffUL) << 24) | \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    35
        (((uint32_t)(x) & 0x0000ff00UL) <<  8) | \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    36
        (((uint32_t)(x) & 0x00ff0000UL) >>  8) | \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    37
        (((uint32_t)(x) & 0xff000000UL) >> 24) ))
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    38
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    39
#endif
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    40
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    41
/****************************************************************************/
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    42
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    43
struct CoEDataType {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    44
    const char *name;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    45
    uint16_t coeCode;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    46
    unsigned int byteSize;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    47
};
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    48
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    49
static const CoEDataType dataTypes[] = {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    50
    {"int8",   0x0002, 1},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    51
    {"int16",  0x0003, 2},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    52
    {"int32",  0x0004, 4},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    53
    {"uint8",  0x0005, 1},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    54
    {"uint16", 0x0006, 2},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    55
    {"uint32", 0x0007, 4},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    56
    {"string", 0x0009, 0},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    57
    {"raw",    0xffff, 0},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    58
    {}
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    59
};
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    60
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    61
/****************************************************************************/
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    62
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    63
const CoEDataType *findDataType(const string &str)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    64
{
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    65
    const CoEDataType *d;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    66
    
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    67
    for (d = dataTypes; d->name; d++)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    68
        if (str == d->name)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    69
            return d;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    70
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    71
    return NULL;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    72
}
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    73
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    74
/****************************************************************************/
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    75
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    76
const CoEDataType *findDataType(uint16_t code)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    77
{
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    78
    const CoEDataType *d;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    79
    
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    80
    for (d = dataTypes; d->name; d++)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    81
        if (code == d->coeCode)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    82
            return d;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    83
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    84
    return NULL;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    85
}
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    86
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
/****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
Master::Master()
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    index = 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    fd = -1;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
/****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
Master::~Master()
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    close();
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
/****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
void Master::open(unsigned int index)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    stringstream deviceName;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
    
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    Master::index = index;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    deviceName << "/dev/EtherCAT" << index;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    if ((fd = ::open(deviceName.str().c_str(), O_RDONLY)) == -1) {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
        stringstream err;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
        err << "Failed to open master device " << deviceName.str() << ": "
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
            << strerror(errno);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
        throw MasterException(err.str());
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
    }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
/****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
void Master::close()
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    if (fd == -1)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
        return;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    ::close(fd);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
/****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   132
void Master::outputData(int domainIndex)
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   133
{
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   134
    if (domainIndex == -1) {
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   135
        unsigned int numDomains = domainCount(), i;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   136
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   137
        for (i = 0; i < numDomains; i++) {
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   138
            outputDomainData(i);
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   139
        }
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   140
    } else {
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   141
        outputDomainData(domainIndex);
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   142
    }
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   143
}
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   144
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   145
/****************************************************************************/
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   146
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   147
void Master::setDebug(const vector<string> &commandArgs)
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   148
{
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   149
    stringstream str;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   150
    int debugLevel;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   151
    
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   152
    if (commandArgs.size() != 1) {
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   153
        stringstream err;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   154
        err << "'debug' takes exactly one argument!";
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   155
        throw MasterException(err.str());
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   156
    }
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   157
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   158
    str << commandArgs[0];
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   159
    str >> debugLevel;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   160
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   161
    if (str.fail()) {
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   162
        stringstream err;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   163
        err << "Invalid debug level '" << commandArgs[0] << "'!";
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   164
        throw MasterException(err.str());
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   165
    }
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   166
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   167
    if (ioctl(fd, EC_IOCTL_SET_DEBUG, debugLevel) < 0) {
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   168
        stringstream err;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   169
        err << "Failed to set debug level: " << strerror(errno);
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   170
        throw MasterException(err.str());
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   171
    }
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   172
}
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   173
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   174
/****************************************************************************/
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   175
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   176
void Master::showDomains(int domainIndex)
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   177
{
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   178
    if (domainIndex == -1) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   179
        unsigned int numDomains = domainCount(), i;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   180
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   181
        for (i = 0; i < numDomains; i++) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   182
            showDomain(i);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   183
        }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   184
    } else {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   185
        showDomain(domainIndex);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   186
    }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   187
}
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   188
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   189
/****************************************************************************/
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   190
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
void Master::listSlaves()
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
    unsigned int numSlaves = slaveCount(), i;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   194
    ec_ioctl_slave_t slave;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
    uint16_t lastAlias, aliasIndex;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
    
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
    lastAlias = 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
    aliasIndex = 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
    for (i = 0; i < numSlaves; i++) {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   200
        getSlave(&slave, i);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   201
        cout << setw(2) << i << "  ";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   202
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   203
        if (slave.alias) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   204
            lastAlias = slave.alias;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
            aliasIndex = 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
        }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
        if (lastAlias) {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
            cout << setw(10) << "#" << lastAlias << ":" << aliasIndex;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
        }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   211
        cout << "  " << slaveState(slave.state) << "  ";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   212
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   213
        if (strlen(slave.name)) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   214
            cout << slave.name;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
        } else {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   216
            cout << "0x" << hex << setfill('0') << slave.vendor_id
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   217
                << ":0x" << slave.product_code;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
        }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
        cout << endl;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
    }
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   222
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   223
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   224
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   225
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   226
void Master::showMaster()
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   227
{
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   228
    ec_ioctl_master_t data;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   229
    stringstream err;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   230
    unsigned int i;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   231
    
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   232
    getMaster(&data);
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   233
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   234
    cout
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   235
        << "Master" << index << endl
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   236
        << "  State: ";
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   237
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   238
    switch (data.mode) {
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   239
        case 0: cout << "Waiting for device..."; break;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   240
        case 1: cout << "Idle"; break;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   241
        case 2: cout << "Operation"; break;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   242
        default:
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   243
                err << "Invalid master state " << data.mode;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   244
                throw MasterException(err.str());
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   245
    }
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   246
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   247
    cout << endl
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   248
        << "  Slaves: " << data.slave_count << endl;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   249
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   250
    for (i = 0; i < 2; i++) {
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   251
        cout << "  Device" << i << ": ";
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   252
        if (data.devices[i].address[0] == 0x00
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   253
                && data.devices[i].address[1] == 0x00
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   254
                && data.devices[i].address[2] == 0x00
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   255
                && data.devices[i].address[3] == 0x00
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   256
                && data.devices[i].address[4] == 0x00
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   257
                && data.devices[i].address[5] == 0x00) {
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   258
            cout << "None.";
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   259
        } else {
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   260
            cout << hex << setfill('0')
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   261
                << setw(2) << (unsigned int) data.devices[i].address[0] << ":"
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   262
                << setw(2) << (unsigned int) data.devices[i].address[1] << ":"
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   263
                << setw(2) << (unsigned int) data.devices[i].address[2] << ":"
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   264
                << setw(2) << (unsigned int) data.devices[i].address[3] << ":"
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   265
                << setw(2) << (unsigned int) data.devices[i].address[4] << ":"
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   266
                << setw(2) << (unsigned int) data.devices[i].address[5] << " ("
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   267
                << (data.devices[i].attached ? "attached" : "waiting...")
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   268
                << ")" << endl << dec
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   269
                << "    Tx count: " << data.devices[i].tx_count << endl
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   270
                << "    Rx count: " << data.devices[i].rx_count;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   271
        }
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   272
        cout << endl;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   273
    }
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   274
}
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   275
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   276
/****************************************************************************/
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   277
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   278
void Master::listPdos(int slavePosition, bool quiet)
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   279
{
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   280
    if (slavePosition == -1) {
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   281
        unsigned int numSlaves = slaveCount(), i;
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   282
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   283
        for (i = 0; i < numSlaves; i++) {
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   284
            listSlavePdos(i, quiet, true);
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   285
        }
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   286
    } else {
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   287
        listSlavePdos(slavePosition, quiet, false);
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   288
    }
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   289
}
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   290
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   291
/****************************************************************************/
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   292
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   293
void Master::listSdos(int slavePosition, bool quiet)
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   294
{
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   295
    if (slavePosition == -1) {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   296
        unsigned int numSlaves = slaveCount(), i;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   297
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   298
        for (i = 0; i < numSlaves; i++) {
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   299
            listSlaveSdos(i, quiet, true);
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   300
        }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   301
    } else {
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   302
        listSlaveSdos(slavePosition, quiet, false);
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   303
    }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   304
}
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   305
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   306
/****************************************************************************/
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   307
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   308
void Master::sdoUpload(
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   309
        int slavePosition,
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   310
        const string &dataTypeStr,
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   311
        const vector<string> &commandArgs
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   312
        )
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   313
{
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   314
    stringstream strIndex, strSubIndex;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   315
    int number, sval;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   316
    ec_ioctl_sdo_upload_t data;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   317
    unsigned int i, uval;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   318
    const CoEDataType *dataType = NULL;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   319
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   320
    if (slavePosition < 0) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   321
        stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   322
        err << "'sdo_upload' requires a slave! Please specify --slave.";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   323
        throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   324
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   325
    data.slave_position = slavePosition;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   326
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   327
    if (commandArgs.size() != 2) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   328
        stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   329
        err << "'sdo_upload' takes two arguments!";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   330
        throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   331
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   332
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   333
    strIndex << commandArgs[0];
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   334
    strIndex >> hex >> number;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   335
    if (strIndex.fail() || number < 0x0000 || number > 0xffff) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   336
        stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   337
        err << "Invalid Sdo index '" << commandArgs[0] << "'!";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   338
        throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   339
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   340
    data.sdo_index = number;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   341
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   342
    strSubIndex << commandArgs[1];
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   343
    strSubIndex >> hex >> number;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   344
    if (strSubIndex.fail() || number < 0x00 || number > 0xff) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   345
        stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   346
        err << "Invalid Sdo subindex '" << commandArgs[1] << "'!";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   347
        throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   348
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   349
    data.sdo_entry_subindex = number;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   350
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   351
    if (dataTypeStr != "") { // data type specified
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   352
        if (!(dataType = findDataType(dataTypeStr))) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   353
            stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   354
            err << "Invalid data type '" << dataTypeStr << "'!";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   355
            throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   356
        }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   357
    } else { // no data type specified: fetch from dictionary
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   358
        ec_ioctl_sdo_entry_t entry;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   359
        unsigned int entryByteSize;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   360
        try {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   361
            getSdoEntry(&entry, slavePosition,
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   362
                    data.sdo_index, data.sdo_entry_subindex);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   363
        } catch (MasterException &e) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   364
            stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   365
            err << "Failed to determine Sdo entry data type. "
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   366
                << "Please specify --type.";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   367
            throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   368
        }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   369
        if (!(dataType = findDataType(entry.data_type))) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   370
            stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   371
            err << "Pdo entry has unknown data type 0x"
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   372
                << hex << setfill('0') << setw(4) << entry.data_type << "!"
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   373
                << " Please specify --type.";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   374
            throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   375
        }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   376
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   377
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   378
    if (dataType->byteSize) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   379
        data.target_size = dataType->byteSize;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   380
    } else {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   381
        data.target_size = DefaultTargetSize;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   382
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   383
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   384
    data.target = new uint8_t[data.target_size + 1];
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   385
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   386
    if (ioctl(fd, EC_IOCTL_SDO_UPLOAD, &data) < 0) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   387
        stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   388
        err << "Failed to upload Sdo: " << strerror(errno);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   389
        delete [] data.target;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   390
        throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   391
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   392
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   393
    if (dataType->byteSize && data.data_size != dataType->byteSize) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   394
        stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   395
        err << "Data type mismatch. Expected " << dataType->name
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   396
            << " with " << dataType->byteSize << " byte(s), but got "
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   397
            << data.data_size << " byte(s).";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   398
        throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   399
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   400
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   401
    cout << setfill('0');
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   402
    switch (dataType->coeCode) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   403
        case 0x0002: // int8
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   404
            sval = *(int8_t *) data.target;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   405
            cout << sval << " 0x" << hex << setw(2) << sval << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   406
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   407
        case 0x0003: // int16
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   408
            sval = le16tocpu(*(int16_t *) data.target);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   409
            cout << sval << " 0x" << hex << setw(4) << sval << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   410
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   411
        case 0x0004: // int32
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   412
            sval = le32tocpu(*(int32_t *) data.target);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   413
            cout << sval << " 0x" << hex << setw(8) << sval << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   414
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   415
        case 0x0005: // uint8
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   416
            uval = (unsigned int) *(uint8_t *) data.target;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   417
            cout << uval << " 0x" << hex << setw(2) << uval << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   418
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   419
        case 0x0006: // uint16
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   420
            uval = le16tocpu(*(uint16_t *) data.target);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   421
            cout << uval << " 0x" << hex << setw(4) << uval << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   422
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   423
        case 0x0007: // uint32
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   424
            uval = le32tocpu(*(uint32_t *) data.target);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   425
            cout << uval << " 0x" << hex << setw(8) << uval << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   426
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   427
        case 0x0009: // string
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   428
            cout << string((const char *) data.target, data.data_size)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   429
                << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   430
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   431
        default:
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   432
            printRawData(data.target, data.data_size);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   433
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   434
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   435
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   436
    delete [] data.target;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   437
}
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   438
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   439
/****************************************************************************/
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   440
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   441
void Master::requestStates(
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   442
        int slavePosition,
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   443
        const vector<string> &commandArgs
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   444
        )
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   445
{
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   446
    string stateStr;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   447
    uint8_t state;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   448
    
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   449
    if (commandArgs.size() != 1) {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   450
        stringstream err;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   451
        err << "'state' takes exactly one argument!";
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   452
        throw MasterException(err.str());
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   453
    }
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   454
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   455
    stateStr = commandArgs[0];
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   456
    transform(stateStr.begin(), stateStr.end(),
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   457
            stateStr.begin(), (int (*) (int)) std::toupper);
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   458
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   459
    if (stateStr == "INIT") {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   460
        state = 0x01;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   461
    } else if (stateStr == "PREOP") {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   462
        state = 0x02;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   463
    } else if (stateStr == "SAFEOP") {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   464
        state = 0x04;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   465
    } else if (stateStr == "OP") {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   466
        state = 0x08;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   467
    } else {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   468
        stringstream err;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   469
        err << "Invalid state '" << commandArgs[0] << "'!";
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   470
        throw MasterException(err.str());
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   471
    }
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   472
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   473
    if (slavePosition == -1) {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   474
        unsigned int i, numSlaves = slaveCount();
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   475
        for (i = 0; i < numSlaves; i++)
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   476
            requestState(i, state);
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   477
    } else {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   478
        requestState(slavePosition, state);
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   479
    }
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   480
}
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   481
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   482
/****************************************************************************/
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   483
938
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   484
void Master::generateXml(int slavePosition)
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   485
{
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   486
    if (slavePosition == -1) {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   487
        unsigned int numSlaves = slaveCount(), i;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   488
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   489
        for (i = 0; i < numSlaves; i++) {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   490
            generateSlaveXml(i);
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   491
        }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   492
    } else {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   493
        generateSlaveXml(slavePosition);
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   494
    }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   495
}
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   496
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   497
/****************************************************************************/
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   498
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   499
void Master::outputDomainData(unsigned int domainIndex)
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   500
{
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   501
    ec_ioctl_domain_t domain;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   502
    ec_ioctl_data_t data;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   503
    unsigned char *processData;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   504
    unsigned int i;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   505
    
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   506
    getDomain(&domain, domainIndex);
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   507
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   508
    if (!domain.data_size)
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   509
        return;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   510
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   511
    processData = new unsigned char[domain.data_size];
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   512
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   513
    try {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   514
        getData(&data, domainIndex, domain.data_size, processData);
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   515
    } catch (MasterException &e) {
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   516
        delete [] processData;
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   517
        throw e;
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   518
    }
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   519
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   520
    for (i = 0; i < data.data_size; i++)
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   521
        cout << processData[i];
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   522
    cout.flush();
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   523
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   524
    delete [] processData;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   525
}
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   526
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   527
/****************************************************************************/
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   528
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   529
void Master::showDomain(unsigned int domainIndex)
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   530
{
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   531
    ec_ioctl_domain_t domain;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   532
    unsigned char *processData;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   533
    ec_ioctl_data_t data;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   534
    unsigned int i, j;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   535
    ec_ioctl_domain_fmmu_t fmmu;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   536
    unsigned int dataOffset;
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   537
    
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   538
    getDomain(&domain, domainIndex);
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   539
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   540
	cout << "Domain" << domainIndex << ":"
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   541
		<< " LogBaseAddr 0x"
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   542
		<< hex << setfill('0') << setw(8) << domain.logical_base_address
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   543
		<< ", Size " << dec << setfill(' ') << setw(3) << domain.data_size
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   544
		<< ", WorkingCounter "
951
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
   545
		<< dec << domain.working_counter << "/"
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
   546
        << domain.expected_working_counter << endl;
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   547
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   548
    if (!domain.data_size)
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   549
        return;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   550
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   551
    processData = new unsigned char[domain.data_size];
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   552
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   553
    try {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   554
        getData(&data, domainIndex, domain.data_size, processData);
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   555
    } catch (MasterException &e) {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   556
        delete [] processData;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   557
        throw e;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   558
    }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   559
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   560
    for (i = 0; i < domain.fmmu_count; i++) {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   561
        getFmmu(&fmmu, domainIndex, i);
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   562
951
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
   563
        cout << "  SlaveConfig "
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
   564
            << fmmu.slave_config_alias << ":" << fmmu.slave_config_position
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
   565
            << ", Dir "
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
   566
            << setfill(' ') << setw(3) << (fmmu.fmmu_dir ? "In" : "Out")
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   567
            << ", LogAddr 0x" 
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   568
            << hex << setfill('0') << setw(8) << fmmu.logical_address
951
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
   569
            << ", Size " << dec << fmmu.data_size << endl;
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   570
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   571
        dataOffset = fmmu.logical_address - domain.logical_base_address;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   572
        if (dataOffset + fmmu.data_size > domain.data_size) {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   573
            stringstream err;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   574
            err << "Fmmu information corrupted!";
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   575
            delete [] processData;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   576
            throw MasterException(err.str());
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   577
        }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   578
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   579
        cout << "    " << hex << setfill('0');
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   580
        for (j = 0; j < fmmu.data_size; j++) {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   581
            cout << setw(2)
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   582
                << (unsigned int) *(processData + dataOffset + j) << " ";
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   583
        }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   584
        cout << endl;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   585
    }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   586
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   587
    delete [] processData;
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   588
}
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   589
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   590
/****************************************************************************/
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   591
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   592
void Master::listSlavePdos(
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   593
        uint16_t slavePosition,
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   594
        bool quiet,
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   595
        bool withHeader
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   596
        )
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   597
{
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   598
    ec_ioctl_slave_t slave;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   599
    ec_ioctl_sync_t sync;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   600
    ec_ioctl_pdo_t pdo;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   601
    ec_ioctl_pdo_entry_t entry;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   602
    unsigned int i, j, k;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   603
    
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   604
    getSlave(&slave, slavePosition);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   605
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   606
    if (withHeader)
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   607
        cout << "=== Slave " << slavePosition << " ===" << endl;
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   608
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   609
    for (i = 0; i < slave.sync_count; i++) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   610
        getSync(&sync, slavePosition, i);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   611
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   612
        cout << "SM" << i << ":"
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   613
            << " PhysAddr 0x"
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   614
            << hex << setfill('0') << setw(4) << sync.physical_start_address
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   615
            << ", DefaultSize "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   616
            << dec << setfill(' ') << setw(4) << sync.default_size
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   617
            << ", ControlRegister 0x"
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   618
            << hex << setfill('0') << setw(2)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   619
            << (unsigned int) sync.control_register
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   620
            << ", Enable " << dec << (unsigned int) sync.enable
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   621
            << endl;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   622
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   623
        for (j = 0; j < sync.pdo_count; j++) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   624
            getPdo(&pdo, slavePosition, i, j);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   625
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   626
            cout << "  " << (pdo.dir ? "T" : "R") << "xPdo 0x"
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   627
                << hex << setfill('0') << setw(4) << pdo.index
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   628
                << " \"" << pdo.name << "\"" << endl;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   629
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   630
            if (quiet)
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   631
                continue;
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   632
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   633
            for (k = 0; k < pdo.entry_count; k++) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   634
                getPdoEntry(&entry, slavePosition, i, j, k);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   635
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   636
                cout << "    Pdo entry 0x"
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   637
                    << hex << setfill('0') << setw(4) << entry.index
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   638
                    << ":" << hex << setfill('0') << setw(2)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   639
                    << (unsigned int) entry.subindex
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   640
                    << ", " << dec << (unsigned int) entry.bit_length
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   641
                    << " bit, \"" << entry.name << "\"" << endl;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   642
            }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   643
        }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   644
    }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   645
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   646
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   647
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   648
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   649
void Master::listSlaveSdos(
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   650
        uint16_t slavePosition,
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   651
        bool quiet,
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   652
        bool withHeader
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   653
        )
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   654
{
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   655
    ec_ioctl_slave_t slave;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   656
    ec_ioctl_sdo_t sdo;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   657
    ec_ioctl_sdo_entry_t entry;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   658
    unsigned int i, j, k;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   659
    
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   660
    getSlave(&slave, slavePosition);
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   661
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   662
    if (withHeader)
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   663
        cout << "=== Slave " << slavePosition << " ===" << endl;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   664
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   665
    for (i = 0; i < slave.sdo_count; i++) {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   666
        getSdo(&sdo, slavePosition, i);
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   667
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   668
        cout << "Sdo 0x"
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   669
            << hex << setfill('0') << setw(4) << sdo.sdo_index
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   670
            << ", \"" << sdo.name << "\"" << endl;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   671
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   672
        if (quiet)
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   673
            continue;
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   674
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   675
        for (j = 0; j <= sdo.max_subindex; j++) {
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   676
            getSdoEntry(&entry, slavePosition, -i, j);
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   677
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   678
            cout << "  Entry 0x"
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   679
                << hex << setfill('0') << setw(2)
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   680
                << (unsigned int) entry.sdo_entry_subindex
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   681
                << ", type 0x" << setw(4) << entry.data_type
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   682
                << ", " << dec << entry.bit_length << " bit, \""
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   683
                << entry.description << "\"" << endl;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   684
        }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   685
    }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   686
}
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   687
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   688
/****************************************************************************/
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   689
938
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   690
void Master::generateSlaveXml(uint16_t slavePosition)
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   691
{
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   692
    ec_ioctl_slave_t slave;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   693
    ec_ioctl_sync_t sync;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   694
    ec_ioctl_pdo_t pdo;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   695
    ec_ioctl_pdo_entry_t entry;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   696
    unsigned int i, j, k;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   697
    
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   698
    getSlave(&slave, slavePosition);
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   699
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   700
    cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   701
        << "<?xml version=\"1.0\" ?>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   702
        << "  <EtherCATInfo>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   703
        << "    <!-- Slave " << slave.position << " -->" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   704
        << "    <Vendor>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   705
        << "      <Id>" << slave.vendor_id << "</Id>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   706
        << "    </Vendor>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   707
        << "    <Descriptions>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   708
        << "      <Devices>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   709
        << "        <Device>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   710
        << "          <Type ProductCode=\"#x"
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   711
        << hex << setfill('0') << setw(8) << slave.product_code
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   712
        << "\" RevisionNo=\"#x"
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   713
        << hex << setfill('0') << setw(8) << slave.revision_number
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   714
        << "\"/>" << endl;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   715
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   716
    for (i = 0; i < slave.sync_count; i++) {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   717
        getSync(&sync, slavePosition, i);
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   718
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   719
        for (j = 0; j < sync.pdo_count; j++) {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   720
            getPdo(&pdo, slavePosition, i, j);
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   721
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   722
            cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   723
                << "          <" << (pdo.dir ? "T" : "R") << "xPdo>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   724
                << "            <Index>#x"
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   725
                << hex << setfill('0') << setw(4) << pdo.index
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   726
                << "</Index>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   727
                << "            <Name>" << pdo.name << "</Name>" << endl;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   728
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   729
            for (k = 0; k < pdo.entry_count; k++) {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   730
                getPdoEntry(&entry, slavePosition, i, j, k);
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   731
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   732
                cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   733
                    << "            <Entry>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   734
                    << "              <Index>#x"
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   735
                    << hex << setfill('0') << setw(4) << entry.index
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   736
                    << "</Index>" << endl;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   737
                if (entry.index)
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   738
                    cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   739
                        << "              <SubIndex>"
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   740
                        << dec << (unsigned int) entry.subindex
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   741
                        << "</SubIndex>" << endl;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   742
                
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   743
                cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   744
                    << "              <BitLen>"
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   745
                    << (unsigned int) entry.bit_length
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   746
                    << "</BitLen>" << endl;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   747
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   748
                if (entry.index) {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   749
                    cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   750
                        << "              <Name>" << entry.name
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   751
                        << "</Name>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   752
                        << "              <DataType>";
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   753
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   754
                    if (entry.bit_length == 1) {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   755
                        cout << "BOOL";
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   756
                    } else if (!(entry.bit_length % 8)) {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   757
                        if (entry.bit_length <= 64)
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   758
                            cout << "UINT" << (unsigned int) entry.bit_length;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   759
                        else
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   760
                            cout << "STRING("
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   761
                                << (unsigned int) (entry.bit_length / 8)
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   762
                                << ")";
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   763
                    } else {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   764
                        cerr << "Invalid bit length "
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   765
                            << (unsigned int) entry.bit_length << endl;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   766
                    }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   767
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   768
                        cout << "</DataType>" << endl;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   769
                }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   770
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   771
                cout << "            </Entry>" << endl;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   772
            }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   773
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   774
            cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   775
                << "          </" << (pdo.dir ? "T" : "R") << "xPdo>" << endl;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   776
        }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   777
    }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   778
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   779
    cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   780
        << "        </Device>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   781
        << "     </Devices>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   782
        << "  </Descriptions>" << endl
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   783
        << "</EtherCATInfo>" << endl;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   784
}
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   785
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   786
/****************************************************************************/
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
   787
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   788
unsigned int Master::domainCount()
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   789
{
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   790
    int ret;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   791
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   792
    if ((ret = ioctl(fd, EC_IOCTL_DOMAIN_COUNT, 0)) < 0) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   793
        stringstream err;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   794
        err << "Failed to get number of domains: " << strerror(errno);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   795
        throw MasterException(err.str());
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   796
    }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   797
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   798
    return ret;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   799
}
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   800
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   801
/****************************************************************************/
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   802
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   803
unsigned int Master::slaveCount()
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   804
{
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   805
    ec_ioctl_master_t data;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   806
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   807
    getMaster(&data);
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   808
    return data.slave_count;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   809
}
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   810
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   811
/****************************************************************************/
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   812
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   813
void Master::getMaster(ec_ioctl_master_t *data)
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   814
{
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   815
    if (ioctl(fd, EC_IOCTL_MASTER, data) < 0) {
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   816
        stringstream err;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   817
        err << "Failed to get master information: " << strerror(errno);
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   818
        throw MasterException(err.str());
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   819
    }
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   820
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   821
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   822
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   823
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   824
void Master::getDomain(ec_ioctl_domain_t *data, unsigned int index)
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   825
{
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   826
    data->index = index;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   827
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   828
    if (ioctl(fd, EC_IOCTL_DOMAIN, data)) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   829
        stringstream err;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   830
        err << "Failed to get domain: ";
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   831
        if (errno == EINVAL)
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   832
            err << "Domain " << index << " does not exist!";
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   833
        else
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   834
            err << strerror(errno);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   835
        throw MasterException(err.str());
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   836
    }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   837
}
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   838
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   839
/****************************************************************************/
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   840
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   841
void Master::getData(ec_ioctl_data_t *data, unsigned int domainIndex,
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   842
        unsigned int dataSize, unsigned char *mem)
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   843
{
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   844
    data->domain_index = domainIndex;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   845
    data->data_size = dataSize;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   846
    data->target = mem;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   847
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   848
    if (ioctl(fd, EC_IOCTL_DATA, data) < 0) {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   849
        stringstream err;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   850
        err << "Failed to get domain data: " << strerror(errno);
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   851
        throw MasterException(err.str());
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   852
    }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   853
}
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   854
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   855
/****************************************************************************/
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   856
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   857
void Master::getSlave(ec_ioctl_slave_t *slave, uint16_t slaveIndex)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   858
{
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   859
    slave->position = slaveIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   860
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   861
    if (ioctl(fd, EC_IOCTL_SLAVE, slave)) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   862
        stringstream err;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   863
        err << "Failed to get slave: ";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   864
        if (errno == EINVAL)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   865
            err << "Slave " << slaveIndex << " does not exist!";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   866
        else
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   867
            err << strerror(errno);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   868
        throw MasterException(err.str());
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   869
    }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   870
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   871
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   872
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   873
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   874
void Master::getFmmu(
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   875
        ec_ioctl_domain_fmmu_t *fmmu,
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   876
        unsigned int domainIndex,
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   877
        unsigned int fmmuIndex
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   878
        )
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   879
{
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   880
    fmmu->domain_index = domainIndex;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   881
    fmmu->fmmu_index = fmmuIndex;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   882
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   883
    if (ioctl(fd, EC_IOCTL_DOMAIN_FMMU, fmmu)) {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   884
        stringstream err;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   885
        err << "Failed to get domain FMMU: ";
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   886
        if (errno == EINVAL)
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   887
            err << "Either domain " << domainIndex << " does not exist, "
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   888
                << "or it contains less than " << (unsigned int) fmmuIndex + 1
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   889
                << " FMMus!";
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   890
        else
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   891
            err << strerror(errno);
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   892
        throw MasterException(err.str());
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   893
    }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   894
}
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   895
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   896
/****************************************************************************/
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   897
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   898
void Master::getSync(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   899
        ec_ioctl_sync_t *sync,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   900
        uint16_t slaveIndex,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   901
        uint8_t syncIndex
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   902
        )
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   903
{
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   904
    sync->slave_position = slaveIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   905
    sync->sync_index = syncIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   906
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   907
    if (ioctl(fd, EC_IOCTL_SYNC, sync)) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   908
        stringstream err;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   909
        err << "Failed to get sync manager: ";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   910
        if (errno == EINVAL)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   911
            err << "Either slave " << slaveIndex << " does not exist, "
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   912
                << "or it contains less than " << (unsigned int) syncIndex + 1
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   913
                << " sync managers!";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   914
        else
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   915
            err << strerror(errno);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   916
        throw MasterException(err.str());
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   917
    }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   918
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   919
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   920
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   921
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   922
void Master::getPdo(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   923
        ec_ioctl_pdo_t *pdo,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   924
        uint16_t slaveIndex,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   925
        uint8_t syncIndex,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   926
        uint8_t pdoPos
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   927
        )
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   928
{
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   929
    pdo->slave_position = slaveIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   930
    pdo->sync_index = syncIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   931
    pdo->pdo_pos = pdoPos;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   932
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   933
    if (ioctl(fd, EC_IOCTL_PDO, pdo)) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   934
        stringstream err;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   935
        err << "Failed to get Pdo: ";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   936
        if (errno == EINVAL)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   937
            err << "Either slave " << slaveIndex << " does not exist, "
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   938
                << "or it contains less than " << (unsigned int) syncIndex + 1
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   939
                << " sync managers, or sync manager "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   940
                << (unsigned int) syncIndex << " contains less than "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   941
                << pdoPos + 1 << " Pdos!" << endl;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   942
        else
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   943
            err << strerror(errno);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   944
        throw MasterException(err.str());
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   945
    }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   946
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   947
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   948
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   949
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   950
void Master::getPdoEntry(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   951
        ec_ioctl_pdo_entry_t *entry,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   952
        uint16_t slaveIndex,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   953
        uint8_t syncIndex,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   954
        uint8_t pdoPos,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   955
        uint8_t entryPos
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   956
        )
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   957
{
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   958
    entry->slave_position = slaveIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   959
    entry->sync_index = syncIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   960
    entry->pdo_pos = pdoPos;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   961
    entry->entry_pos = entryPos;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   962
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   963
    if (ioctl(fd, EC_IOCTL_PDO_ENTRY, entry)) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   964
        stringstream err;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   965
        err << "Failed to get Pdo entry: ";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   966
        if (errno == EINVAL)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   967
            err << "Either slave " << slaveIndex << " does not exist, "
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   968
                << "or it contains less than " << (unsigned int) syncIndex + 1
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   969
                << " sync managers, or sync manager "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   970
                << (unsigned int) syncIndex << " contains less than "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   971
                << pdoPos + 1 << " Pdos, or the Pdo at position " << pdoPos
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   972
                << " contains less than " << (unsigned int) entryPos + 1
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   973
                << " entries!" << endl;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   974
        else
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   975
            err << strerror(errno);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   976
        throw MasterException(err.str());
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   977
    }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   978
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   979
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   980
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   981
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   982
void Master::getSdo(
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   983
        ec_ioctl_sdo_t *sdo,
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   984
        uint16_t slaveIndex,
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   985
        uint16_t sdoPosition
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   986
        )
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   987
{
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   988
    sdo->slave_position = slaveIndex;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   989
    sdo->sdo_position = sdoPosition;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   990
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   991
    if (ioctl(fd, EC_IOCTL_SDO, sdo)) {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   992
        stringstream err;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   993
        err << "Failed to get Sdo: ";
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   994
        if (errno == EINVAL)
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   995
            err << "Either slave " << slaveIndex << " does not exist, "
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   996
                << "or it contains less than " << sdoPosition + 1 << " Sdos!"
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   997
                << endl;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   998
        else
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   999
            err << strerror(errno);
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1000
        throw MasterException(err.str());
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1001
    }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1002
}
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1003
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1004
/****************************************************************************/
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1005
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1006
void Master::getSdoEntry(
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1007
        ec_ioctl_sdo_entry_t *entry,
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1008
        uint16_t slaveIndex,
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1009
        int sdoSpec,
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1010
        uint8_t entrySubindex
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1011
        )
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1012
{
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1013
    entry->slave_position = slaveIndex;
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1014
    entry->sdo_spec = sdoSpec;
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1015
    entry->sdo_entry_subindex = entrySubindex;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1016
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1017
    if (ioctl(fd, EC_IOCTL_SDO_ENTRY, entry)) {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1018
        stringstream err;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1019
        err << "Failed to get Sdo entry: ";
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1020
        err << strerror(errno);
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1021
        throw MasterException(err.str());
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1022
    }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1023
}
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1024
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1025
/****************************************************************************/
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1026
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1027
void Master::requestState(
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1028
        uint16_t slavePosition,
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1029
        uint8_t state
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1030
        )
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1031
{
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1032
    ec_ioctl_slave_state_t data;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1033
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1034
    data.slave_position = slavePosition;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1035
    data.requested_state = state;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1036
    
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1037
    if (ioctl(fd, EC_IOCTL_SLAVE_STATE, &data)) {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1038
        stringstream err;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1039
        err << "Failed to request slave state: ";
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1040
        if (errno == EINVAL)
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1041
            err << "Slave " << slavePosition << " does not exist!";
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1042
        else
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1043
            err << strerror(errno);
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1044
        throw MasterException(err.str());
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1045
    }
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1046
}
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1047
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1048
/****************************************************************************/
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1049
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1050
string Master::slaveState(uint8_t state)
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1051
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1052
    switch (state) {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1053
        case 1: return "INIT";
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1054
        case 2: return "PREOP";
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1055
        case 4: return "SAFEOP";
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1056
        case 8: return "OP";
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1057
        default: return "???";
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1058
    }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1059
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1060
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1061
/****************************************************************************/
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1062
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1063
void Master::printRawData(
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1064
        const uint8_t *data,
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1065
        unsigned int size)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1066
{
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1067
    cout << hex << setfill('0');
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1068
    while (size--) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1069
        cout << "0x" << setw(2) << (unsigned int) *data++;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1070
        if (size)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1071
            cout << " ";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1072
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1073
    cout << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1074
}
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1075
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1076
/****************************************************************************/