tools/Master.cpp
author Florian Pose <fp@igh-essen.com>
Thu, 12 Jun 2008 07:32:05 +0000
changeset 994 e29edcced328
parent 990 4f223f3df05a
child 1001 a8eab75aa8e3
permissions -rw-r--r--
Clear domains before slave configs, because domain references the FMMU
configurations.
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>
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
    16
#include <fstream>
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
    17
#include <cctype> // toupper()
988
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
    18
#include <list>
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
using namespace std;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
#include "Master.h"
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
974
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    23
#define swap16(x) \
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    24
        ((uint16_t)( \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    25
        (((uint16_t)(x) & 0x00ffU) << 8) | \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    26
        (((uint16_t)(x) & 0xff00U) >> 8) ))
974
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    27
#define swap32(x) \
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    28
        ((uint32_t)( \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    29
        (((uint32_t)(x) & 0x000000ffUL) << 24) | \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    30
        (((uint32_t)(x) & 0x0000ff00UL) <<  8) | \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    31
        (((uint32_t)(x) & 0x00ff0000UL) >>  8) | \
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    32
        (((uint32_t)(x) & 0xff000000UL) >> 24) ))
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    33
974
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    34
#if __BYTE_ORDER == __LITTLE_ENDIAN
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    35
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    36
#define le16tocpu(x) x
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    37
#define le32tocpu(x) x
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    38
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    39
#define cputole16(x) x
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    40
#define cputole32(x) x
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    41
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    42
#elif __BYTE_ORDER == __BIG_ENDIAN
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    43
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    44
#define le16tocpu(x) swap16(x)
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    45
#define le32tocpu(x) swap32(x)
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    46
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    47
#define cputole16(x) swap16(x)
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    48
#define cputole32(x) swap32(x)
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
    49
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    50
#endif
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    51
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    52
/****************************************************************************/
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    53
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    54
struct CoEDataType {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    55
    const char *name;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    56
    uint16_t coeCode;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    57
    unsigned int byteSize;
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
static const CoEDataType dataTypes[] = {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    61
    {"int8",   0x0002, 1},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    62
    {"int16",  0x0003, 2},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    63
    {"int32",  0x0004, 4},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    64
    {"uint8",  0x0005, 1},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    65
    {"uint16", 0x0006, 2},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    66
    {"uint32", 0x0007, 4},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    67
    {"string", 0x0009, 0},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    68
    {"raw",    0xffff, 0},
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    69
    {}
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
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
const CoEDataType *findDataType(const string &str)
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 *d;
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
    for (d = dataTypes; d->name; d++)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    79
        if (str == d->name)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    80
            return d;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    81
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    82
    return NULL;
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
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
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    87
const CoEDataType *findDataType(uint16_t code)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    88
{
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    89
    const CoEDataType *d;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    90
    
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    91
    for (d = dataTypes; d->name; d++)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    92
        if (code == d->coeCode)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    93
            return d;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    94
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    95
    return NULL;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    96
}
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
    97
922
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
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
Master::Master()
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
    index = 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    fd = -1;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
}
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
/****************************************************************************/
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::~Master()
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
    close();
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
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
/****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   115
void Master::setIndex(unsigned int i)
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   116
{
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   117
    index = i;
922
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
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   120
/*****************************************************************************/
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   121
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   122
/**
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   123
 * Writes the Secondary slave address (alias) to the slave's SII.
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   124
 */
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   125
void Master::writeAlias(
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   126
        int slavePosition,
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   127
        bool force,
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   128
        const vector<string> &commandArgs
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   129
        )
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   130
{
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   131
    ec_ioctl_sii_t data;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   132
    ec_ioctl_slave_t slave;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   133
    unsigned int i;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   134
    uint16_t alias;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   135
    stringstream err, strAlias;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   136
    int number;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   137
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   138
    if (commandArgs.size() != 1) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   139
        stringstream err;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   140
        err << "'alias' takes exactly one argument!";
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   141
        throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   142
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   143
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   144
    strAlias << commandArgs[0];
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   145
    strAlias >> hex >> number;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   146
    if (strAlias.fail() || number < 0x0000 || number > 0xffff) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   147
        err << "Invalid alias '" << commandArgs[0] << "'!";
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   148
        throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   149
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   150
    alias = number;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   151
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   152
    if (slavePosition == -1) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   153
        unsigned int numSlaves, i;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   154
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   155
        if (!force) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   156
            err << "This will write the alias addresses of all slaves to 0x"
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   157
                << hex << setfill('0') << setw(4) << alias << "! "
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   158
                << "Please specify --force to proceed.";
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   159
            throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   160
        }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   161
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   162
        open(ReadWrite);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   163
        numSlaves = slaveCount();
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   164
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   165
        for (i = 0; i < numSlaves; i++) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   166
            writeSlaveAlias(i, alias);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   167
        }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   168
    } else {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   169
        open(ReadWrite);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   170
        writeSlaveAlias(slavePosition, alias);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   171
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   172
}
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   173
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   174
/*****************************************************************************/
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   175
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   176
/**
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   177
 * Lists the bus configuration.
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   178
 */
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   179
void Master::showConfig()
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   180
{
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   181
    ec_ioctl_master_t master;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   182
    unsigned int i, j, k, l;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   183
    ec_ioctl_config_t config;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   184
    ec_ioctl_config_pdo_t pdo;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   185
    ec_ioctl_config_pdo_entry_t entry;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   186
    ec_ioctl_config_sdo_t sdo;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   187
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   188
    open(Read);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   189
    getMaster(&master);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   190
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   191
    for (i = 0; i < master.config_count; i++) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   192
        getConfig(&config, i);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   193
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   194
        cout << "Alias: 0x"
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   195
            << hex << setfill('0') << setw(4) << config.alias << endl
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   196
            << "Position: " << dec << config.position << endl
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   197
            << "Vendor Id: 0x"
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   198
            << hex << setw(8) << config.vendor_id << endl
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   199
            << "Product code: 0x"
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   200
            << hex << setw(8) << config.product_code << endl
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   201
            << "Attached: " << (config.attached ? "yes" : "no") << endl;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   202
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   203
        for (j = 0; j < 2; j++) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   204
            if (config.pdo_count[j]) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   205
                cout << (j ? "Input" : "Output")
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   206
                    << " Pdo assignment / mapping " << endl;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   207
                for (k = 0; k < config.pdo_count[j]; k++) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   208
                    getConfigPdo(&pdo, i, j, k);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   209
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   210
                    cout << "  Pdo 0x"
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   211
                        << hex << setfill('0') << setw(4) << pdo.index
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   212
                        << " \"" << pdo.name << "\"" << endl;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   213
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   214
                    for (l = 0; l < pdo.entry_count; l++) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   215
                        getConfigPdoEntry(&entry, i, j, k, l);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   216
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   217
                        cout << "    Pdo entry 0x"
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   218
                            << hex << setfill('0') << setw(4) << entry.index
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   219
                            << ":" << setw(2) << (unsigned int) entry.subindex
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   220
                            << ", " << dec << (unsigned int) entry.bit_length
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   221
                            << " bit, \"" << entry.name << "\"" << endl;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   222
                    }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   223
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   224
            }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   225
        }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   226
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   227
        if (config.sdo_count) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   228
            cout << "Sdo configuration:" << endl;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   229
            for (j = 0; j < config.sdo_count; j++) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   230
                getConfigSdo(&sdo, i, j);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   231
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   232
                cout << "  0x"
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   233
                    << hex << setfill('0') << setw(4) << sdo.index
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   234
                    << ":" << setw(2) << (unsigned int) sdo.subindex
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   235
                    << ", " << sdo.size << " byte: " << hex;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   236
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   237
                switch (sdo.size) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   238
                    case 1:
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   239
                        cout << "0x" << setw(2)
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   240
                            << (unsigned int) *(uint8_t *) &sdo.data;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   241
                        break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   242
                    case 2:
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   243
                        cout << "0x" << setw(4)
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   244
                            << le16tocpu(*(uint16_t *) &sdo.data);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   245
                        break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   246
                    case 4:
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   247
                        cout << "0x" << setw(8)
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   248
                            << le32tocpu(*(uint32_t *) &sdo.data);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   249
                        break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   250
                    default:
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   251
                        cout << "???";
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   252
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   253
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   254
                cout << endl;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   255
            }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   256
        }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   257
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   258
        cout << endl;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   259
    }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   260
}
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   261
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
/****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   264
void Master::outputData(int domainIndex)
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   265
{
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   266
    open(Read);
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   267
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   268
    if (domainIndex == -1) {
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   269
        unsigned int numDomains = domainCount(), i;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   270
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   271
        for (i = 0; i < numDomains; i++) {
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   272
            outputDomainData(i);
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   273
        }
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   274
    } else {
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   275
        outputDomainData(domainIndex);
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   276
    }
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   277
}
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   278
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   279
/****************************************************************************/
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   280
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   281
void Master::setDebug(const vector<string> &commandArgs)
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   282
{
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   283
    stringstream str;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   284
    int debugLevel;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   285
    
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   286
    if (commandArgs.size() != 1) {
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   287
        stringstream err;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   288
        err << "'debug' takes exactly one argument!";
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   289
        throw MasterException(err.str());
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   290
    }
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   291
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   292
    str << commandArgs[0];
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   293
    str >> debugLevel;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   294
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   295
    if (str.fail()) {
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   296
        stringstream err;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   297
        err << "Invalid debug level '" << commandArgs[0] << "'!";
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   298
        throw MasterException(err.str());
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   299
    }
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   300
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   301
    open(ReadWrite);
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   302
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   303
    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
   304
        stringstream err;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   305
        err << "Failed to set debug level: " << strerror(errno);
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   306
        throw MasterException(err.str());
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   307
    }
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   308
}
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   309
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   310
/****************************************************************************/
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 951
diff changeset
   311
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   312
void Master::showDomains(int domainIndex)
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   313
{
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   314
    open(Read);
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   315
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   316
    if (domainIndex == -1) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   317
        unsigned int numDomains = domainCount(), i;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   318
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   319
        for (i = 0; i < numDomains; i++) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   320
            showDomain(i);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   321
        }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   322
    } else {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   323
        showDomain(domainIndex);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   324
    }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   325
}
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   326
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   327
/****************************************************************************/
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   328
988
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   329
struct SlaveInfo {
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   330
    string pos;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   331
    string alias;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   332
    string relPos;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   333
    string state;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   334
    string flag;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   335
    string name;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   336
};
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   337
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
void Master::listSlaves()
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
{
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   340
    unsigned int numSlaves, i;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   341
    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
   342
    uint16_t lastAlias, aliasIndex;
988
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   343
    SlaveInfo slaveInfo;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   344
    typedef list<SlaveInfo> SlaveInfoList;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   345
    SlaveInfoList slaveInfoList;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   346
    SlaveInfoList::const_iterator iter;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   347
    stringstream str;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   348
    unsigned int maxPosWidth = 0, maxAliasWidth = 0,
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   349
                 maxRelPosWidth = 0, maxStateWidth = 0;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
    
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   351
    open(Read);
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   352
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   353
    numSlaves = slaveCount();
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   354
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
    lastAlias = 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
    aliasIndex = 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
    for (i = 0; i < numSlaves; i++) {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   358
        getSlave(&slave, i);
988
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   359
        
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   360
        str << dec << i;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   361
        slaveInfo.pos = str.str();
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   362
        str.clear();
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   363
        str.str("");
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   364
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   365
        if (slave.alias) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   366
            lastAlias = slave.alias;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   367
            aliasIndex = 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
        }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   369
        if (lastAlias) {
988
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   370
            str << "#" << hex << lastAlias;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   371
            slaveInfo.alias = str.str();
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   372
            str.str("");
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   373
            str << ":" << dec << aliasIndex;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   374
            slaveInfo.relPos = str.str();
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   375
            str.str("");
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   376
            aliasIndex++;
988
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   377
        } else {
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   378
            slaveInfo.alias = "";
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   379
            slaveInfo.relPos = "";
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   380
        }
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   381
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   382
        slaveInfo.state = slaveState(slave.state);
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   383
        slaveInfo.flag = (slave.error_flag ? 'E' : '+');
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   384
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   385
        if (strlen(slave.name)) {
988
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   386
            slaveInfo.name = slave.name;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   387
        } else {
988
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   388
            str << hex << setfill('0')
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   389
                << setw(8) << slave.vendor_id << ":"
988
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   390
                << setw(8) << slave.product_code;
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   391
            slaveInfo.name = str.str();
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   392
            str.str("");
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   393
        }
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   394
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   395
        slaveInfoList.push_back(slaveInfo);
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   396
        if (slaveInfo.pos.length() > maxPosWidth)
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   397
            maxPosWidth = slaveInfo.pos.length();
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   398
        if (slaveInfo.alias.length() > maxAliasWidth)
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   399
            maxAliasWidth = slaveInfo.alias.length();
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   400
        if (slaveInfo.relPos.length() > maxRelPosWidth)
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   401
            maxRelPosWidth = slaveInfo.relPos.length();
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   402
        if (slaveInfo.state.length() > maxStateWidth)
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   403
            maxStateWidth = slaveInfo.state.length();
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   404
    }
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   405
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   406
    for (iter = slaveInfoList.begin(); iter != slaveInfoList.end(); iter++) {
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   407
        cout << setfill(' ') << right
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   408
            << setw(maxPosWidth) << iter->pos << "  "
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   409
            << setw(maxAliasWidth) << iter->alias
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   410
            << left
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   411
            << setw(maxRelPosWidth) << iter->relPos << "  "
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   412
            << setw(maxStateWidth) << iter->state << "  "
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   413
            << iter->flag << "  "
a47c5a3c143d Improved 'ethercat ls' formatting.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   414
            << iter->name << endl;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   415
    }
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   416
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   417
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   418
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   419
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   420
void Master::showMaster()
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   421
{
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   422
    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
   423
    stringstream err;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   424
    unsigned int i;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   425
    
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   426
    open(Read);
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   427
    getMaster(&data);
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   428
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   429
    cout
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   430
        << "Master" << index << endl
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   431
        << "  State: ";
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   432
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   433
    switch (data.mode) {
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   434
        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
   435
        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
   436
        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
   437
        default:
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   438
                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
   439
                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
   440
    }
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   441
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   442
    cout << endl
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   443
        << "  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
   444
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   445
    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
   446
        cout << "  Device" << i << ": ";
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   447
        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
   448
                && 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
   449
                && 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
   450
                && 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
   451
                && 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
   452
                && 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
   453
            cout << "None.";
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   454
        } else {
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   455
            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
   456
                << 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
   457
                << 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
   458
                << 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
   459
                << 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
   460
                << 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
   461
                << 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
   462
                << (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
   463
                << ")" << endl << dec
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   464
                << "    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
   465
                << "    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
   466
        }
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   467
        cout << endl;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   468
    }
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   469
}
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   470
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   471
/****************************************************************************/
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   472
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   473
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
   474
{
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   475
    open(Read);
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   476
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   477
    if (slavePosition == -1) {
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   478
        unsigned int numSlaves = slaveCount(), i;
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   479
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   480
        for (i = 0; i < numSlaves; i++) {
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   481
            listSlavePdos(i, quiet, true);
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   482
        }
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   483
    } else {
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   484
        listSlavePdos(slavePosition, quiet, false);
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   485
    }
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   486
}
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   487
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   488
/****************************************************************************/
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   489
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   490
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
   491
{
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   492
    open(Read);
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   493
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   494
    if (slavePosition == -1) {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   495
        unsigned int numSlaves = slaveCount(), i;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   496
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   497
        for (i = 0; i < numSlaves; i++) {
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   498
            listSlaveSdos(i, quiet, true);
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   499
        }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   500
    } else {
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   501
        listSlaveSdos(slavePosition, quiet, false);
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   502
    }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   503
}
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   504
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   505
/****************************************************************************/
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   506
974
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   507
void Master::sdoDownload(
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   508
        int slavePosition,
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   509
        const string &dataTypeStr,
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   510
        const vector<string> &commandArgs
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   511
        )
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   512
{
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   513
    stringstream strIndex, strSubIndex, strValue, err;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   514
    int number, sval;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   515
    ec_ioctl_sdo_download_t data;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   516
    unsigned int i, uval;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   517
    const CoEDataType *dataType = NULL;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   518
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   519
    if (slavePosition < 0) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   520
        err << "'sdo_download' requires a slave! Please specify --slave.";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   521
        throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   522
    }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   523
    data.slave_position = slavePosition;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   524
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   525
    if (commandArgs.size() != 3) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   526
        err << "'sdo_download' takes 3 arguments!";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   527
        throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   528
    }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   529
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   530
    strIndex << commandArgs[0];
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   531
    strIndex >> hex >> number;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   532
    if (strIndex.fail() || number < 0x0000 || number > 0xffff) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   533
        err << "Invalid Sdo index '" << commandArgs[0] << "'!";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   534
        throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   535
    }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   536
    data.sdo_index = number;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   537
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   538
    strSubIndex << commandArgs[1];
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   539
    strSubIndex >> hex >> number;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   540
    if (strSubIndex.fail() || number < 0x00 || number > 0xff) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   541
        err << "Invalid Sdo subindex '" << commandArgs[1] << "'!";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   542
        throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   543
    }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   544
    data.sdo_entry_subindex = number;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   545
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   546
    if (dataTypeStr != "") { // data type specified
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   547
        if (!(dataType = findDataType(dataTypeStr))) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   548
            err << "Invalid data type '" << dataTypeStr << "'!";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   549
            throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   550
        }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   551
    } else { // no data type specified: fetch from dictionary
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   552
        ec_ioctl_sdo_entry_t entry;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   553
        unsigned int entryByteSize;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   554
982
861eb2810f56 Open device with correct permissions immediately.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
   555
        open(ReadWrite);
974
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   556
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   557
        try {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   558
            getSdoEntry(&entry, slavePosition,
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   559
                    data.sdo_index, data.sdo_entry_subindex);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   560
        } catch (MasterException &e) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   561
            err << "Failed to determine Sdo entry data type. "
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   562
                << "Please specify --type.";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   563
            throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   564
        }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   565
        if (!(dataType = findDataType(entry.data_type))) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   566
            err << "Pdo entry has unknown data type 0x"
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   567
                << hex << setfill('0') << setw(4) << entry.data_type << "!"
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   568
                << " Please specify --type.";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   569
            throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   570
        }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   571
    }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   572
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   573
    if (dataType->byteSize) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   574
        data.data_size = dataType->byteSize;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   575
    } else {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   576
        data.data_size = DefaultBufferSize;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   577
    }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   578
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   579
    data.data = new uint8_t[data.data_size + 1];
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   580
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   581
    strValue << commandArgs[2];
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   582
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   583
    switch (dataType->coeCode) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   584
        case 0x0002: // int8
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   585
            strValue >> sval;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   586
            if ((uint32_t) sval > 0xff) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   587
                delete [] data.data;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   588
                err << "Invalid value for type '"
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   589
                    << dataType->name << "'!";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   590
                throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   591
            }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   592
            *data.data = (int8_t) sval;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   593
            break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   594
        case 0x0003: // int16
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   595
            strValue >> sval;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   596
            if ((uint32_t) sval > 0xffff) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   597
                delete [] data.data;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   598
                err << "Invalid value for type '"
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   599
                    << dataType->name << "'!";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   600
                throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   601
            }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   602
            *(int16_t *) data.data = cputole16(sval);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   603
            break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   604
        case 0x0004: // int32
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   605
            strValue >> sval;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   606
            *(int32_t *) data.data = cputole32(sval);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   607
            break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   608
        case 0x0005: // uint8
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   609
            strValue >> uval;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   610
            if ((uint32_t) uval > 0xff) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   611
                delete [] data.data;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   612
                err << "Invalid value for type '"
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   613
                    << dataType->name << "'!";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   614
                throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   615
            }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   616
            *data.data = (uint8_t) uval;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   617
            break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   618
        case 0x0006: // uint16
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   619
            strValue >> uval;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   620
            if ((uint32_t) uval > 0xffff) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   621
                delete [] data.data;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   622
                err << "Invalid value for type '"
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   623
                    << dataType->name << "'!";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   624
                throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   625
            }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   626
            *(uint16_t *) data.data = cputole16(uval);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   627
            break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   628
        case 0x0007: // uint32
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   629
            strValue >> uval;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   630
            *(uint32_t *) data.data = cputole32(uval);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   631
            break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   632
        case 0x0009: // string
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   633
            if (strValue.str().size() >= data.data_size) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   634
                err << "String too big";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   635
                throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   636
            }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   637
            data.data_size = strValue.str().size();
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   638
            strValue >> (char *) data.data;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   639
            break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   640
        default:
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   641
            break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   642
    }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   643
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   644
    if (strValue.fail()) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   645
        err << "Invalid value argument '" << commandArgs[2] << "'!";
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   646
        throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   647
    }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   648
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   649
    open(ReadWrite);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   650
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   651
    if (ioctl(fd, EC_IOCTL_SDO_DOWNLOAD, &data) < 0) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   652
        stringstream err;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   653
        err << "Failed to download Sdo: " << strerror(errno);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   654
        delete [] data.data;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   655
        throw MasterException(err.str());
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   656
    }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   657
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   658
    delete [] data.data;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   659
}
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   660
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   661
/****************************************************************************/
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   662
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   663
void Master::sdoUpload(
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   664
        int slavePosition,
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   665
        const string &dataTypeStr,
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   666
        const vector<string> &commandArgs
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   667
        )
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   668
{
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   669
    stringstream strIndex, strSubIndex;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   670
    int number, sval;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   671
    ec_ioctl_sdo_upload_t data;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   672
    unsigned int i, uval;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   673
    const CoEDataType *dataType = NULL;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   674
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   675
    if (slavePosition < 0) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   676
        stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   677
        err << "'sdo_upload' requires a slave! Please specify --slave.";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   678
        throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   679
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   680
    data.slave_position = slavePosition;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   681
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   682
    if (commandArgs.size() != 2) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   683
        stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   684
        err << "'sdo_upload' takes two arguments!";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   685
        throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   686
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   687
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   688
    strIndex << commandArgs[0];
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   689
    strIndex >> hex >> number;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   690
    if (strIndex.fail() || number < 0x0000 || number > 0xffff) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   691
        stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   692
        err << "Invalid Sdo index '" << commandArgs[0] << "'!";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   693
        throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   694
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   695
    data.sdo_index = number;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   696
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   697
    strSubIndex << commandArgs[1];
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   698
    strSubIndex >> hex >> number;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   699
    if (strSubIndex.fail() || number < 0x00 || number > 0xff) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   700
        stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   701
        err << "Invalid Sdo subindex '" << commandArgs[1] << "'!";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   702
        throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   703
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   704
    data.sdo_entry_subindex = number;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   705
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   706
    if (dataTypeStr != "") { // data type specified
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   707
        if (!(dataType = findDataType(dataTypeStr))) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   708
            stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   709
            err << "Invalid data type '" << dataTypeStr << "'!";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   710
            throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   711
        }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   712
    } else { // no data type specified: fetch from dictionary
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   713
        ec_ioctl_sdo_entry_t entry;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   714
        unsigned int entryByteSize;
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   715
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   716
        open(Read);
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   717
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   718
        try {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   719
            getSdoEntry(&entry, slavePosition,
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   720
                    data.sdo_index, data.sdo_entry_subindex);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   721
        } catch (MasterException &e) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   722
            stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   723
            err << "Failed to determine Sdo entry data type. "
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   724
                << "Please specify --type.";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   725
            throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   726
        }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   727
        if (!(dataType = findDataType(entry.data_type))) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   728
            stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   729
            err << "Pdo entry has unknown data type 0x"
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   730
                << hex << setfill('0') << setw(4) << entry.data_type << "!"
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   731
                << " Please specify --type.";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   732
            throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   733
        }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   734
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   735
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   736
    if (dataType->byteSize) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   737
        data.target_size = dataType->byteSize;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   738
    } else {
974
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   739
        data.target_size = DefaultBufferSize;
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   740
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   741
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   742
    data.target = new uint8_t[data.target_size + 1];
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   743
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   744
    open(Read);
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   745
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   746
    if (ioctl(fd, EC_IOCTL_SDO_UPLOAD, &data) < 0) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   747
        stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   748
        err << "Failed to upload Sdo: " << strerror(errno);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   749
        delete [] data.target;
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   750
        close();
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   751
        throw MasterException(err.str());
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   752
    }
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   753
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   754
    close();
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   755
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   756
    if (dataType->byteSize && data.data_size != dataType->byteSize) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   757
        stringstream err;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   758
        err << "Data type mismatch. Expected " << dataType->name
970
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
   759
            << " with " << dataType->byteSize << " byte, but got "
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
   760
            << data.data_size << " byte.";
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   761
        throw MasterException(err.str());
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   762
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   763
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   764
    cout << setfill('0');
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   765
    switch (dataType->coeCode) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   766
        case 0x0002: // int8
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   767
            sval = *(int8_t *) data.target;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   768
            cout << sval << " 0x" << hex << setw(2) << sval << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   769
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   770
        case 0x0003: // int16
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   771
            sval = le16tocpu(*(int16_t *) data.target);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   772
            cout << sval << " 0x" << hex << setw(4) << sval << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   773
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   774
        case 0x0004: // int32
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   775
            sval = le32tocpu(*(int32_t *) data.target);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   776
            cout << sval << " 0x" << hex << setw(8) << sval << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   777
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   778
        case 0x0005: // uint8
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   779
            uval = (unsigned int) *(uint8_t *) data.target;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   780
            cout << uval << " 0x" << hex << setw(2) << uval << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   781
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   782
        case 0x0006: // uint16
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   783
            uval = le16tocpu(*(uint16_t *) data.target);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   784
            cout << uval << " 0x" << hex << setw(4) << uval << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   785
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   786
        case 0x0007: // uint32
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   787
            uval = le32tocpu(*(uint32_t *) data.target);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   788
            cout << uval << " 0x" << hex << setw(8) << uval << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   789
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   790
        case 0x0009: // string
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   791
            cout << string((const char *) data.target, data.data_size)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   792
                << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   793
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   794
        default:
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   795
            printRawData(data.target, data.data_size);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   796
            break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   797
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   798
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   799
    delete [] data.target;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   800
}
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   801
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   802
/****************************************************************************/
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
   803
989
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   804
void Master::showSlaves(int slavePosition)
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   805
{
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   806
    open(Read);
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   807
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   808
    if (slavePosition == -1) {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   809
        unsigned int numSlaves = slaveCount(), i;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   810
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   811
        for (i = 0; i < numSlaves; i++) {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   812
            showSlave(i);
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   813
        }
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   814
    } else {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   815
        showSlave(slavePosition);
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   816
    }
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   817
}
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   818
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   819
/****************************************************************************/
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
   820
978
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   821
void Master::siiRead(int slavePosition)
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   822
{
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   823
    ec_ioctl_sii_t data;
978
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   824
    ec_ioctl_slave_t slave;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   825
    unsigned int i;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   826
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   827
    if (slavePosition < 0) {
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   828
        stringstream err;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   829
        err << "'sii_read' requires a slave! Please specify --slave.";
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   830
        throw MasterException(err.str());
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   831
    }
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   832
    data.slave_position = slavePosition;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   833
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   834
    open(Read);
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   835
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   836
    getSlave(&slave, slavePosition);
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   837
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   838
    if (!slave.sii_nwords)
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   839
        return;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   840
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   841
    data.offset = 0;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   842
    data.nwords = slave.sii_nwords;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   843
    data.words = new uint16_t[data.nwords];
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   844
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   845
    if (ioctl(fd, EC_IOCTL_SII_READ, &data) < 0) {
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   846
        stringstream err;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   847
        delete [] data.words;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   848
        err << "Failed to read SII: " << strerror(errno);
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   849
        throw MasterException(err.str());
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   850
    }
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   851
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   852
    for (i = 0; i < data.nwords; i++) {
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   853
        uint16_t *w = data.words + i;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   854
        cout << *(uint8_t *) w << *((uint8_t *) w + 1);
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   855
    }
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   856
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   857
    delete [] data.words;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   858
}
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   859
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   860
/****************************************************************************/
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 976
diff changeset
   861
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   862
void Master::siiWrite(
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   863
        int slavePosition,
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   864
        bool force,
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   865
        const vector<string> &commandArgs
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   866
        )
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   867
{
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   868
    stringstream err;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   869
    ec_ioctl_sii_t data;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   870
    ifstream file;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   871
    unsigned int byte_size;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   872
    const uint16_t *categoryHeader;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   873
    uint16_t categoryType, categorySize;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   874
    uint8_t crc;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   875
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   876
    if (slavePosition < 0) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   877
        err << "'sii_write' requires a slave! Please specify --slave.";
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   878
        throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   879
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   880
    data.slave_position = slavePosition;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   881
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   882
    if (commandArgs.size() != 1) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   883
        err << "'ssi_write' takes exactly one argument!";
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   884
        throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   885
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   886
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   887
    file.open(commandArgs[0].c_str(), ifstream::in | ifstream::binary);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   888
    if (file.fail()) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   889
        err << "Failed to open '" << commandArgs[0] << "'!";
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   890
        throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   891
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   892
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   893
    // get length of file
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   894
    file.seekg(0, ios::end);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   895
    byte_size = file.tellg();
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   896
    file.seekg(0, ios::beg);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   897
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   898
    if (!byte_size || byte_size % 2) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   899
        stringstream err;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   900
        err << "Invalid file size! Must be non-zero and even.";
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   901
        throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   902
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   903
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   904
    data.nwords = byte_size / 2;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   905
    if (data.nwords < 0x0041 && !force) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   906
        err << "SII data too short (" << data.nwords << " words)! Mimimum is"
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   907
                " 40 fixed words + 1 delimiter. Use --force to write anyway.";
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   908
        throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   909
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   910
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   911
    // allocate buffer and read file into buffer
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   912
    data.words = new uint16_t[data.nwords];
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   913
    file.read((char *) data.words, byte_size);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   914
    file.close();
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   915
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   916
    if (!force) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   917
        // calculate checksum over words 0 to 6
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   918
        crc = calcSiiCrc((const uint8_t *) data.words, 14);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   919
        if (crc != ((const uint8_t *) data.words)[14]) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   920
            err << "CRC incorrect. Must be 0x"
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   921
                << hex << setfill('0') << setw(2) << (unsigned int) crc
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   922
                << ". Use --force to write anyway.";
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   923
            throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   924
        }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   925
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   926
        // cycle through categories to detect corruption
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   927
        categoryHeader = data.words + 0x0040;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   928
        categoryType = le16tocpu(*categoryHeader);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   929
        while (categoryType != 0xffff) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   930
            if (categoryHeader + 1 > data.words + data.nwords) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   931
                err << "SII data seem to be corrupted! "
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   932
                    << "Use --force to write anyway.";
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   933
                throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   934
            }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   935
            categorySize = le16tocpu(*(categoryHeader + 1));
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   936
            if (categoryHeader + categorySize + 2 > data.words + data.nwords) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   937
                err << "SII data seem to be corrupted! "
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   938
                    "Use --force to write anyway.";
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   939
                throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   940
            }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   941
            categoryHeader += categorySize + 2;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   942
            categoryType = le16tocpu(*categoryHeader);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   943
        }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   944
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   945
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   946
    // send data to master
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   947
    open(ReadWrite);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   948
    data.offset = 0;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   949
    if (ioctl(fd, EC_IOCTL_SII_WRITE, &data) < 0) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   950
        stringstream err;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   951
        err << "Failed to write SII: " << strerror(errno);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   952
        throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   953
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   954
}
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   955
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   956
/****************************************************************************/
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   957
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   958
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
   959
        int slavePosition,
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   960
        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
   961
        )
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   962
{
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   963
    string stateStr;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   964
    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
   965
    
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   966
    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
   967
        stringstream err;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   968
        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
   969
        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
   970
    }
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   971
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   972
    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
   973
    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
   974
            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
   975
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   976
    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
   977
        state = 0x01;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   978
    } 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
   979
        state = 0x02;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   980
    } 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
   981
        state = 0x04;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   982
    } 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
   983
        state = 0x08;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   984
    } else {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   985
        stringstream err;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   986
        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
   987
        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
   988
    }
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   989
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   990
    open(ReadWrite);
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
   991
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   992
    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
   993
        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
   994
        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
   995
            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
   996
    } else {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   997
        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
   998
    }
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   999
}
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1000
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1001
/****************************************************************************/
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1002
938
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1003
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
  1004
{
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1005
    open(Read);
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1006
938
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1007
    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
  1008
        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
  1009
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1010
        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
  1011
            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
  1012
        }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1013
    } else {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1014
        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
  1015
    }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1016
}
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1017
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1018
/****************************************************************************/
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1019
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1020
void Master::open(Permissions perm)
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1021
{
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1022
    stringstream deviceName;
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1023
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1024
    if (fd != -1) { // already open
982
861eb2810f56 Open device with correct permissions immediately.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
  1025
        return;
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1026
    }
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1027
    
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1028
    deviceName << "/dev/EtherCAT" << index;
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1029
    
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1030
    if ((fd = ::open(deviceName.str().c_str(),
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1031
                    perm == ReadWrite ? O_RDWR : O_RDONLY)) == -1) {
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1032
        stringstream err;
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1033
        err << "Failed to open master device " << deviceName.str() << ": "
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1034
            << strerror(errno);
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1035
        throw MasterException(err.str());
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1036
    }
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1037
}
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1038
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1039
/****************************************************************************/
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1040
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1041
void Master::close()
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1042
{
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1043
    if (fd == -1)
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1044
        return;
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1045
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1046
    ::close(fd);
982
861eb2810f56 Open device with correct permissions immediately.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
  1047
    fd = -1;
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1048
}
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1049
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1050
/*****************************************************************************/
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1051
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1052
/**
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1053
 * Writes the Secondary slave address (alias) to the slave's SII.
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1054
 */
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1055
void Master::writeSlaveAlias(
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1056
        uint16_t slavePosition,
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1057
        uint16_t alias
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1058
        )
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1059
{
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1060
    ec_ioctl_sii_t data;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1061
    ec_ioctl_slave_t slave;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1062
    stringstream err;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1063
    uint8_t crc;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1064
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1065
    open(ReadWrite);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1066
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1067
    getSlave(&slave, slavePosition);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1068
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1069
    if (slave.sii_nwords < 8) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1070
        err << "Current SII contents are too small to set an alias "
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1071
            << "(" << slave.sii_nwords << " words)!";
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1072
        throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1073
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1074
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1075
    data.slave_position = slavePosition;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1076
    data.offset = 0;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1077
    data.nwords = 8;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1078
    data.words = new uint16_t[data.nwords];
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1079
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1080
    // read first 8 SII words
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1081
    if (ioctl(fd, EC_IOCTL_SII_READ, &data) < 0) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1082
        delete [] data.words;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1083
        err << "Failed to read SII: " << strerror(errno);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1084
        throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1085
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1086
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1087
    // write new alias address in word 4
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1088
    data.words[4] = cputole16(alias);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1089
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1090
    // calculate checksum over words 0 to 6
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1091
    crc = calcSiiCrc((const uint8_t *) data.words, 14);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1092
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1093
    // write new checksum into first byte of word 7
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1094
    *(uint8_t *) (data.words + 7) = crc;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1095
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1096
    // write first 8 words with new alias and checksum
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1097
    if (ioctl(fd, EC_IOCTL_SII_WRITE, &data) < 0) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1098
        delete [] data.words;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1099
        err << "Failed to write SII: " << strerror(errno);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1100
        throw MasterException(err.str());
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1101
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1102
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1103
    delete [] data.words;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1104
}
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1105
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1106
/****************************************************************************/
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 970
diff changeset
  1107
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1108
void Master::outputDomainData(unsigned int domainIndex)
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1109
{
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1110
    ec_ioctl_domain_t domain;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1111
    ec_ioctl_data_t data;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1112
    unsigned char *processData;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1113
    unsigned int i;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1114
    
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1115
    getDomain(&domain, domainIndex);
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1116
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1117
    if (!domain.data_size)
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1118
        return;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1119
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1120
    processData = new unsigned char[domain.data_size];
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1121
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1122
    try {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1123
        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
  1124
    } catch (MasterException &e) {
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1125
        delete [] processData;
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1126
        throw e;
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1127
    }
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1128
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1129
    for (i = 0; i < data.data_size; i++)
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1130
        cout << processData[i];
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1131
    cout.flush();
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1132
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1133
    delete [] processData;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1134
}
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1135
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1136
/****************************************************************************/
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
  1137
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1138
void Master::showDomain(unsigned int domainIndex)
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1139
{
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1140
    ec_ioctl_domain_t domain;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1141
    unsigned char *processData;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1142
    ec_ioctl_data_t data;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1143
    unsigned int i, j;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1144
    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
  1145
    unsigned int dataOffset;
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1146
    
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1147
    getDomain(&domain, domainIndex);
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1148
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1149
	cout << "Domain" << domainIndex << ":"
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1150
		<< " LogBaseAddr 0x"
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1151
		<< 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
  1152
		<< ", Size " << dec << setfill(' ') << setw(3) << domain.data_size
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1153
		<< ", WorkingCounter "
951
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
  1154
		<< dec << domain.working_counter << "/"
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
  1155
        << 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
  1156
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1157
    if (!domain.data_size)
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1158
        return;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1159
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1160
    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
  1161
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1162
    try {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1163
        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
  1164
    } catch (MasterException &e) {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1165
        delete [] processData;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1166
        throw e;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1167
    }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1168
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1169
    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
  1170
        getFmmu(&fmmu, domainIndex, i);
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1171
951
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
  1172
        cout << "  SlaveConfig "
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
  1173
            << fmmu.slave_config_alias << ":" << fmmu.slave_config_position
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
  1174
            << ", Dir "
dc84a0af63da Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
  1175
            << 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
  1176
            << ", LogAddr 0x" 
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1177
            << 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
  1178
            << ", 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
  1179
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1180
        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
  1181
        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
  1182
            stringstream err;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1183
            err << "Fmmu information corrupted!";
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1184
            delete [] processData;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1185
            throw MasterException(err.str());
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1186
        }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1187
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1188
        cout << "    " << hex << setfill('0');
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1189
        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
  1190
            cout << setw(2)
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1191
                << (unsigned int) *(processData + dataOffset + j) << " ";
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1192
        }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1193
        cout << endl;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1194
    }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1195
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1196
    delete [] processData;
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1197
}
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1198
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1199
/****************************************************************************/
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1200
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1201
void Master::listSlavePdos(
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1202
        uint16_t slavePosition,
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1203
        bool quiet,
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1204
        bool withHeader
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1205
        )
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
  1206
{
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1207
    ec_ioctl_slave_t slave;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1208
    ec_ioctl_sync_t sync;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1209
    ec_ioctl_pdo_t pdo;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1210
    ec_ioctl_pdo_entry_t entry;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1211
    unsigned int i, j, k;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1212
    
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1213
    getSlave(&slave, slavePosition);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1214
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1215
    if (withHeader)
936
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
  1216
        cout << "=== Slave " << slavePosition << " ===" << endl;
30fddfce8db6 Added multi-slave support.
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
  1217
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1218
    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
  1219
        getSync(&sync, slavePosition, i);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1220
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1221
        cout << "SM" << i << ":"
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1222
            << " PhysAddr 0x"
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1223
            << 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
  1224
            << ", DefaultSize "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1225
            << dec << setfill(' ') << setw(4) << sync.default_size
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1226
            << ", ControlRegister 0x"
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1227
            << hex << setfill('0') << setw(2)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1228
            << (unsigned int) sync.control_register
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1229
            << ", Enable " << dec << (unsigned int) sync.enable
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1230
            << endl;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1231
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1232
        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
  1233
            getPdo(&pdo, slavePosition, i, j);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1234
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1235
            cout << "  " << (pdo.dir ? "T" : "R") << "xPdo 0x"
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1236
                << hex << setfill('0') << setw(4) << pdo.index
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1237
                << " \"" << pdo.name << "\"" << endl;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1238
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1239
            if (quiet)
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1240
                continue;
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1241
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1242
            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
  1243
                getPdoEntry(&entry, slavePosition, i, j, k);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1244
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1245
                cout << "    Pdo entry 0x"
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1246
                    << hex << setfill('0') << setw(4) << entry.index
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1247
                    << ":" << setw(2) << (unsigned int) entry.subindex
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1248
                    << ", " << dec << (unsigned int) entry.bit_length
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1249
                    << " bit, \"" << entry.name << "\"" << endl;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1250
            }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1251
        }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1252
    }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1253
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1254
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1255
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1256
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1257
void Master::listSlaveSdos(
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1258
        uint16_t slavePosition,
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1259
        bool quiet,
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1260
        bool withHeader
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1261
        )
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1262
{
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1263
    ec_ioctl_slave_t slave;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1264
    ec_ioctl_sdo_t sdo;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1265
    ec_ioctl_sdo_entry_t entry;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1266
    unsigned int i, j, k;
970
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1267
    const CoEDataType *d;
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1268
    
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1269
    getSlave(&slave, slavePosition);
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1270
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1271
    if (withHeader)
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1272
        cout << "=== Slave " << slavePosition << " ===" << endl;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1273
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1274
    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
  1275
        getSdo(&sdo, slavePosition, i);
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1276
970
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1277
        cout << "Sdo "
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1278
            << 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
  1279
            << ", \"" << sdo.name << "\"" << endl;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1280
966
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1281
        if (quiet)
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1282
            continue;
f1a7ea8a550a Added -q flag (quiet).
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
  1283
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1284
        for (j = 0; j <= sdo.max_subindex; j++) {
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1285
            getSdoEntry(&entry, slavePosition, -i, j);
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1286
983
efb947bd96f3 Output Sdo index at entry.
Florian Pose <fp@igh-essen.com>
parents: 982
diff changeset
  1287
            cout << "  " << hex << setfill('0')
efb947bd96f3 Output Sdo index at entry.
Florian Pose <fp@igh-essen.com>
parents: 982
diff changeset
  1288
                << setw(4) << sdo.sdo_index << ":" 
efb947bd96f3 Output Sdo index at entry.
Florian Pose <fp@igh-essen.com>
parents: 982
diff changeset
  1289
                << setw(2) << (unsigned int) entry.sdo_entry_subindex
970
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1290
                << ", ";
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1291
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1292
            if ((d = findDataType(entry.data_type))) {
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1293
                cout << d->name;
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1294
            } else {
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1295
                cout << "type " << setw(4) << entry.data_type;
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1296
            }
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1297
b7cbff36bc01 Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1298
            cout << ", " << dec << entry.bit_length << " bit, \""
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1299
                << entry.description << "\"" << endl;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1300
        }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1301
    }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1302
}
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1303
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1304
/****************************************************************************/
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1305
989
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1306
void Master::showSlave(uint16_t slavePosition)
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1307
{
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1308
    ec_ioctl_slave_t slave;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1309
    list<string> protoList;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1310
    list<string>::const_iterator protoIter;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1311
    
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1312
    getSlave(&slave, slavePosition);
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1313
        
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1314
    cout << "Slave " << dec << slavePosition << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1315
        << "Alias: 0x" << hex << setfill('0') << setw(4) << slave.alias << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1316
        << "State: " << slaveState(slave.state) << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1317
        << "Flag: " << (slave.error_flag ? 'E' : '+') << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1318
        << "Identity:" << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1319
        << "  Vendor Id: 0x"
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1320
        << hex << setfill('0') << setw(8) << slave.vendor_id << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1321
        << "  Product code: 0x"
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1322
        << setw(8) << slave.product_code << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1323
        << "  Revision number: 0x"
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1324
        << setw(8) << slave.revision_number << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1325
        << "  Serial number: 0x"
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1326
        << setw(8) << slave.serial_number << endl;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1327
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1328
    if (slave.mailbox_protocols) {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1329
        cout << "Mailboxes:" << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1330
        << "  RX: 0x"
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1331
        << hex << setw(4) << slave.rx_mailbox_offset << "/"
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1332
        << dec << slave.rx_mailbox_size
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1333
        << ", TX: 0x"
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1334
        << hex << setw(4) << slave.tx_mailbox_offset << "/"
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1335
        << dec << slave.tx_mailbox_size << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1336
        << "  Supported protocols: ";
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1337
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1338
        if (slave.mailbox_protocols & EC_MBOX_AOE) {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1339
            protoList.push_back("AoE");
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1340
        }
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1341
        if (slave.mailbox_protocols & EC_MBOX_EOE) {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1342
            protoList.push_back("EoE");
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1343
        }
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1344
        if (slave.mailbox_protocols & EC_MBOX_COE) {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1345
            protoList.push_back("CoE");
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1346
        }
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1347
        if (slave.mailbox_protocols & EC_MBOX_FOE) {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1348
            protoList.push_back("FoE");
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1349
        }
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1350
        if (slave.mailbox_protocols & EC_MBOX_SOE) {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1351
            protoList.push_back("SoE");
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1352
        }
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1353
        if (slave.mailbox_protocols & EC_MBOX_VOE) {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1354
            protoList.push_back("VoE");
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1355
        }
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1356
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1357
        for (protoIter = protoList.begin(); protoIter != protoList.end();
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1358
                protoIter++) {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1359
            if (protoIter != protoList.begin())
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1360
                cout << ", ";
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1361
            cout << *protoIter;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1362
        }
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1363
        cout << endl;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1364
    }
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1365
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1366
    if (slave.has_general_category) {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1367
        cout << "General:" << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1368
            << "  Name: " << slave.name << endl;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1369
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1370
        if (slave.mailbox_protocols & EC_MBOX_COE) {
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1371
            cout << "  CoE details:" << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1372
                << "    Enable Sdo: "
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1373
                << (slave.coe_details.enable_sdo ? "yes" : "no") << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1374
                << "    Enable Sdo Info: "
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1375
                << (slave.coe_details.enable_sdo_info ? "yes" : "no") << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1376
                << "    Enable Pdo Assign: "
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1377
                << (slave.coe_details.enable_pdo_assign
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1378
                        ? "yes" : "no") << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1379
                << "    Enable Pdo Configuration: "
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1380
                << (slave.coe_details.enable_pdo_configuration
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1381
                        ? "yes" : "no") << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1382
                << "    Enable Upload at startup: "
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1383
                << (slave.coe_details.enable_upload_at_startup
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1384
                        ? "yes" : "no") << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1385
                << "    Enable Sdo complete access: "
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1386
                << (slave.coe_details.enable_sdo_complete_access
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1387
                        ? "yes" : "no") << endl;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1388
        }
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1389
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1390
        cout << "  Flags:" << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1391
            << "    Enable SafeOp: "
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1392
            << (slave.general_flags.enable_safeop ? "yes" : "no") << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1393
            << "    Enable notLRW: "
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1394
            << (slave.general_flags.enable_not_lrw ? "yes" : "no") << endl
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1395
            << "  Current consumption: "
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1396
            << dec << slave.current_on_ebus << " mA" << endl;
989
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1397
    }
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1398
    cout << endl;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1399
}
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1400
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1401
/****************************************************************************/
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 988
diff changeset
  1402
938
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1403
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
  1404
{
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1405
    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
  1406
    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
  1407
    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
  1408
    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
  1409
    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
  1410
    
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1411
    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
  1412
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1413
    cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1414
        << "<?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
  1415
        << "  <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
  1416
        << "    <!-- 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
  1417
        << "    <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
  1418
        << "      <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
  1419
        << "    </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
  1420
        << "    <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
  1421
        << "      <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
  1422
        << "        <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
  1423
        << "          <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
  1424
        << 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
  1425
        << "\" 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
  1426
        << 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
  1427
        << "\"/>" << endl;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1428
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1429
    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
  1430
        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
  1431
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1432
        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
  1433
            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
  1434
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1435
            cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1436
                << "          <" << (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
  1437
                << "            <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
  1438
                << 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
  1439
                << "</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
  1440
                << "            <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
  1441
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1442
            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
  1443
                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
  1444
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1445
                cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1446
                    << "            <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
  1447
                    << "              <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
  1448
                    << 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
  1449
                    << "</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
  1450
                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
  1451
                    cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1452
                        << "              <SubIndex>"
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1453
                        << 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
  1454
                        << "</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
  1455
                
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1456
                cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1457
                    << "              <BitLen>"
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1458
                    << (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
  1459
                    << "</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
  1460
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1461
                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
  1462
                    cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1463
                        << "              <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
  1464
                        << "</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
  1465
                        << "              <DataType>";
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1466
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1467
                    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
  1468
                        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
  1469
                    } 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
  1470
                        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
  1471
                            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
  1472
                        else
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1473
                            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
  1474
                                << (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
  1475
                                << ")";
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1476
                    } else {
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1477
                        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
  1478
                            << (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
  1479
                    }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1480
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1481
                        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
  1482
                }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1483
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1484
                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
  1485
            }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1486
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1487
            cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1488
                << "          </" << (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
  1489
        }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1490
    }
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1491
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1492
    cout
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1493
        << "        </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
  1494
        << "     </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
  1495
        << "  </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
  1496
        << "</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
  1497
}
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1498
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1499
/****************************************************************************/
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 936
diff changeset
  1500
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1501
unsigned int Master::domainCount()
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1502
{
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1503
    int ret;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1504
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1505
    if ((ret = ioctl(fd, EC_IOCTL_DOMAIN_COUNT, 0)) < 0) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1506
        stringstream err;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1507
        err << "Failed to get number of domains: " << strerror(errno);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1508
        throw MasterException(err.str());
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1509
    }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1510
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1511
    return ret;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1512
}
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1513
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1514
/****************************************************************************/
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1515
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1516
unsigned int Master::slaveCount()
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1517
{
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
  1518
    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
  1519
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
  1520
    getMaster(&data);
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
  1521
    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
  1522
}
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
  1523
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
  1524
/****************************************************************************/
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
  1525
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
  1526
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
  1527
{
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
  1528
    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
  1529
        stringstream err;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
  1530
        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
  1531
        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
  1532
    }
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1533
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1534
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1535
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1536
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1537
void Master::getConfig(ec_ioctl_config_t *data, unsigned int index)
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1538
{
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1539
    data->config_index = index;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1540
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1541
    if (ioctl(fd, EC_IOCTL_CONFIG, data) < 0) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1542
        stringstream err;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1543
        err << "Failed to get slave configuration: " << strerror(errno);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1544
        throw MasterException(err.str());
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1545
    }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1546
}
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1547
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1548
/****************************************************************************/
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1549
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1550
void Master::getConfigPdo(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1551
        ec_ioctl_config_pdo_t *data,
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1552
        unsigned int index,
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1553
        unsigned int dir,
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1554
        unsigned int pdo_pos
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1555
        )
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1556
{
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1557
    data->config_index = index;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1558
    data->direction = dir;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1559
    data->pdo_pos = pdo_pos;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1560
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1561
    if (ioctl(fd, EC_IOCTL_CONFIG_PDO, data) < 0) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1562
        stringstream err;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1563
        err << "Failed to get slave config Pdo: " << strerror(errno);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1564
        throw MasterException(err.str());
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1565
    }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1566
}
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1567
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1568
/****************************************************************************/
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1569
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1570
void Master::getConfigPdoEntry(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1571
        ec_ioctl_config_pdo_entry_t *data,
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1572
        unsigned int index,
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1573
        unsigned int dir,
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1574
        unsigned int pdo_pos,
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1575
        unsigned int entry_pos
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1576
        )
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1577
{
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1578
    data->config_index = index;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1579
    data->direction = dir;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1580
    data->pdo_pos = pdo_pos;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1581
    data->entry_pos = entry_pos;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1582
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1583
    if (ioctl(fd, EC_IOCTL_CONFIG_PDO_ENTRY, data) < 0) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1584
        stringstream err;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1585
        err << "Failed to get slave config Pdo entry: " << strerror(errno);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1586
        throw MasterException(err.str());
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1587
    }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1588
}
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1589
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1590
/****************************************************************************/
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1591
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1592
void Master::getConfigSdo(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1593
        ec_ioctl_config_sdo_t *data,
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1594
        unsigned int index,
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1595
        unsigned int sdo_pos
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1596
        )
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1597
{
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1598
    data->config_index = index;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1599
    data->sdo_pos = sdo_pos;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1600
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1601
    if (ioctl(fd, EC_IOCTL_CONFIG_SDO, data) < 0) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1602
        stringstream err;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1603
        err << "Failed to get slave config Sdo: " << strerror(errno);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1604
        throw MasterException(err.str());
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1605
    }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1606
}
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1607
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1608
/****************************************************************************/
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1609
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1610
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
  1611
{
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1612
    data->index = index;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1613
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1614
    if (ioctl(fd, EC_IOCTL_DOMAIN, data)) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1615
        stringstream err;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1616
        err << "Failed to get domain: ";
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1617
        if (errno == EINVAL)
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1618
            err << "Domain " << index << " does not exist!";
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1619
        else
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1620
            err << strerror(errno);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1621
        throw MasterException(err.str());
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1622
    }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1623
}
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1624
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1625
/****************************************************************************/
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  1626
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1627
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
  1628
        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
  1629
{
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1630
    data->domain_index = domainIndex;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1631
    data->data_size = dataSize;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1632
    data->target = mem;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1633
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1634
    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
  1635
        stringstream err;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1636
        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
  1637
        throw MasterException(err.str());
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1638
    }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1639
}
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1640
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1641
/****************************************************************************/
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1642
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1643
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
  1644
{
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1645
    slave->position = slaveIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1646
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1647
    if (ioctl(fd, EC_IOCTL_SLAVE, slave)) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1648
        stringstream err;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1649
        err << "Failed to get slave: ";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1650
        if (errno == EINVAL)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1651
            err << "Slave " << slaveIndex << " does not exist!";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1652
        else
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1653
            err << strerror(errno);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1654
        throw MasterException(err.str());
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1655
    }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1656
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1657
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1658
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1659
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1660
void Master::getFmmu(
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1661
        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
  1662
        unsigned int domainIndex,
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1663
        unsigned int fmmuIndex
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1664
        )
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1665
{
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1666
    fmmu->domain_index = domainIndex;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1667
    fmmu->fmmu_index = fmmuIndex;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1668
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1669
    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
  1670
        stringstream err;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1671
        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
  1672
        if (errno == EINVAL)
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1673
            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
  1674
                << "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
  1675
                << " FMMus!";
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1676
        else
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1677
            err << strerror(errno);
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1678
        throw MasterException(err.str());
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1679
    }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1680
}
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1681
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1682
/****************************************************************************/
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  1683
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1684
void Master::getSync(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1685
        ec_ioctl_sync_t *sync,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1686
        uint16_t slaveIndex,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1687
        uint8_t syncIndex
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1688
        )
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1689
{
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1690
    sync->slave_position = slaveIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1691
    sync->sync_index = syncIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1692
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1693
    if (ioctl(fd, EC_IOCTL_SYNC, sync)) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1694
        stringstream err;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1695
        err << "Failed to get sync manager: ";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1696
        if (errno == EINVAL)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1697
            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
  1698
                << "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
  1699
                << " sync managers!";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1700
        else
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1701
            err << strerror(errno);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1702
        throw MasterException(err.str());
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1703
    }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1704
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1705
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1706
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1707
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1708
void Master::getPdo(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1709
        ec_ioctl_pdo_t *pdo,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1710
        uint16_t slaveIndex,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1711
        uint8_t syncIndex,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1712
        uint8_t pdoPos
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1713
        )
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1714
{
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1715
    pdo->slave_position = slaveIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1716
    pdo->sync_index = syncIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1717
    pdo->pdo_pos = pdoPos;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1718
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1719
    if (ioctl(fd, EC_IOCTL_PDO, pdo)) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1720
        stringstream err;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1721
        err << "Failed to get Pdo: ";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1722
        if (errno == EINVAL)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1723
            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
  1724
                << "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
  1725
                << " sync managers, or sync manager "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1726
                << (unsigned int) syncIndex << " contains less than "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1727
                << pdoPos + 1 << " Pdos!" << endl;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1728
        else
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1729
            err << strerror(errno);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1730
        throw MasterException(err.str());
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1731
    }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1732
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1733
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1734
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1735
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1736
void Master::getPdoEntry(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1737
        ec_ioctl_pdo_entry_t *entry,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1738
        uint16_t slaveIndex,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1739
        uint8_t syncIndex,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1740
        uint8_t pdoPos,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1741
        uint8_t entryPos
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1742
        )
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1743
{
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1744
    entry->slave_position = slaveIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1745
    entry->sync_index = syncIndex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1746
    entry->pdo_pos = pdoPos;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1747
    entry->entry_pos = entryPos;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1748
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1749
    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
  1750
        stringstream err;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1751
        err << "Failed to get Pdo entry: ";
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1752
        if (errno == EINVAL)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1753
            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
  1754
                << "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
  1755
                << " sync managers, or sync manager "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1756
                << (unsigned int) syncIndex << " contains less than "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1757
                << 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
  1758
                << " contains less than " << (unsigned int) entryPos + 1
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1759
                << " entries!" << endl;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1760
        else
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1761
            err << strerror(errno);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1762
        throw MasterException(err.str());
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1763
    }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1764
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1765
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1766
/****************************************************************************/
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1767
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1768
void Master::getSdo(
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1769
        ec_ioctl_sdo_t *sdo,
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1770
        uint16_t slaveIndex,
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1771
        uint16_t sdoPosition
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1772
        )
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1773
{
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1774
    sdo->slave_position = slaveIndex;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1775
    sdo->sdo_position = sdoPosition;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1776
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1777
    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
  1778
        stringstream err;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1779
        err << "Failed to get Sdo: ";
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1780
        if (errno == EINVAL)
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1781
            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
  1782
                << "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
  1783
                << endl;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1784
        else
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1785
            err << strerror(errno);
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1786
        throw MasterException(err.str());
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1787
    }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1788
}
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1789
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1790
/****************************************************************************/
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1791
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1792
void Master::getSdoEntry(
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1793
        ec_ioctl_sdo_entry_t *entry,
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1794
        uint16_t slaveIndex,
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1795
        int sdoSpec,
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1796
        uint8_t entrySubindex
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1797
        )
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1798
{
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1799
    entry->slave_position = slaveIndex;
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1800
    entry->sdo_spec = sdoSpec;
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1801
    entry->sdo_entry_subindex = entrySubindex;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1802
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1803
    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
  1804
        stringstream err;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1805
        err << "Failed to get Sdo entry: ";
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1806
        err << strerror(errno);
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1807
        throw MasterException(err.str());
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1808
    }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1809
}
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1810
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1811
/****************************************************************************/
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
  1812
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1813
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
  1814
        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
  1815
        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
  1816
        )
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1817
{
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1818
    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
  1819
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1820
    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
  1821
    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
  1822
    
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1823
    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
  1824
        stringstream err;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1825
        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
  1826
        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
  1827
            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
  1828
        else
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1829
            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
  1830
        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
  1831
    }
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1832
}
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1833
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1834
/****************************************************************************/
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  1835
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1836
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
  1837
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1838
    switch (state) {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1839
        case 1: return "INIT";
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1840
        case 2: return "PREOP";
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1841
        case 4: return "SAFEOP";
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1842
        case 8: return "OP";
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1843
        default: return "???";
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1844
    }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1845
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1846
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1847
/****************************************************************************/
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1848
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1849
void Master::printRawData(
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1850
        const uint8_t *data,
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1851
        unsigned int size)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1852
{
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1853
    cout << hex << setfill('0');
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1854
    while (size--) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1855
        cout << "0x" << setw(2) << (unsigned int) *data++;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1856
        if (size)
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1857
            cout << " ";
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1858
    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1859
    cout << endl;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1860
}
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 966
diff changeset
  1861
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1862
/*****************************************************************************/
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1863
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1864
/**
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1865
 * Calculates the SII checksum field.
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1866
 *
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1867
 * The checksum is generated with the polynom x^8+x^2+x+1 (0x07) and an
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1868
 * initial value of 0xff (see IEC 61158-6-12 ch. 5.4).
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1869
 *
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1870
 * The below code was originally generated with PYCRC
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1871
 * http://www.tty1.net/pycrc
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1872
 *
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1873
 * ./pycrc.py --width=8 --poly=0x07 --reflect-in=0 --xor-in=0xff
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1874
 *   --reflect-out=0 --xor-out=0 --generate c --algorithm=bit-by-bit
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1875
 *
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1876
 * \return CRC8
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1877
 */
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1878
uint8_t Master::calcSiiCrc(
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1879
        const uint8_t *data, /**< pointer to data */
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1880
        size_t length /**< number of bytes in \a data */
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1881
        )
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1882
{
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1883
    unsigned int i;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1884
    uint8_t bit, byte, crc = 0x48;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1885
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1886
    while (length--) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1887
        byte = *data++;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1888
        for (i = 0; i < 8; i++) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1889
            bit = crc & 0x80;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1890
            crc = (crc << 1) | ((byte >> (7 - i)) & 0x01);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1891
            if (bit) crc ^= 0x07;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1892
        }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1893
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1894
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1895
    for (i = 0; i < 8; i++) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1896
        bit = crc & 0x80;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1897
        crc <<= 1;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1898
        if (bit) crc ^= 0x07;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1899
    }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1900
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1901
    return crc;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1902
}
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1903
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
  1904
/*****************************************************************************/