tool/MasterDevice.cpp
author Florian Pose <fp@igh-essen.com>
Tue, 30 Sep 2008 07:34:55 +0000
changeset 1225 4d5b739edcb5
parent 1222 7348d6abb6cb
child 1238 02711963a059
permissions -rw-r--r--
Introduced ec_datagram_zero().
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 * $Id$
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 ****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#include <sys/stat.h>
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
#include <fcntl.h>
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
#include <errno.h>
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
#include <sys/ioctl.h>
1222
7348d6abb6cb Applied patch by Karsten Schwinne, adding a few header files necessary
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    11
#include <string.h>
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
#include <sstream>
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    14
#include <iomanip>
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
using namespace std;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
#include "MasterDevice.h"
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
MasterDevice::MasterDevice()
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
    index = 0;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
    fd = -1;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
MasterDevice::~MasterDevice()
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
    close();
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
void MasterDevice::setIndex(unsigned int i)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
    index = i;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
void MasterDevice::open(Permissions perm)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
    stringstream deviceName;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    47
    if (fd == -1) { // not already open
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    48
		deviceName << "/dev/EtherCAT" << index;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    49
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    50
		if ((fd = ::open(deviceName.str().c_str(),
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    51
						perm == ReadWrite ? O_RDWR : O_RDONLY)) == -1) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    52
			stringstream err;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    53
			err << "Failed to open master device " << deviceName.str() << ": "
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    54
				<< strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
    55
			throw MasterDeviceException(err);
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    56
		}
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
void MasterDevice::close()
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
{
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    64
    if (fd != -1) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    65
		::close(fd);
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    66
		fd = -1;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    67
	}
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    68
}
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
    69
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
void MasterDevice::getMaster(ec_ioctl_master_t *data)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    if (ioctl(fd, EC_IOCTL_MASTER, data) < 0) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
        stringstream err;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
        err << "Failed to get master information: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
    77
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
void MasterDevice::getConfig(ec_ioctl_config_t *data, unsigned int index)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
    data->config_index = index;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
    if (ioctl(fd, EC_IOCTL_CONFIG, data) < 0) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
        stringstream err;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
        err << "Failed to get slave configuration: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
    90
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
void MasterDevice::getConfigPdo(
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
        ec_ioctl_config_pdo_t *data,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
        unsigned int index,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
        uint8_t sync_index,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
        uint16_t pdo_pos
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
        )
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    data->config_index = index;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
    data->sync_index = sync_index;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    data->pdo_pos = pdo_pos;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
    if (ioctl(fd, EC_IOCTL_CONFIG_PDO, data) < 0) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
        stringstream err;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
        err << "Failed to get slave config Pdo: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   110
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
void MasterDevice::getConfigPdoEntry(
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
        ec_ioctl_config_pdo_entry_t *data,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
        unsigned int index,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
        uint8_t sync_index,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
        uint16_t pdo_pos,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
        uint8_t entry_pos
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
        )
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    data->config_index = index;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
    data->sync_index = sync_index;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    data->pdo_pos = pdo_pos;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    data->entry_pos = entry_pos;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
    if (ioctl(fd, EC_IOCTL_CONFIG_PDO_ENTRY, data) < 0) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
        stringstream err;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
        err << "Failed to get slave config Pdo entry: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   132
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
void MasterDevice::getConfigSdo(
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
        ec_ioctl_config_sdo_t *data,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
        unsigned int index,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
        unsigned int sdo_pos
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
        )
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
    data->config_index = index;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
    data->sdo_pos = sdo_pos;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
    if (ioctl(fd, EC_IOCTL_CONFIG_SDO, data) < 0) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
        stringstream err;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
        err << "Failed to get slave config Sdo: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   150
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
void MasterDevice::getDomain(ec_ioctl_domain_t *data, unsigned int index)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
    data->index = index;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
    if (ioctl(fd, EC_IOCTL_DOMAIN, data)) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
        stringstream err;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
        err << "Failed to get domain: ";
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
        if (errno == EINVAL)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
            err << "Domain " << index << " does not exist!";
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
        else
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
            err << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   167
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   173
void MasterDevice::getData(ec_ioctl_domain_data_t *data,
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   174
        unsigned int domainIndex, unsigned int dataSize, unsigned char *mem)
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
    data->domain_index = domainIndex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
    data->data_size = dataSize;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
    data->target = mem;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
    if (ioctl(fd, EC_IOCTL_DOMAIN_DATA, data) < 0) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
        stringstream err;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
        err << "Failed to get domain data: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   183
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
void MasterDevice::getSlave(ec_ioctl_slave_t *slave, uint16_t slaveIndex)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    slave->position = slaveIndex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
    if (ioctl(fd, EC_IOCTL_SLAVE, slave)) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
        stringstream err;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
        err << "Failed to get slave: ";
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
        if (errno == EINVAL)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
            err << "Slave " << slaveIndex << " does not exist!";
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
        else
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
            err << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   200
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
void MasterDevice::getFmmu(
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
        ec_ioctl_domain_fmmu_t *fmmu,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
        unsigned int domainIndex,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
        unsigned int fmmuIndex
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
        )
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
    fmmu->domain_index = domainIndex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
    fmmu->fmmu_index = fmmuIndex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
    if (ioctl(fd, EC_IOCTL_DOMAIN_FMMU, fmmu)) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
        stringstream err;
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   217
        err << "Failed to get domain FMMU: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   218
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
void MasterDevice::getSync(
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
        ec_ioctl_slave_sync_t *sync,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
        uint16_t slaveIndex,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
        uint8_t syncIndex
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
        )
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
    sync->slave_position = slaveIndex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
    sync->sync_index = syncIndex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
    if (ioctl(fd, EC_IOCTL_SLAVE_SYNC, sync)) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
        stringstream err;
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   235
        err << "Failed to get sync manager: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   236
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
void MasterDevice::getPdo(
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
        ec_ioctl_slave_sync_pdo_t *pdo,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
        uint16_t slaveIndex,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
        uint8_t syncIndex,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
        uint8_t pdoPos
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
        )
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
    pdo->slave_position = slaveIndex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
    pdo->sync_index = syncIndex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
    pdo->pdo_pos = pdoPos;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
    if (ioctl(fd, EC_IOCTL_SLAVE_SYNC_PDO, pdo)) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
        stringstream err;
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   255
        err << "Failed to get Pdo: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   256
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
void MasterDevice::getPdoEntry(
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
        ec_ioctl_slave_sync_pdo_entry_t *entry,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
        uint16_t slaveIndex,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
        uint8_t syncIndex,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
        uint8_t pdoPos,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
        uint8_t entryPos
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
        )
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
    entry->slave_position = slaveIndex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
    entry->sync_index = syncIndex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
    entry->pdo_pos = pdoPos;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
    entry->entry_pos = entryPos;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
    if (ioctl(fd, EC_IOCTL_SLAVE_SYNC_PDO_ENTRY, entry)) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
        stringstream err;
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   277
        err << "Failed to get Pdo entry: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   278
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
void MasterDevice::getSdo(
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
        ec_ioctl_slave_sdo_t *sdo,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
        uint16_t slaveIndex,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
        uint16_t sdoPosition
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
        )
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
    sdo->slave_position = slaveIndex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
    sdo->sdo_position = sdoPosition;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
    if (ioctl(fd, EC_IOCTL_SLAVE_SDO, sdo)) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
        stringstream err;
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   295
        err << "Failed to get Sdo: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   296
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
void MasterDevice::getSdoEntry(
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
        ec_ioctl_slave_sdo_entry_t *entry,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
        uint16_t slaveIndex,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
        int sdoSpec,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
        uint8_t entrySubindex
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
        )
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
    entry->slave_position = slaveIndex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
    entry->sdo_spec = sdoSpec;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
    entry->sdo_entry_subindex = entrySubindex;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
    if (ioctl(fd, EC_IOCTL_SLAVE_SDO_ENTRY, entry)) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
        stringstream err;
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   315
        err << "Failed to get Sdo entry: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   316
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   322
void MasterDevice::readSii(
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
        ec_ioctl_slave_sii_t *data
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
        )
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
    if (ioctl(fd, EC_IOCTL_SLAVE_SII_READ, data) < 0) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
        stringstream err;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   328
        err << "Failed to read SII: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   329
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   332
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   333
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
void MasterDevice::writeSii(
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   336
        ec_ioctl_slave_sii_t *data
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
        )
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
    if (ioctl(fd, EC_IOCTL_SLAVE_SII_WRITE, data) < 0) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
        stringstream err;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
        err << "Failed to write SII: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   342
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   344
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
/****************************************************************************/
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   348
void MasterDevice::readPhy(
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   349
        ec_ioctl_slave_phy_t *data
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   350
        )
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   351
{
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   352
    if (ioctl(fd, EC_IOCTL_SLAVE_PHY_READ, data) < 0) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   353
        stringstream err;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   354
        err << "Failed to read physical memory: " << strerror(errno);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   355
        throw MasterDeviceException(err);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   356
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   357
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   358
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   359
/****************************************************************************/
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   360
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   361
void MasterDevice::writePhy(
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   362
        ec_ioctl_slave_phy_t *data
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   363
        )
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   364
{
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   365
    if (ioctl(fd, EC_IOCTL_SLAVE_PHY_WRITE, data) < 0) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   366
        stringstream err;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   367
        err << "Failed to write physical memory: " << strerror(errno);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   368
        throw MasterDeviceException(err);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   369
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   370
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   371
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   372
/****************************************************************************/
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1184
diff changeset
   373
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   374
void MasterDevice::setDebug(unsigned int debugLevel)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   375
{
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   376
    if (ioctl(fd, EC_IOCTL_MASTER_DEBUG, debugLevel) < 0) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   377
        stringstream err;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   378
        err << "Failed to set debug level: " << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   379
        throw MasterDeviceException(err);
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   380
	}
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   381
}
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   382
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   383
/****************************************************************************/
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   384
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   385
void MasterDevice::sdoDownload(ec_ioctl_slave_sdo_download_t *data)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   386
{
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   387
    if (ioctl(fd, EC_IOCTL_SLAVE_SDO_DOWNLOAD, data) < 0) {
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   388
        stringstream err;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   389
        if (errno == EIO && data->abort_code) {
1184
75cd6681eb08 Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   390
            throw MasterDeviceSdoAbortException(data->abort_code);
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   391
        } else {
1184
75cd6681eb08 Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   392
            err << "Failed to download Sdo: " << strerror(errno);
75cd6681eb08 Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   393
            throw MasterDeviceException(err);
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   394
        }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   395
	}
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   396
}
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   397
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   398
/****************************************************************************/
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   399
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   400
void MasterDevice::sdoUpload(ec_ioctl_slave_sdo_upload_t *data)
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   401
{
1135
807ec6498502 Fixed sdoUpload().
Florian Pose <fp@igh-essen.com>
parents: 1126
diff changeset
   402
    if (ioctl(fd, EC_IOCTL_SLAVE_SDO_UPLOAD, data) < 0) {
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   403
        stringstream err;
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   404
        if (errno == EIO && data->abort_code) {
1184
75cd6681eb08 Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   405
            throw MasterDeviceSdoAbortException(data->abort_code);
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   406
        } else {
1184
75cd6681eb08 Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   407
            err << "Failed to upload Sdo: " << strerror(errno);
75cd6681eb08 Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents: 1160
diff changeset
   408
            throw MasterDeviceException(err);
1126
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   409
        }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   410
    }
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   411
}
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   412
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   413
/****************************************************************************/
b09fd81894cb Moved every command into a separate file.
Florian Pose <fp@igh-essen.com>
parents: 1122
diff changeset
   414
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   415
void MasterDevice::requestState(
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   416
        uint16_t slavePosition,
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   417
        uint8_t state
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   418
        )
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   419
{
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   420
    ec_ioctl_slave_state_t data;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   421
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   422
    data.slave_position = slavePosition;
1148
1762296870bd Renamed state field to al_state.
Florian Pose <fp@igh-essen.com>
parents: 1136
diff changeset
   423
    data.al_state = state;
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   424
    
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   425
    if (ioctl(fd, EC_IOCTL_SLAVE_STATE, &data)) {
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   426
        stringstream err;
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   427
        err << "Failed to request slave state: ";
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   428
        if (errno == EINVAL)
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   429
            err << "Slave " << slavePosition << " does not exist!";
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   430
        else
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
            err << strerror(errno);
1136
a0982873d655 Improved exceptions and commandName usage.
Florian Pose <fp@igh-essen.com>
parents: 1135
diff changeset
   432
        throw MasterDeviceException(err);
1122
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
    }
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   434
}
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   435
ee305a780a02 First step of moving to command list.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   436
/*****************************************************************************/