author | Florian Pose <fp@igh-essen.com> |
Tue, 08 Jul 2008 08:35:22 +0000 | |
changeset 1104 | 9e7fe258495e |
parent 1103 | b6998e916d5a |
child 1105 | 3552b4c46f10 |
permissions | -rw-r--r-- |
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; |
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
103 |
verbosity = Normal; |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
fd = -1; |
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 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
Master::~Master() |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
{ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
111 |
close(); |
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 |
/****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
|
972 | 116 |
void Master::setIndex(unsigned int i) |
117 |
{ |
|
118 |
index = i; |
|
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
|
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
121 |
/****************************************************************************/ |
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
122 |
|
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
123 |
void Master::setVerbosity(Verbosity v) |
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
124 |
{ |
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
125 |
verbosity = v; |
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
126 |
} |
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
127 |
|
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
128 |
/*****************************************************************************/ |
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 |
* 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
|
132 |
*/ |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
133 |
void Master::writeAlias( |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
134 |
int slavePosition, |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
135 |
bool force, |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
136 |
const vector<string> &commandArgs |
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 |
{ |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
139 |
uint16_t alias; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
140 |
stringstream err, strAlias; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
141 |
int number; |
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 |
if (commandArgs.size() != 1) { |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
144 |
stringstream err; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
145 |
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
|
146 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
147 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
148 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
149 |
strAlias << commandArgs[0]; |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
150 |
strAlias |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
151 |
>> resetiosflags(ios::basefield) // guess base from prefix |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
152 |
>> number; |
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
153 |
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
|
154 |
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
|
155 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
156 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
157 |
alias = number; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
158 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
159 |
if (slavePosition == -1) { |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
160 |
unsigned int numSlaves, i; |
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 |
if (!force) { |
1068 | 163 |
err << "This will write the alias addresses of all slaves to " |
164 |
<< alias << "! Please specify --force to proceed."; |
|
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
165 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
166 |
} |
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 |
open(ReadWrite); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
169 |
numSlaves = slaveCount(); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
170 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
171 |
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
|
172 |
writeSlaveAlias(i, alias); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
173 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
174 |
} else { |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
175 |
open(ReadWrite); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
176 |
writeSlaveAlias(slavePosition, alias); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
177 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
178 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
179 |
|
990
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 |
|
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
182 |
/** Lists the bus configuration. |
990
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
183 |
*/ |
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
184 |
void Master::showConfigs() |
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
185 |
{ |
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
186 |
if (verbosity == Verbose) { |
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
187 |
showDetailedConfigs(); |
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
188 |
} else { |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
189 |
listConfigs(); |
990
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 |
} |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
192 |
|
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
193 |
/****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
194 |
|
949
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
195 |
void Master::outputData(int domainIndex) |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
196 |
{ |
972 | 197 |
open(Read); |
198 |
||
949
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
199 |
if (domainIndex == -1) { |
1001
a8eab75aa8e3
Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents:
990
diff
changeset
|
200 |
unsigned int i; |
a8eab75aa8e3
Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents:
990
diff
changeset
|
201 |
ec_ioctl_master_t master; |
a8eab75aa8e3
Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents:
990
diff
changeset
|
202 |
|
a8eab75aa8e3
Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents:
990
diff
changeset
|
203 |
getMaster(&master); |
a8eab75aa8e3
Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents:
990
diff
changeset
|
204 |
|
a8eab75aa8e3
Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents:
990
diff
changeset
|
205 |
for (i = 0; i < master.domain_count; i++) { |
949
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
206 |
outputDomainData(i); |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
207 |
} |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
208 |
} else { |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
209 |
outputDomainData(domainIndex); |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
210 |
} |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
211 |
} |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
212 |
|
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
213 |
/****************************************************************************/ |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
214 |
|
956
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
215 |
void Master::setDebug(const vector<string> &commandArgs) |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
216 |
{ |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
217 |
stringstream str; |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
218 |
int debugLevel; |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
219 |
|
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
220 |
if (commandArgs.size() != 1) { |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
221 |
stringstream err; |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
222 |
err << "'debug' takes exactly one argument!"; |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
223 |
throw MasterException(err.str()); |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
224 |
} |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
225 |
|
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
226 |
str << commandArgs[0]; |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
227 |
str >> resetiosflags(ios::basefield) // guess base from prefix |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
228 |
>> debugLevel; |
956
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
229 |
|
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
230 |
if (str.fail()) { |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
231 |
stringstream err; |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
232 |
err << "Invalid debug level '" << commandArgs[0] << "'!"; |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
233 |
throw MasterException(err.str()); |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
234 |
} |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
235 |
|
972 | 236 |
open(ReadWrite); |
237 |
||
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
238 |
if (ioctl(fd, EC_IOCTL_MASTER_DEBUG, debugLevel) < 0) { |
956
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
239 |
stringstream err; |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
240 |
err << "Failed to set debug level: " << strerror(errno); |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
241 |
throw MasterException(err.str()); |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
242 |
} |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
243 |
} |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
244 |
|
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
245 |
/****************************************************************************/ |
d9b9bc794d10
Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents:
951
diff
changeset
|
246 |
|
948
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
247 |
void Master::showDomains(int domainIndex) |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
248 |
{ |
972 | 249 |
open(Read); |
250 |
||
948
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
251 |
if (domainIndex == -1) { |
1001
a8eab75aa8e3
Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents:
990
diff
changeset
|
252 |
unsigned int i; |
a8eab75aa8e3
Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents:
990
diff
changeset
|
253 |
ec_ioctl_master_t master; |
a8eab75aa8e3
Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents:
990
diff
changeset
|
254 |
|
a8eab75aa8e3
Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents:
990
diff
changeset
|
255 |
getMaster(&master); |
a8eab75aa8e3
Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents:
990
diff
changeset
|
256 |
|
a8eab75aa8e3
Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents:
990
diff
changeset
|
257 |
for (i = 0; i < master.domain_count; i++) { |
948
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
258 |
showDomain(i); |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
259 |
} |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
260 |
} else { |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
261 |
showDomain(domainIndex); |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
262 |
} |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
263 |
} |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
264 |
|
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
265 |
/****************************************************************************/ |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
266 |
|
957
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
267 |
void Master::showMaster() |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
268 |
{ |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
269 |
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
|
270 |
stringstream err; |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
271 |
unsigned int i; |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
272 |
|
972 | 273 |
open(Read); |
957
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
274 |
getMaster(&data); |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
275 |
|
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
276 |
cout |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
277 |
<< "Master" << index << endl |
1029
61ffe5f22306
Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents:
1001
diff
changeset
|
278 |
<< " Phase: "; |
61ffe5f22306
Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents:
1001
diff
changeset
|
279 |
|
61ffe5f22306
Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents:
1001
diff
changeset
|
280 |
switch (data.phase) { |
957
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
default: |
1029
61ffe5f22306
Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents:
1001
diff
changeset
|
285 |
err << "Invalid master phase " << data.phase; |
957
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
286 |
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
|
287 |
} |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
288 |
|
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
289 |
cout << endl |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
290 |
<< " 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
|
291 |
|
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
292 |
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
|
293 |
cout << " Device" << i << ": "; |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
294 |
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
|
295 |
&& 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
|
296 |
&& 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
|
297 |
&& 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
|
298 |
&& 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
|
299 |
&& 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
|
300 |
cout << "None."; |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
301 |
} else { |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
302 |
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
|
303 |
<< 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
|
304 |
<< 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
|
305 |
<< 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
|
306 |
<< 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
|
307 |
<< 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
|
308 |
<< 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
|
309 |
<< (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
|
310 |
<< ")" << endl << dec |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
311 |
<< " 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
|
312 |
<< " 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
|
313 |
} |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
314 |
cout << endl; |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
315 |
} |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
316 |
} |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
317 |
|
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
318 |
/****************************************************************************/ |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
319 |
|
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
320 |
void Master::listPdos(int slavePosition) |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
321 |
{ |
972 | 322 |
open(Read); |
323 |
||
936 | 324 |
if (slavePosition == -1) { |
325 |
unsigned int numSlaves = slaveCount(), i; |
|
326 |
||
327 |
for (i = 0; i < numSlaves; i++) { |
|
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
328 |
listSlavePdos(i, true); |
936 | 329 |
} |
330 |
} else { |
|
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
331 |
listSlavePdos(slavePosition, false); |
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
332 |
} |
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
333 |
} |
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
334 |
|
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
335 |
/****************************************************************************/ |
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
336 |
|
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
337 |
void Master::listSdos(int slavePosition) |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
338 |
{ |
972 | 339 |
open(Read); |
340 |
||
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
341 |
if (slavePosition == -1) { |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
342 |
unsigned int numSlaves = slaveCount(), i; |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
343 |
|
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
344 |
for (i = 0; i < numSlaves; i++) { |
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
345 |
listSlaveSdos(i, true); |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
346 |
} |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
347 |
} else { |
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
348 |
listSlaveSdos(slavePosition, false); |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
349 |
} |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
350 |
} |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
351 |
|
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
352 |
/****************************************************************************/ |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
353 |
|
974
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
354 |
void Master::sdoDownload( |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
355 |
int slavePosition, |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
356 |
const string &dataTypeStr, |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
357 |
const vector<string> &commandArgs |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
358 |
) |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
359 |
{ |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
360 |
stringstream strIndex, strSubIndex, strValue, err; |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
361 |
ec_ioctl_slave_sdo_download_t data; |
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
362 |
unsigned int number; |
974
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
363 |
const CoEDataType *dataType = NULL; |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
364 |
|
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
365 |
if (slavePosition < 0) { |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
366 |
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
|
367 |
throw MasterException(err.str()); |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
368 |
} |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
369 |
data.slave_position = slavePosition; |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
370 |
|
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
371 |
if (commandArgs.size() != 3) { |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
372 |
err << "'sdo_download' takes 3 arguments!"; |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
373 |
throw MasterException(err.str()); |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
374 |
} |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
375 |
|
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
376 |
strIndex << commandArgs[0]; |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
377 |
strIndex |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
378 |
>> resetiosflags(ios::basefield) // guess base from prefix |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
379 |
>> data.sdo_index; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
380 |
if (strIndex.fail()) { |
974
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
381 |
err << "Invalid Sdo index '" << commandArgs[0] << "'!"; |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
382 |
throw MasterException(err.str()); |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
383 |
} |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
384 |
|
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
385 |
strSubIndex << commandArgs[1]; |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
386 |
strSubIndex |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
387 |
>> resetiosflags(ios::basefield) // guess base from prefix |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
388 |
>> number; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
389 |
if (strSubIndex.fail() || number > 0xff) { |
974
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
390 |
err << "Invalid Sdo subindex '" << commandArgs[1] << "'!"; |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
391 |
throw MasterException(err.str()); |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
392 |
} |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
393 |
data.sdo_entry_subindex = number; |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
394 |
|
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
395 |
if (dataTypeStr != "") { // data type specified |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
396 |
if (!(dataType = findDataType(dataTypeStr))) { |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
397 |
err << "Invalid data type '" << dataTypeStr << "'!"; |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
398 |
throw MasterException(err.str()); |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
399 |
} |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
400 |
} else { // no data type specified: fetch from dictionary |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
401 |
ec_ioctl_slave_sdo_entry_t entry; |
974
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
402 |
|
982
861eb2810f56
Open device with correct permissions immediately.
Florian Pose <fp@igh-essen.com>
parents:
980
diff
changeset
|
403 |
open(ReadWrite); |
974
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
404 |
|
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
405 |
try { |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
406 |
getSdoEntry(&entry, slavePosition, |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
407 |
data.sdo_index, data.sdo_entry_subindex); |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
408 |
} catch (MasterException &e) { |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
409 |
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
|
410 |
<< "Please specify --type."; |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
411 |
throw MasterException(err.str()); |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
412 |
} |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
413 |
if (!(dataType = findDataType(entry.data_type))) { |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
414 |
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
|
415 |
<< 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
|
416 |
<< " Please specify --type."; |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
417 |
throw MasterException(err.str()); |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
418 |
} |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
419 |
} |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
420 |
|
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
421 |
if (dataType->byteSize) { |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
422 |
data.data_size = dataType->byteSize; |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
423 |
} else { |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
424 |
data.data_size = DefaultBufferSize; |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
425 |
} |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
426 |
|
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
427 |
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
|
428 |
|
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
429 |
strValue << commandArgs[2]; |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
430 |
strValue >> resetiosflags(ios::basefield); // guess base from prefix |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
431 |
strValue.exceptions(ios::failbit); |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
432 |
|
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
433 |
try { |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
434 |
switch (dataType->coeCode) { |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
435 |
case 0x0002: // int8 |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
436 |
{ |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
437 |
int16_t val; // uint8_t is interpreted as char |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
438 |
strValue >> val; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
439 |
if (val > 127 || val < -128) |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
440 |
throw ios::failure("Value out of range"); |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
441 |
*data.data = val; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
442 |
break; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
443 |
} |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
444 |
case 0x0003: // int16 |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
445 |
{ |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
446 |
int16_t val; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
447 |
strValue >> val; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
448 |
*(int16_t *) data.data = cputole16(val); |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
449 |
break; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
450 |
} |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
451 |
case 0x0004: // int32 |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
452 |
{ |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
453 |
int32_t val; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
454 |
strValue >> val; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
455 |
*(int32_t *) data.data = cputole32(val); |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
456 |
break; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
457 |
} |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
458 |
case 0x0005: // uint8 |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
459 |
{ |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
460 |
uint16_t val; // uint8_t is interpreted as char |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
461 |
strValue >> val; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
462 |
if (val > 0xff) |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
463 |
throw ios::failure("Value out of range"); |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
464 |
*data.data = val; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
465 |
break; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
466 |
} |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
467 |
case 0x0006: // uint16 |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
468 |
{ |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
469 |
uint16_t val; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
470 |
strValue >> val; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
471 |
*(uint16_t *) data.data = cputole16(val); |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
472 |
break; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
473 |
} |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
474 |
case 0x0007: // uint32 |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
475 |
{ |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
476 |
uint32_t val; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
477 |
strValue >> val; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
478 |
*(uint32_t *) data.data = cputole32(val); |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
479 |
break; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
480 |
} |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
481 |
case 0x0009: // string |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
482 |
if (strValue.str().size() >= data.data_size) { |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
483 |
err << "String too large"; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
484 |
throw MasterException(err.str()); |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
485 |
} |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
486 |
data.data_size = strValue.str().size(); |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
487 |
strValue >> (char *) data.data; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
488 |
break; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
489 |
|
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
490 |
default: |
974
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
491 |
delete [] data.data; |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
492 |
err << "Unknown data type 0x" << hex << dataType->coeCode; |
974
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
493 |
throw MasterException(err.str()); |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
494 |
} |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
495 |
} catch (ios::failure &e) { |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
496 |
delete [] data.data; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
497 |
err << "Invalid value argument '" << commandArgs[2] |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
498 |
<< "' for type '" << dataType->name << "'!"; |
974
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
499 |
throw MasterException(err.str()); |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
500 |
} |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
501 |
|
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
502 |
open(ReadWrite); |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
503 |
|
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
504 |
if (ioctl(fd, EC_IOCTL_SLAVE_SDO_DOWNLOAD, &data) < 0) { |
974
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
505 |
stringstream err; |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1030
diff
changeset
|
506 |
err << "Failed to download Sdo: "; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1030
diff
changeset
|
507 |
if (errno == EIO && data.abort_code) { |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
508 |
err << "Abort code 0x" << hex << setfill('0') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
509 |
<< setw(8) << data.abort_code; |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1030
diff
changeset
|
510 |
} else { |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1030
diff
changeset
|
511 |
err << strerror(errno); |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1030
diff
changeset
|
512 |
} |
974
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
513 |
delete [] data.data; |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
514 |
throw MasterException(err.str()); |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
515 |
} |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
516 |
|
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
517 |
delete [] data.data; |
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 |
|
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
520 |
/****************************************************************************/ |
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
521 |
|
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
522 |
void Master::sdoUpload( |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
523 |
int slavePosition, |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
524 |
const string &dataTypeStr, |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
525 |
const vector<string> &commandArgs |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
526 |
) |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
527 |
{ |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
528 |
stringstream strIndex, strSubIndex; |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
529 |
int sval; |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
530 |
ec_ioctl_slave_sdo_upload_t data; |
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
531 |
unsigned int uval; |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
532 |
const CoEDataType *dataType = NULL; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
533 |
|
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
534 |
if (slavePosition < 0) { |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
535 |
stringstream err; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
536 |
err << "'sdo_upload' requires a slave! Please specify --slave."; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
537 |
throw MasterException(err.str()); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
538 |
} |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
539 |
data.slave_position = slavePosition; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
540 |
|
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
541 |
if (commandArgs.size() != 2) { |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
542 |
stringstream err; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
543 |
err << "'sdo_upload' takes two arguments!"; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
544 |
throw MasterException(err.str()); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
545 |
} |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
546 |
|
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
547 |
strIndex << commandArgs[0]; |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
548 |
strIndex |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
549 |
>> resetiosflags(ios::basefield) // guess base from prefix |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
550 |
>> data.sdo_index; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
551 |
if (strIndex.fail()) { |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
552 |
stringstream err; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
553 |
err << "Invalid Sdo index '" << commandArgs[0] << "'!"; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
554 |
throw MasterException(err.str()); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
555 |
} |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
556 |
|
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
557 |
strSubIndex << commandArgs[1]; |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
558 |
strSubIndex |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
559 |
>> resetiosflags(ios::basefield) // guess base from prefix |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
560 |
>> uval; |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
561 |
if (strSubIndex.fail() || uval > 0xff) { |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
562 |
stringstream err; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
563 |
err << "Invalid Sdo subindex '" << commandArgs[1] << "'!"; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
564 |
throw MasterException(err.str()); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
565 |
} |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
566 |
data.sdo_entry_subindex = uval; |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
567 |
|
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
568 |
if (dataTypeStr != "") { // data type specified |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
569 |
if (!(dataType = findDataType(dataTypeStr))) { |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
570 |
stringstream err; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
571 |
err << "Invalid data type '" << dataTypeStr << "'!"; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
572 |
throw MasterException(err.str()); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
573 |
} |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
574 |
} else { // no data type specified: fetch from dictionary |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
575 |
ec_ioctl_slave_sdo_entry_t entry; |
972 | 576 |
|
577 |
open(Read); |
|
578 |
||
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
579 |
try { |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
580 |
getSdoEntry(&entry, slavePosition, |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
581 |
data.sdo_index, data.sdo_entry_subindex); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
582 |
} catch (MasterException &e) { |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
583 |
stringstream err; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
584 |
err << "Failed to determine Sdo entry data type. " |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
585 |
<< "Please specify --type."; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
586 |
throw MasterException(err.str()); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
587 |
} |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
588 |
if (!(dataType = findDataType(entry.data_type))) { |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
589 |
stringstream err; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
590 |
err << "Pdo entry has unknown data type 0x" |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
591 |
<< hex << setfill('0') << setw(4) << entry.data_type << "!" |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
592 |
<< " Please specify --type."; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
593 |
throw MasterException(err.str()); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
594 |
} |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
595 |
} |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
596 |
|
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
597 |
if (dataType->byteSize) { |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
598 |
data.target_size = dataType->byteSize; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
599 |
} else { |
974
5868944a6456
Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
972
diff
changeset
|
600 |
data.target_size = DefaultBufferSize; |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
601 |
} |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
602 |
|
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
603 |
data.target = new uint8_t[data.target_size + 1]; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
604 |
|
972 | 605 |
open(Read); |
606 |
||
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
607 |
if (ioctl(fd, EC_IOCTL_SLAVE_SDO_UPLOAD, &data) < 0) { |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
608 |
stringstream err; |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1030
diff
changeset
|
609 |
err << "Failed to upload Sdo: "; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1030
diff
changeset
|
610 |
if (errno == EIO && data.abort_code) { |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
611 |
err << "Abort code 0x" << hex << setfill('0') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
612 |
<< setw(8) << data.abort_code; |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1030
diff
changeset
|
613 |
} else { |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1030
diff
changeset
|
614 |
err << strerror(errno); |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1030
diff
changeset
|
615 |
} |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
616 |
delete [] data.target; |
972 | 617 |
close(); |
618 |
throw MasterException(err.str()); |
|
619 |
} |
|
620 |
||
621 |
close(); |
|
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
622 |
|
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
623 |
if (dataType->byteSize && data.data_size != dataType->byteSize) { |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
624 |
stringstream err; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
625 |
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
|
626 |
<< " with " << dataType->byteSize << " byte, but got " |
b7cbff36bc01
Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
968
diff
changeset
|
627 |
<< data.data_size << " byte."; |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
628 |
throw MasterException(err.str()); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
629 |
} |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
630 |
|
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
631 |
cout << setfill('0'); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
632 |
switch (dataType->coeCode) { |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
633 |
case 0x0002: // int8 |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
634 |
sval = *(int8_t *) data.target; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
635 |
cout << sval << " 0x" << hex << setw(2) << sval << endl; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
636 |
break; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
637 |
case 0x0003: // int16 |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
638 |
sval = le16tocpu(*(int16_t *) data.target); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
639 |
cout << sval << " 0x" << hex << setw(4) << sval << endl; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
640 |
break; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
641 |
case 0x0004: // int32 |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
642 |
sval = le32tocpu(*(int32_t *) data.target); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
643 |
cout << sval << " 0x" << hex << setw(8) << sval << endl; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
644 |
break; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
645 |
case 0x0005: // uint8 |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
646 |
uval = (unsigned int) *(uint8_t *) data.target; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
647 |
cout << uval << " 0x" << hex << setw(2) << uval << endl; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
648 |
break; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
649 |
case 0x0006: // uint16 |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
650 |
uval = le16tocpu(*(uint16_t *) data.target); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
651 |
cout << uval << " 0x" << hex << setw(4) << uval << endl; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
652 |
break; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
653 |
case 0x0007: // uint32 |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
654 |
uval = le32tocpu(*(uint32_t *) data.target); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
655 |
cout << uval << " 0x" << hex << setw(8) << uval << endl; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
656 |
break; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
657 |
case 0x0009: // string |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
658 |
cout << string((const char *) data.target, data.data_size) |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
659 |
<< endl; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
660 |
break; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
661 |
default: |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
662 |
printRawData(data.target, data.data_size); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
663 |
break; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
664 |
} |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
665 |
|
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
666 |
delete [] data.target; |
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 |
/****************************************************************************/ |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
670 |
|
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
671 |
void Master::showSlaves(int slavePosition) |
989
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
672 |
{ |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
673 |
open(Read); |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
674 |
|
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
675 |
if (verbosity == Verbose) { |
1065
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
676 |
if (slavePosition == -1) { |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
677 |
unsigned int numSlaves = slaveCount(), i; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
678 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
679 |
for (i = 0; i < numSlaves; i++) { |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
680 |
showSlave(i); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
681 |
} |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
682 |
} else { |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
683 |
showSlave(slavePosition); |
989
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
684 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
685 |
} else { |
1065
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
686 |
listSlaves(slavePosition); |
989
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
687 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
688 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
689 |
|
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
690 |
/****************************************************************************/ |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
691 |
|
1103 | 692 |
struct CategoryName { |
693 |
uint16_t type; |
|
694 |
const char *name; |
|
695 |
}; |
|
696 |
||
697 |
static const CategoryName categoryNames[] = { |
|
698 |
{0x000a, "STRINGS"}, |
|
699 |
{0x0014, "DataTypes"}, |
|
700 |
{0x001e, "General"}, |
|
701 |
{0x0028, "FMMU"}, |
|
702 |
{0x0029, "SyncM"}, |
|
703 |
{0x0032, "TXPDO"}, |
|
704 |
{0x0033, "RXPDO"}, |
|
705 |
{0x003c, "DC"}, |
|
706 |
{} |
|
707 |
}; |
|
708 |
||
709 |
const char *getCategoryName(uint16_t type) |
|
710 |
{ |
|
711 |
const CategoryName *cn = categoryNames; |
|
712 |
||
713 |
while (cn->type) { |
|
714 |
if (cn->type == type) { |
|
715 |
return cn->name; |
|
716 |
} |
|
717 |
cn++; |
|
718 |
} |
|
719 |
||
720 |
return "unknown"; |
|
721 |
} |
|
722 |
||
978 | 723 |
void Master::siiRead(int slavePosition) |
724 |
{ |
|
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
725 |
ec_ioctl_slave_sii_t data; |
978 | 726 |
ec_ioctl_slave_t slave; |
727 |
unsigned int i; |
|
1102
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
728 |
const uint16_t *categoryHeader; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
729 |
uint16_t categoryType, categorySize; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
730 |
stringstream err; |
978 | 731 |
|
732 |
if (slavePosition < 0) { |
|
733 |
stringstream err; |
|
734 |
err << "'sii_read' requires a slave! Please specify --slave."; |
|
735 |
throw MasterException(err.str()); |
|
736 |
} |
|
737 |
data.slave_position = slavePosition; |
|
738 |
||
739 |
open(Read); |
|
740 |
||
741 |
getSlave(&slave, slavePosition); |
|
742 |
||
743 |
if (!slave.sii_nwords) |
|
744 |
return; |
|
745 |
||
746 |
data.offset = 0; |
|
747 |
data.nwords = slave.sii_nwords; |
|
748 |
data.words = new uint16_t[data.nwords]; |
|
749 |
||
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
750 |
if (ioctl(fd, EC_IOCTL_SLAVE_SII_READ, &data) < 0) { |
978 | 751 |
stringstream err; |
752 |
delete [] data.words; |
|
753 |
err << "Failed to read SII: " << strerror(errno); |
|
754 |
throw MasterException(err.str()); |
|
755 |
} |
|
756 |
||
1102
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
757 |
if (verbosity == Verbose) { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
758 |
cout << "SII Area:" << hex << setfill('0'); |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
759 |
for (i = 0; i < min(data.nwords, 0x0040U) * 2; i++) { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
760 |
if (i % BreakAfterBytes) { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
761 |
cout << " "; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
762 |
} else { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
763 |
cout << endl << " "; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
764 |
} |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
765 |
cout << setw(2) << (unsigned int) *((uint8_t *) data.words + i); |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
766 |
} |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
767 |
cout << endl; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
768 |
|
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
769 |
if (data.nwords > 0x0040U) { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
770 |
// cycle through categories |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
771 |
categoryHeader = data.words + 0x0040U; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
772 |
categoryType = le16tocpu(*categoryHeader); |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
773 |
while (categoryType != 0xffff) { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
774 |
cout << "SII Category 0x" << hex |
1103 | 775 |
<< setw(4) << categoryType |
776 |
<< " (" << getCategoryName(categoryType) << ")" << flush; |
|
1102
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
777 |
|
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
778 |
if (categoryHeader + 1 > data.words + data.nwords) { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
779 |
err << "SII data seem to be corrupted!"; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
780 |
throw MasterException(err.str()); |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
781 |
} |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
782 |
categorySize = le16tocpu(*(categoryHeader + 1)); |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
783 |
cout << ", " << dec << categorySize << " words" << flush; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
784 |
|
1103 | 785 |
if (categoryHeader + 2 + categorySize |
786 |
> data.words + data.nwords) { |
|
1102
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
787 |
err << "SII data seem to be corrupted!"; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
788 |
throw MasterException(err.str()); |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
789 |
} |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
790 |
|
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
791 |
cout << hex; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
792 |
for (i = 0; i < categorySize * 2U; i++) { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
793 |
if (i % BreakAfterBytes) { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
794 |
cout << " "; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
795 |
} else { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
796 |
cout << endl << " "; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
797 |
} |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
798 |
cout << setw(2) << (unsigned int) |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
799 |
*((uint8_t *) (categoryHeader + 2) + i); |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
800 |
} |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
801 |
cout << endl; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
802 |
|
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
803 |
if (categoryHeader + 2 + categorySize + 1 |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
804 |
> data.words + data.nwords) { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
805 |
err << "SII data seem to be corrupted!"; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
806 |
throw MasterException(err.str()); |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
807 |
} |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
808 |
categoryHeader += 2 + categorySize; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
809 |
categoryType = le16tocpu(*categoryHeader); |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
810 |
} |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
811 |
} |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
812 |
} else { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
813 |
for (i = 0; i < data.nwords; i++) { |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
814 |
uint16_t *w = data.words + i; |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
815 |
cout << *(uint8_t *) w << *((uint8_t *) w + 1); |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
816 |
} |
978 | 817 |
} |
818 |
||
819 |
delete [] data.words; |
|
820 |
} |
|
821 |
||
822 |
/****************************************************************************/ |
|
823 |
||
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
824 |
void Master::siiWrite( |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
825 |
int slavePosition, |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
826 |
bool force, |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
827 |
const vector<string> &commandArgs |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
828 |
) |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
829 |
{ |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
830 |
stringstream err; |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
831 |
ec_ioctl_slave_sii_t data; |
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
832 |
ifstream file; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
833 |
unsigned int byte_size; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
834 |
const uint16_t *categoryHeader; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
835 |
uint16_t categoryType, categorySize; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
836 |
uint8_t crc; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
837 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
838 |
if (slavePosition < 0) { |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
839 |
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
|
840 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
841 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
842 |
data.slave_position = slavePosition; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
843 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
844 |
if (commandArgs.size() != 1) { |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
845 |
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
|
846 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
847 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
848 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
849 |
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
|
850 |
if (file.fail()) { |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
851 |
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
|
852 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
853 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
854 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
855 |
// get length of file |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
856 |
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
|
857 |
byte_size = file.tellg(); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
858 |
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
|
859 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
860 |
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
|
861 |
stringstream err; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
862 |
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
|
863 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
864 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
865 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
866 |
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
|
867 |
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
|
868 |
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
|
869 |
" 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
|
870 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
871 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
872 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
873 |
// 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
|
874 |
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
|
875 |
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
|
876 |
file.close(); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
877 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
878 |
if (!force) { |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
879 |
// 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
|
880 |
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
|
881 |
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
|
882 |
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
|
883 |
<< 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
|
884 |
<< ". 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
|
885 |
throw MasterException(err.str()); |
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 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
888 |
// cycle through categories to detect corruption |
1102
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
889 |
categoryHeader = data.words + 0x0040U; |
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
890 |
categoryType = le16tocpu(*categoryHeader); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
891 |
while (categoryType != 0xffff) { |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
892 |
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
|
893 |
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
|
894 |
<< "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
|
895 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
896 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
897 |
categorySize = le16tocpu(*(categoryHeader + 1)); |
1102
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
898 |
if (categoryHeader + 2 + categorySize + 1 |
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
899 |
> data.words + data.nwords) { |
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
900 |
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
|
901 |
"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
|
902 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
903 |
} |
1102
5461894b05ab
Implemented 'ethercat sii_read -v'.
Florian Pose <fp@igh-essen.com>
parents:
1101
diff
changeset
|
904 |
categoryHeader += 2 + categorySize; |
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
905 |
categoryType = le16tocpu(*categoryHeader); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
906 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
907 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
908 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
909 |
// send data to master |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
910 |
open(ReadWrite); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
911 |
data.offset = 0; |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
912 |
if (ioctl(fd, EC_IOCTL_SLAVE_SII_WRITE, &data) < 0) { |
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
913 |
stringstream err; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
914 |
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
|
915 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
916 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
917 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
918 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
919 |
/****************************************************************************/ |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
920 |
|
960
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
921 |
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
|
922 |
int slavePosition, |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
923 |
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
|
924 |
) |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
925 |
{ |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
926 |
string stateStr; |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
927 |
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
|
928 |
|
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
929 |
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
|
930 |
stringstream err; |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
931 |
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
|
932 |
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
|
933 |
} |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
934 |
|
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
935 |
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
|
936 |
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
|
937 |
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
|
938 |
|
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
939 |
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
|
940 |
state = 0x01; |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
941 |
} 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
|
942 |
state = 0x02; |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
943 |
} 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
|
944 |
state = 0x04; |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
945 |
} 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
|
946 |
state = 0x08; |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
947 |
} else { |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
948 |
stringstream err; |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
949 |
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
|
950 |
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
|
951 |
} |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
952 |
|
972 | 953 |
open(ReadWrite); |
954 |
||
960
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
955 |
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
|
956 |
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
|
957 |
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
|
958 |
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
|
959 |
} else { |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
960 |
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
|
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 |
|
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
964 |
/****************************************************************************/ |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
965 |
|
938
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
966 |
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
|
967 |
{ |
972 | 968 |
open(Read); |
969 |
||
938
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
970 |
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
|
971 |
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
|
972 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
973 |
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
|
974 |
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
|
975 |
} |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
976 |
} else { |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
977 |
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
|
978 |
} |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
979 |
} |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
980 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
981 |
/****************************************************************************/ |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
982 |
|
972 | 983 |
void Master::open(Permissions perm) |
984 |
{ |
|
985 |
stringstream deviceName; |
|
986 |
||
987 |
if (fd != -1) { // already open |
|
982
861eb2810f56
Open device with correct permissions immediately.
Florian Pose <fp@igh-essen.com>
parents:
980
diff
changeset
|
988 |
return; |
972 | 989 |
} |
990 |
||
991 |
deviceName << "/dev/EtherCAT" << index; |
|
992 |
||
993 |
if ((fd = ::open(deviceName.str().c_str(), |
|
994 |
perm == ReadWrite ? O_RDWR : O_RDONLY)) == -1) { |
|
995 |
stringstream err; |
|
996 |
err << "Failed to open master device " << deviceName.str() << ": " |
|
997 |
<< strerror(errno); |
|
998 |
throw MasterException(err.str()); |
|
999 |
} |
|
1000 |
} |
|
1001 |
||
1002 |
/****************************************************************************/ |
|
1003 |
||
1004 |
void Master::close() |
|
1005 |
{ |
|
1006 |
if (fd == -1) |
|
1007 |
return; |
|
1008 |
||
1009 |
::close(fd); |
|
982
861eb2810f56
Open device with correct permissions immediately.
Florian Pose <fp@igh-essen.com>
parents:
980
diff
changeset
|
1010 |
fd = -1; |
972 | 1011 |
} |
1012 |
||
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1013 |
/*****************************************************************************/ |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1014 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1015 |
/** |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1016 |
* 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
|
1017 |
*/ |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1018 |
void Master::writeSlaveAlias( |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1019 |
uint16_t slavePosition, |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1020 |
uint16_t alias |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1021 |
) |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1022 |
{ |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1023 |
ec_ioctl_slave_sii_t data; |
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1024 |
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
|
1025 |
stringstream err; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1026 |
uint8_t crc; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1027 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1028 |
open(ReadWrite); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1029 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1030 |
getSlave(&slave, slavePosition); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1031 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1032 |
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
|
1033 |
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
|
1034 |
<< "(" << slave.sii_nwords << " words)!"; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1035 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1036 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1037 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1038 |
data.slave_position = slavePosition; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1039 |
data.offset = 0; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1040 |
data.nwords = 8; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1041 |
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
|
1042 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1043 |
// read first 8 SII words |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1044 |
if (ioctl(fd, EC_IOCTL_SLAVE_SII_READ, &data) < 0) { |
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1045 |
delete [] data.words; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1046 |
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
|
1047 |
throw MasterException(err.str()); |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1048 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1049 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1050 |
// 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
|
1051 |
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
|
1052 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1053 |
// 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
|
1054 |
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
|
1055 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1056 |
// 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
|
1057 |
*(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
|
1058 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1059 |
// write first 8 words with new alias and checksum |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1060 |
if (ioctl(fd, EC_IOCTL_SLAVE_SII_WRITE, &data) < 0) { |
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1061 |
delete [] data.words; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1062 |
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
|
1063 |
throw MasterException(err.str()); |
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 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1066 |
delete [] data.words; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1067 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
1068 |
|
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1069 |
/*****************************************************************************/ |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1070 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1071 |
/** Lists the complete bus configuration. |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1072 |
*/ |
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
1073 |
void Master::showDetailedConfigs() |
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1074 |
{ |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1075 |
ec_ioctl_master_t master; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1076 |
unsigned int i, j, k, l; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1077 |
ec_ioctl_config_t config; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1078 |
ec_ioctl_config_pdo_t pdo; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1079 |
ec_ioctl_config_pdo_entry_t entry; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1080 |
ec_ioctl_config_sdo_t sdo; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1081 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1082 |
open(Read); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1083 |
getMaster(&master); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1084 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1085 |
for (i = 0; i < master.config_count; i++) { |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1086 |
getConfig(&config, i); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1087 |
|
1068 | 1088 |
cout << "Alias: " |
1089 |
<< dec << config.alias << endl |
|
1090 |
<< "Position: " << config.position << endl |
|
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1091 |
<< "Vendor Id: 0x" |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1092 |
<< hex << setfill('0') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1093 |
<< setw(8) << config.vendor_id << endl |
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1094 |
<< "Product code: 0x" |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1095 |
<< setw(8) << config.product_code << endl |
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1096 |
<< "Attached: " << (config.attached ? "yes" : "no") << endl |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1097 |
<< "Operational: " << (config.operational ? "yes" : "no") << endl; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1098 |
|
1082
ff06c58e269c
Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents:
1079
diff
changeset
|
1099 |
for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) { |
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1100 |
if (config.syncs[j].pdo_count) { |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1101 |
cout << "SM" << dec << j << " (" |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1102 |
<< (config.syncs[j].dir == EC_DIR_INPUT |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1103 |
? "Input" : "Output") << ")" << endl; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1104 |
for (k = 0; k < config.syncs[j].pdo_count; k++) { |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1105 |
getConfigPdo(&pdo, i, j, k); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1106 |
|
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1107 |
cout << " Pdo 0x" << hex |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1108 |
<< setw(4) << pdo.index |
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1109 |
<< " \"" << pdo.name << "\"" << endl; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1110 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1111 |
for (l = 0; l < pdo.entry_count; l++) { |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1112 |
getConfigPdoEntry(&entry, i, j, k, l); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1113 |
|
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1114 |
cout << " Pdo entry 0x" << hex |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1115 |
<< setw(4) << entry.index << ":" |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1116 |
<< setw(2) << (unsigned int) entry.subindex |
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1117 |
<< ", " << dec << (unsigned int) entry.bit_length |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1118 |
<< " bit, \"" << entry.name << "\"" << endl; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1119 |
} |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1120 |
} |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1121 |
} |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1122 |
} |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1123 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1124 |
if (config.sdo_count) { |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1125 |
cout << "Sdo configuration:" << endl; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1126 |
for (j = 0; j < config.sdo_count; j++) { |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1127 |
getConfigSdo(&sdo, i, j); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1128 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1129 |
cout << " 0x" |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1130 |
<< hex << setfill('0') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1131 |
<< setw(4) << sdo.index << ":" |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1132 |
<< setw(2) << (unsigned int) sdo.subindex |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1133 |
<< ", " << dec << sdo.size << " byte: " << hex; |
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1134 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1135 |
switch (sdo.size) { |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1136 |
case 1: |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1137 |
cout << "0x" << setw(2) |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1138 |
<< (unsigned int) *(uint8_t *) &sdo.data; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1139 |
break; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1140 |
case 2: |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1141 |
cout << "0x" << setw(4) |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1142 |
<< le16tocpu(*(uint16_t *) &sdo.data); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1143 |
break; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1144 |
case 4: |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1145 |
cout << "0x" << setw(8) |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1146 |
<< le32tocpu(*(uint32_t *) &sdo.data); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1147 |
break; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1148 |
default: |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1149 |
cout << "???"; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1150 |
} |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1151 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1152 |
cout << endl; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1153 |
} |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1154 |
} |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1155 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1156 |
cout << endl; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1157 |
} |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1158 |
} |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1159 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1160 |
/*****************************************************************************/ |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1161 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1162 |
struct ConfigInfo { |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1163 |
string alias; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1164 |
string pos; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1165 |
string ident; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1166 |
string att; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1167 |
string op; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1168 |
}; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1169 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1170 |
/** Lists the bus configuration. |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1171 |
*/ |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1172 |
void Master::listConfigs() |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1173 |
{ |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1174 |
ec_ioctl_master_t master; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1175 |
unsigned int i; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1176 |
ec_ioctl_config_t config; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1177 |
stringstream str; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1178 |
ConfigInfo info; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1179 |
typedef list<ConfigInfo> ConfigInfoList; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1180 |
ConfigInfoList list; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1181 |
ConfigInfoList::const_iterator iter; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1182 |
unsigned int maxAliasWidth = 0, maxPosWidth = 0, |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1183 |
maxAttWidth = 0, maxOpWidth = 0; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1184 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1185 |
open(Read); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1186 |
getMaster(&master); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1187 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1188 |
for (i = 0; i < master.config_count; i++) { |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1189 |
getConfig(&config, i); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1190 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1191 |
str << dec << config.alias; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1192 |
info.alias = str.str(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1193 |
str.clear(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1194 |
str.str(""); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1195 |
|
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1196 |
str << config.position; |
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1197 |
info.pos = str.str(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1198 |
str.clear(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1199 |
str.str(""); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1200 |
|
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1201 |
str << hex << setfill('0') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1202 |
<< "0x" << setw(8) << config.vendor_id |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1203 |
<< "/0x" << setw(8) << config.product_code; |
1066
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1204 |
info.ident = str.str(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1205 |
str.clear(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1206 |
str.str(""); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1207 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1208 |
str << (config.attached ? "attached" : "-"); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1209 |
info.att = str.str(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1210 |
str.clear(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1211 |
str.str(""); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1212 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1213 |
str << (config.operational ? "operational" : "-"); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1214 |
info.op = str.str(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1215 |
str.clear(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1216 |
str.str(""); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1217 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1218 |
list.push_back(info); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1219 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1220 |
if (info.alias.length() > maxAliasWidth) |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1221 |
maxAliasWidth = info.alias.length(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1222 |
if (info.pos.length() > maxPosWidth) |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1223 |
maxPosWidth = info.pos.length(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1224 |
if (info.att.length() > maxAttWidth) |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1225 |
maxAttWidth = info.att.length(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1226 |
if (info.op.length() > maxOpWidth) |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1227 |
maxOpWidth = info.op.length(); |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1228 |
} |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1229 |
|
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1230 |
for (iter = list.begin(); iter != list.end(); iter++) { |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1231 |
cout << setfill(' ') << right |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1232 |
<< setw(maxAliasWidth) << iter->alias |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1233 |
<< ":" << left |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1234 |
<< setw(maxPosWidth) << iter->pos |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1235 |
<< " " |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1236 |
<< iter->ident |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1237 |
<< " " |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1238 |
<< setw(maxAttWidth) << iter->att << " " |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1239 |
<< setw(maxOpWidth) << iter->op << " " |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1240 |
<< endl; |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1241 |
} |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1242 |
} |
7ece00bd6559
Added configuration listing command.
Florian Pose <fp@igh-essen.com>
parents:
1065
diff
changeset
|
1243 |
|
972 | 1244 |
/****************************************************************************/ |
1245 |
||
949
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1246 |
void Master::outputDomainData(unsigned int domainIndex) |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1247 |
{ |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1248 |
ec_ioctl_domain_t domain; |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1249 |
ec_ioctl_domain_data_t data; |
949
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1250 |
unsigned char *processData; |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1251 |
unsigned int i; |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1252 |
|
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1253 |
getDomain(&domain, domainIndex); |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1254 |
|
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1255 |
if (!domain.data_size) |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1256 |
return; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1257 |
|
949
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1258 |
processData = new unsigned char[domain.data_size]; |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1259 |
|
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1260 |
try { |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1261 |
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
|
1262 |
} catch (MasterException &e) { |
949
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1263 |
delete [] processData; |
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1264 |
throw e; |
949
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1265 |
} |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1266 |
|
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1267 |
for (i = 0; i < data.data_size; i++) |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1268 |
cout << processData[i]; |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1269 |
cout.flush(); |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1270 |
|
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1271 |
delete [] processData; |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1272 |
} |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1273 |
|
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1274 |
/****************************************************************************/ |
e424c0074c67
Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents:
948
diff
changeset
|
1275 |
|
948
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1276 |
void Master::showDomain(unsigned int domainIndex) |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1277 |
{ |
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1278 |
ec_ioctl_domain_t domain; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1279 |
unsigned char *processData; |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1280 |
ec_ioctl_domain_data_t data; |
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1281 |
unsigned int i, j; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1282 |
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
|
1283 |
unsigned int dataOffset; |
948
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1284 |
|
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1285 |
getDomain(&domain, domainIndex); |
948
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1286 |
|
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1287 |
cout << "Domain" << dec << domainIndex << ":" |
948
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1288 |
<< " LogBaseAddr 0x" |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1289 |
<< hex << setfill('0') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1290 |
<< setw(8) << domain.logical_base_address |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1291 |
<< ", Size " << dec << setfill(' ') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1292 |
<< setw(3) << domain.data_size |
948
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1293 |
<< ", WorkingCounter " |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1294 |
<< domain.working_counter << "/" |
951
dc84a0af63da
Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents:
950
diff
changeset
|
1295 |
<< 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
|
1296 |
|
1100
af0b187de6ef
Show domain data only if verbose.
Florian Pose <fp@igh-essen.com>
parents:
1099
diff
changeset
|
1297 |
if (!domain.data_size || verbosity != Verbose) |
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1298 |
return; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1299 |
|
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1300 |
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
|
1301 |
|
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1302 |
try { |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1303 |
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
|
1304 |
} catch (MasterException &e) { |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1305 |
delete [] processData; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1306 |
throw e; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1307 |
} |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1308 |
|
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1309 |
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
|
1310 |
getFmmu(&fmmu, domainIndex, i); |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1311 |
|
951
dc84a0af63da
Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents:
950
diff
changeset
|
1312 |
cout << " SlaveConfig " |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1313 |
<< dec << fmmu.slave_config_alias |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1314 |
<< ":" << fmmu.slave_config_position |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1315 |
<< ", SM" << (unsigned int) fmmu.sync_index << " (" |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1316 |
<< setfill(' ') << setw(6) |
1062
75a2b2934e2b
Show sync manager index in 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents:
1057
diff
changeset
|
1317 |
<< (fmmu.dir == EC_DIR_INPUT ? "Input" : "Output") |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1318 |
<< "), LogAddr 0x" |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1319 |
<< hex << setfill('0') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1320 |
<< setw(8) << fmmu.logical_address |
951
dc84a0af63da
Improved output of 'ethercat domain'.
Florian Pose <fp@igh-essen.com>
parents:
950
diff
changeset
|
1321 |
<< ", 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
|
1322 |
|
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1323 |
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
|
1324 |
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
|
1325 |
stringstream err; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1326 |
err << "Fmmu information corrupted!"; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1327 |
delete [] processData; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1328 |
throw MasterException(err.str()); |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1329 |
} |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1330 |
|
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1331 |
cout << " " << hex << setfill('0'); |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1332 |
for (j = 0; j < fmmu.data_size; j++) { |
1101
f8d13814af03
Break domain output data after 16 bytes.
Florian Pose <fp@igh-essen.com>
parents:
1100
diff
changeset
|
1333 |
if (j && !(j % BreakAfterBytes)) |
f8d13814af03
Break domain output data after 16 bytes.
Florian Pose <fp@igh-essen.com>
parents:
1100
diff
changeset
|
1334 |
cout << endl << " "; |
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1335 |
cout << setw(2) |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1336 |
<< (unsigned int) *(processData + dataOffset + j) << " "; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1337 |
} |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1338 |
cout << endl; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1339 |
} |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1340 |
|
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1341 |
delete [] processData; |
948
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1342 |
} |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1343 |
|
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1344 |
/****************************************************************************/ |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1345 |
|
966 | 1346 |
void Master::listSlavePdos( |
1347 |
uint16_t slavePosition, |
|
1348 |
bool withHeader |
|
1349 |
) |
|
936 | 1350 |
{ |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1351 |
ec_ioctl_slave_t slave; |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1352 |
ec_ioctl_slave_sync_t sync; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1353 |
ec_ioctl_slave_sync_pdo_t pdo; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1354 |
ec_ioctl_slave_sync_pdo_entry_t entry; |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1355 |
unsigned int i, j, k; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1356 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1357 |
getSlave(&slave, slavePosition); |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1358 |
|
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1359 |
if (withHeader) |
936 | 1360 |
cout << "=== Slave " << slavePosition << " ===" << endl; |
1361 |
||
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1362 |
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
|
1363 |
getSync(&sync, slavePosition, i); |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1364 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1365 |
cout << "SM" << i << ":" |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1366 |
<< " PhysAddr 0x" |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1367 |
<< hex << setfill('0') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1368 |
<< setw(4) << sync.physical_start_address |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1369 |
<< ", DefaultSize " |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1370 |
<< dec << setfill(' ') << setw(4) << sync.default_size |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1371 |
<< ", ControlRegister 0x" |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1372 |
<< hex << setfill('0') << setw(2) |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1373 |
<< (unsigned int) sync.control_register |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1374 |
<< ", Enable " << dec << (unsigned int) sync.enable |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1375 |
<< endl; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1376 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1377 |
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
|
1378 |
getPdo(&pdo, slavePosition, i, j); |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1379 |
|
1055
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1380 |
cout << " " << (sync.control_register & 0x04 ? "R" : "T") |
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1381 |
<< "xPdo 0x" |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1382 |
<< hex << setfill('0') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1383 |
<< setw(4) << pdo.index |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1384 |
<< " \"" << pdo.name << "\"" << endl; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1385 |
|
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
1386 |
if (verbosity == Quiet) |
966 | 1387 |
continue; |
1388 |
||
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1389 |
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
|
1390 |
getPdoEntry(&entry, slavePosition, i, j, k); |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1391 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1392 |
cout << " Pdo entry 0x" |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1393 |
<< hex << setfill('0') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1394 |
<< setw(4) << entry.index |
990
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1395 |
<< ":" << setw(2) << (unsigned int) entry.subindex |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1396 |
<< ", " << dec << (unsigned int) entry.bit_length |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1397 |
<< " bit, \"" << entry.name << "\"" << endl; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1398 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1399 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1400 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1401 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1402 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1403 |
/****************************************************************************/ |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1404 |
|
966 | 1405 |
void Master::listSlaveSdos( |
1406 |
uint16_t slavePosition, |
|
1407 |
bool withHeader |
|
1408 |
) |
|
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1409 |
{ |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1410 |
ec_ioctl_slave_t slave; |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1411 |
ec_ioctl_slave_sdo_t sdo; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1412 |
ec_ioctl_slave_sdo_entry_t entry; |
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
1413 |
unsigned int i, j; |
970
b7cbff36bc01
Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
968
diff
changeset
|
1414 |
const CoEDataType *d; |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1415 |
|
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1416 |
getSlave(&slave, slavePosition); |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1417 |
|
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1418 |
if (withHeader) |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1419 |
cout << "=== Slave " << slavePosition << " ===" << endl; |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1420 |
|
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1421 |
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
|
1422 |
getSdo(&sdo, slavePosition, i); |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1423 |
|
1068 | 1424 |
cout << "Sdo 0x" |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1425 |
<< hex << setfill('0') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1426 |
<< setw(4) << sdo.sdo_index |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1427 |
<< ", \"" << sdo.name << "\"" << endl; |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1428 |
|
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
1429 |
if (verbosity == Quiet) |
966 | 1430 |
continue; |
1431 |
||
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1432 |
for (j = 0; j <= sdo.max_subindex; j++) { |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
1433 |
getSdoEntry(&entry, slavePosition, -i, j); |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1434 |
|
1068 | 1435 |
cout << " 0x" << hex << setfill('0') |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1436 |
<< setw(4) << sdo.sdo_index << ":" |
983 | 1437 |
<< 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
|
1438 |
<< ", "; |
b7cbff36bc01
Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
968
diff
changeset
|
1439 |
|
b7cbff36bc01
Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
968
diff
changeset
|
1440 |
if ((d = findDataType(entry.data_type))) { |
b7cbff36bc01
Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
968
diff
changeset
|
1441 |
cout << d->name; |
b7cbff36bc01
Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
968
diff
changeset
|
1442 |
} else { |
b7cbff36bc01
Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
968
diff
changeset
|
1443 |
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
|
1444 |
} |
b7cbff36bc01
Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
968
diff
changeset
|
1445 |
|
b7cbff36bc01
Display textual data type in 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
968
diff
changeset
|
1446 |
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
|
1447 |
<< entry.description << "\"" << endl; |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1448 |
} |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1449 |
} |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1450 |
} |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1451 |
|
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1452 |
/****************************************************************************/ |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
1453 |
|
1065
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1454 |
struct SlaveInfo { |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1455 |
string pos; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1456 |
string alias; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1457 |
string relPos; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1458 |
string state; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1459 |
string flag; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1460 |
string name; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1461 |
}; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1462 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1463 |
void Master::listSlaves(int slavePosition) |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1464 |
{ |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1465 |
unsigned int numSlaves, i; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1466 |
ec_ioctl_slave_t slave; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1467 |
uint16_t lastAlias, aliasIndex; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1468 |
SlaveInfo slaveInfo; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1469 |
typedef list<SlaveInfo> SlaveInfoList; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1470 |
SlaveInfoList slaveInfoList; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1471 |
SlaveInfoList::const_iterator iter; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1472 |
stringstream str; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1473 |
unsigned int maxPosWidth = 0, maxAliasWidth = 0, |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1474 |
maxRelPosWidth = 0, maxStateWidth = 0; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1475 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1476 |
open(Read); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1477 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1478 |
numSlaves = slaveCount(); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1479 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1480 |
lastAlias = 0; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1481 |
aliasIndex = 0; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1482 |
for (i = 0; i < numSlaves; i++) { |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1483 |
getSlave(&slave, i); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1484 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1485 |
if (slave.alias) { |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1486 |
lastAlias = slave.alias; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1487 |
aliasIndex = 0; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1488 |
} |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1489 |
|
1099
eb8d16507d88
Made verbosity a master property; added -Wall flag to tools.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
1490 |
if (slavePosition == -1 || i == (unsigned int) slavePosition) { |
1065
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1491 |
str << dec << i; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1492 |
slaveInfo.pos = str.str(); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1493 |
str.clear(); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1494 |
str.str(""); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1495 |
|
1067 | 1496 |
str << lastAlias; |
1497 |
slaveInfo.alias = str.str(); |
|
1498 |
str.str(""); |
|
1499 |
||
1500 |
str << aliasIndex; |
|
1501 |
slaveInfo.relPos = str.str(); |
|
1502 |
str.str(""); |
|
1065
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1503 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1504 |
slaveInfo.state = slaveState(slave.state); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1505 |
slaveInfo.flag = (slave.error_flag ? 'E' : '+'); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1506 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1507 |
if (strlen(slave.name)) { |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1508 |
slaveInfo.name = slave.name; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1509 |
} else { |
1068 | 1510 |
str << "0x" << hex << setfill('0') |
1511 |
<< setw(8) << slave.vendor_id << ":0x" |
|
1065
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1512 |
<< setw(8) << slave.product_code; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1513 |
slaveInfo.name = str.str(); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1514 |
str.str(""); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1515 |
} |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1516 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1517 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1518 |
slaveInfoList.push_back(slaveInfo); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1519 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1520 |
if (slaveInfo.pos.length() > maxPosWidth) |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1521 |
maxPosWidth = slaveInfo.pos.length(); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1522 |
if (slaveInfo.alias.length() > maxAliasWidth) |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1523 |
maxAliasWidth = slaveInfo.alias.length(); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1524 |
if (slaveInfo.relPos.length() > maxRelPosWidth) |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1525 |
maxRelPosWidth = slaveInfo.relPos.length(); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1526 |
if (slaveInfo.state.length() > maxStateWidth) |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1527 |
maxStateWidth = slaveInfo.state.length(); |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1528 |
} |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1529 |
|
1067 | 1530 |
aliasIndex++; |
1065
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1531 |
} |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1532 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1533 |
for (iter = slaveInfoList.begin(); iter != slaveInfoList.end(); iter++) { |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1534 |
cout << setfill(' ') << right |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1535 |
<< setw(maxPosWidth) << iter->pos << " " |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1536 |
<< setw(maxAliasWidth) << iter->alias |
1067 | 1537 |
<< ":" << left |
1065
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1538 |
<< setw(maxRelPosWidth) << iter->relPos << " " |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1539 |
<< setw(maxStateWidth) << iter->state << " " |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1540 |
<< iter->flag << " " |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1541 |
<< iter->name << endl; |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1542 |
} |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1543 |
} |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1544 |
|
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1545 |
/****************************************************************************/ |
d1d2aa556344
United 'ethercat slaves' and 'ethercat list' with a verbose flag.
Florian Pose <fp@igh-essen.com>
parents:
1062
diff
changeset
|
1546 |
|
989
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1547 |
void Master::showSlave(uint16_t slavePosition) |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1548 |
{ |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1549 |
ec_ioctl_slave_t slave; |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1550 |
list<string> protoList; |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1551 |
list<string>::const_iterator protoIter; |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1552 |
|
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1553 |
getSlave(&slave, slavePosition); |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1554 |
|
1069
ab0c21d9ab2b
Output slave headers in 'ethercat slaves'; show alias only if set.
Florian Pose <fp@igh-essen.com>
parents:
1068
diff
changeset
|
1555 |
cout << "=== Slave " << dec << slavePosition << " ===" << endl; |
ab0c21d9ab2b
Output slave headers in 'ethercat slaves'; show alias only if set.
Florian Pose <fp@igh-essen.com>
parents:
1068
diff
changeset
|
1556 |
|
ab0c21d9ab2b
Output slave headers in 'ethercat slaves'; show alias only if set.
Florian Pose <fp@igh-essen.com>
parents:
1068
diff
changeset
|
1557 |
if (slave.alias) |
ab0c21d9ab2b
Output slave headers in 'ethercat slaves'; show alias only if set.
Florian Pose <fp@igh-essen.com>
parents:
1068
diff
changeset
|
1558 |
cout << "Alias: " << slave.alias << endl; |
ab0c21d9ab2b
Output slave headers in 'ethercat slaves'; show alias only if set.
Florian Pose <fp@igh-essen.com>
parents:
1068
diff
changeset
|
1559 |
|
ab0c21d9ab2b
Output slave headers in 'ethercat slaves'; show alias only if set.
Florian Pose <fp@igh-essen.com>
parents:
1068
diff
changeset
|
1560 |
cout |
989
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1561 |
<< "State: " << slaveState(slave.state) << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1562 |
<< "Flag: " << (slave.error_flag ? 'E' : '+') << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1563 |
<< "Identity:" << endl |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1564 |
<< " Vendor Id: 0x" |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1565 |
<< hex << setfill('0') |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1566 |
<< setw(8) << slave.vendor_id << endl |
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1567 |
<< " Product code: 0x" |
989
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1568 |
<< setw(8) << slave.product_code << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1569 |
<< " Revision number: 0x" |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1570 |
<< setw(8) << slave.revision_number << endl |
1072
94a5f043dee5
Improved input/output of hex numbers.
Florian Pose <fp@igh-essen.com>
parents:
1071
diff
changeset
|
1571 |
<< " Serial number: 0x" |
989
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1572 |
<< setw(8) << slave.serial_number << endl; |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1573 |
|
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1574 |
if (slave.mailbox_protocols) { |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1575 |
cout << "Mailboxes:" << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1576 |
<< " RX: 0x" |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1577 |
<< hex << setw(4) << slave.rx_mailbox_offset << "/" |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1578 |
<< dec << slave.rx_mailbox_size |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1579 |
<< ", TX: 0x" |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1580 |
<< hex << setw(4) << slave.tx_mailbox_offset << "/" |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1581 |
<< dec << slave.tx_mailbox_size << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1582 |
<< " Supported protocols: "; |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1583 |
|
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1584 |
if (slave.mailbox_protocols & EC_MBOX_AOE) { |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1585 |
protoList.push_back("AoE"); |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1586 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1587 |
if (slave.mailbox_protocols & EC_MBOX_EOE) { |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1588 |
protoList.push_back("EoE"); |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1589 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1590 |
if (slave.mailbox_protocols & EC_MBOX_COE) { |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1591 |
protoList.push_back("CoE"); |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1592 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1593 |
if (slave.mailbox_protocols & EC_MBOX_FOE) { |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1594 |
protoList.push_back("FoE"); |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1595 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1596 |
if (slave.mailbox_protocols & EC_MBOX_SOE) { |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1597 |
protoList.push_back("SoE"); |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1598 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1599 |
if (slave.mailbox_protocols & EC_MBOX_VOE) { |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1600 |
protoList.push_back("VoE"); |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1601 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1602 |
|
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1603 |
for (protoIter = protoList.begin(); protoIter != protoList.end(); |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1604 |
protoIter++) { |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1605 |
if (protoIter != protoList.begin()) |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1606 |
cout << ", "; |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1607 |
cout << *protoIter; |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1608 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1609 |
cout << endl; |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1610 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1611 |
|
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1612 |
if (slave.has_general_category) { |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1613 |
cout << "General:" << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1614 |
<< " Name: " << slave.name << endl; |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1615 |
|
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1616 |
if (slave.mailbox_protocols & EC_MBOX_COE) { |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1617 |
cout << " CoE details:" << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1618 |
<< " Enable Sdo: " |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1619 |
<< (slave.coe_details.enable_sdo ? "yes" : "no") << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1620 |
<< " Enable Sdo Info: " |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1621 |
<< (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
|
1622 |
<< " Enable Pdo Assign: " |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1623 |
<< (slave.coe_details.enable_pdo_assign |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1624 |
? "yes" : "no") << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1625 |
<< " Enable Pdo Configuration: " |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1626 |
<< (slave.coe_details.enable_pdo_configuration |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1627 |
? "yes" : "no") << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1628 |
<< " Enable Upload at startup: " |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1629 |
<< (slave.coe_details.enable_upload_at_startup |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1630 |
? "yes" : "no") << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1631 |
<< " Enable Sdo complete access: " |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1632 |
<< (slave.coe_details.enable_sdo_complete_access |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1633 |
? "yes" : "no") << endl; |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1634 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1635 |
|
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1636 |
cout << " Flags:" << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1637 |
<< " Enable SafeOp: " |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1638 |
<< (slave.general_flags.enable_safeop ? "yes" : "no") << endl |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1639 |
<< " Enable notLRW: " |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1640 |
<< (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
|
1641 |
<< " Current consumption: " |
990
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1642 |
<< dec << slave.current_on_ebus << " mA" << endl; |
989
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1643 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1644 |
} |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1645 |
|
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1646 |
/****************************************************************************/ |
816663ca9370
Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents:
988
diff
changeset
|
1647 |
|
938
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1648 |
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
|
1649 |
{ |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1650 |
ec_ioctl_slave_t slave; |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1651 |
ec_ioctl_slave_sync_t sync; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1652 |
ec_ioctl_slave_sync_pdo_t pdo; |
1055
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1653 |
string pdoType; |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1654 |
ec_ioctl_slave_sync_pdo_entry_t entry; |
938
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1655 |
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
|
1656 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1657 |
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
|
1658 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1659 |
cout |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1660 |
<< "<?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
|
1661 |
<< " <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
|
1662 |
<< " <!-- 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
|
1663 |
<< " <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
|
1664 |
<< " <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
|
1665 |
<< " </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
|
1666 |
<< " <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
|
1667 |
<< " <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
|
1668 |
<< " <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
|
1669 |
<< " <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
|
1670 |
<< 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
|
1671 |
<< "\" 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
|
1672 |
<< 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
|
1673 |
<< "\"/>" << endl; |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1674 |
|
1073
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1675 |
if (strlen(slave.name)) { |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1676 |
cout |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1677 |
<< " <Name><![CDATA[" |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1678 |
<< slave.name |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1679 |
<< "]]></Name>" << endl; |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1680 |
} |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1681 |
|
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1682 |
for (i = 0; i < slave.sync_count; i++) { |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1683 |
getSync(&sync, slavePosition, i); |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1684 |
|
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1685 |
cout |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1686 |
<< " <Sm Enable=\"" << dec << (unsigned int) sync.enable |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1687 |
<< "\" StartAddress=\"" << sync.physical_start_address |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1688 |
<< "\" ControlByte=\"" << (unsigned int) sync.control_register |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1689 |
<< "\" DefaultSize=\"" << sync.default_size |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1690 |
<< "\" />" << endl; |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1691 |
} |
f3c50aa42b6c
Sync manager and name information in xml.
Florian Pose <fp@igh-essen.com>
parents:
1072
diff
changeset
|
1692 |
|
938
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1693 |
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
|
1694 |
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
|
1695 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1696 |
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
|
1697 |
getPdo(&pdo, slavePosition, i, j); |
1055
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1698 |
pdoType = (sync.control_register & 0x04 ? "R" : "T"); |
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1699 |
pdoType += "xPdo"; |
938
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1700 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1701 |
cout |
1071
82122748f4e0
Added Fixed="1" to Pdo element.
Florian Pose <fp@igh-essen.com>
parents:
1070
diff
changeset
|
1702 |
<< " <" << pdoType |
82122748f4e0
Added Fixed="1" to Pdo element.
Florian Pose <fp@igh-essen.com>
parents:
1070
diff
changeset
|
1703 |
<< " Sm=\"" << i << "\" Fixed=\"1\">" << endl |
938
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1704 |
<< " <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
|
1705 |
<< 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
|
1706 |
<< "</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
|
1707 |
<< " <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
|
1708 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1709 |
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
|
1710 |
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
|
1711 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1712 |
cout |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1713 |
<< " <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
|
1714 |
<< " <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
|
1715 |
<< 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
|
1716 |
<< "</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
|
1717 |
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
|
1718 |
cout |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1719 |
<< " <SubIndex>" |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1720 |
<< 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
|
1721 |
<< "</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
|
1722 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1723 |
cout |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1724 |
<< " <BitLen>" |
1030
d7970e934dba
Bugfix: Bitlength always decimal in XML.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
1725 |
<< dec << (unsigned int) entry.bit_length |
938
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1726 |
<< "</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
|
1727 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1728 |
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
|
1729 |
cout |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1730 |
<< " <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
|
1731 |
<< "</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
|
1732 |
<< " <DataType>"; |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1733 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1734 |
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
|
1735 |
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
|
1736 |
} 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
|
1737 |
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
|
1738 |
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
|
1739 |
else |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1740 |
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
|
1741 |
<< (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
|
1742 |
<< ")"; |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1743 |
} else { |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1744 |
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
|
1745 |
<< (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
|
1746 |
} |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1747 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1748 |
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
|
1749 |
} |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1750 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1751 |
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
|
1752 |
} |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1753 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1754 |
cout |
1055
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1755 |
<< " </" << pdoType << ">" << endl; |
938
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1756 |
} |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1757 |
} |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1758 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1759 |
cout |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1760 |
<< " </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
|
1761 |
<< " </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
|
1762 |
<< " </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
|
1763 |
<< "</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
|
1764 |
} |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1765 |
|
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1766 |
/****************************************************************************/ |
5b936e8e39fa
Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents:
936
diff
changeset
|
1767 |
|
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1768 |
unsigned int Master::slaveCount() |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1769 |
{ |
957
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
1770 |
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
|
1771 |
|
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
1772 |
getMaster(&data); |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
1773 |
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
|
1774 |
} |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
1775 |
|
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
1776 |
/****************************************************************************/ |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
1777 |
|
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
1778 |
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
|
1779 |
{ |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
1780 |
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
|
1781 |
stringstream err; |
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
1782 |
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
|
1783 |
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
|
1784 |
} |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1785 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1786 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1787 |
/****************************************************************************/ |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1788 |
|
990
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1789 |
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
|
1790 |
{ |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1791 |
data->config_index = index; |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1792 |
|
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1793 |
if (ioctl(fd, EC_IOCTL_CONFIG, data) < 0) { |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1794 |
stringstream err; |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1795 |
err << "Failed to get slave configuration: " << strerror(errno); |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1796 |
throw MasterException(err.str()); |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1797 |
} |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1798 |
} |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1799 |
|
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1800 |
/****************************************************************************/ |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1801 |
|
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1802 |
void Master::getConfigPdo( |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1803 |
ec_ioctl_config_pdo_t *data, |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1804 |
unsigned int index, |
1055
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1805 |
uint8_t sync_index, |
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1806 |
uint16_t pdo_pos |
990
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1807 |
) |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1808 |
{ |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1809 |
data->config_index = index; |
1055
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1810 |
data->sync_index = sync_index; |
990
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1811 |
data->pdo_pos = pdo_pos; |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1812 |
|
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1813 |
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
|
1814 |
stringstream err; |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1815 |
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
|
1816 |
throw MasterException(err.str()); |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1817 |
} |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1818 |
} |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1819 |
|
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1820 |
/****************************************************************************/ |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1821 |
|
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1822 |
void Master::getConfigPdoEntry( |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1823 |
ec_ioctl_config_pdo_entry_t *data, |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1824 |
unsigned int index, |
1055
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1825 |
uint8_t sync_index, |
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1826 |
uint16_t pdo_pos, |
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1827 |
uint8_t entry_pos |
990
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1828 |
) |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1829 |
{ |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1830 |
data->config_index = index; |
1055
2be8918682fa
Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1831 |
data->sync_index = sync_index; |
990
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1832 |
data->pdo_pos = pdo_pos; |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1833 |
data->entry_pos = entry_pos; |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1834 |
|
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1835 |
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
|
1836 |
stringstream err; |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1837 |
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
|
1838 |
throw MasterException(err.str()); |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1839 |
} |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1840 |
} |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1841 |
|
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1842 |
/****************************************************************************/ |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1843 |
|
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1844 |
void Master::getConfigSdo( |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1845 |
ec_ioctl_config_sdo_t *data, |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1846 |
unsigned int index, |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1847 |
unsigned int sdo_pos |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1848 |
) |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1849 |
{ |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1850 |
data->config_index = index; |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1851 |
data->sdo_pos = sdo_pos; |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1852 |
|
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1853 |
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
|
1854 |
stringstream err; |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1855 |
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
|
1856 |
throw MasterException(err.str()); |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1857 |
} |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1858 |
} |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1859 |
|
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1860 |
/****************************************************************************/ |
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1861 |
|
948
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1862 |
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
|
1863 |
{ |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1864 |
data->index = index; |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1865 |
|
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1866 |
if (ioctl(fd, EC_IOCTL_DOMAIN, data)) { |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1867 |
stringstream err; |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1868 |
err << "Failed to get domain: "; |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1869 |
if (errno == EINVAL) |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1870 |
err << "Domain " << index << " does not exist!"; |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1871 |
else |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1872 |
err << strerror(errno); |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1873 |
throw MasterException(err.str()); |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1874 |
} |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1875 |
} |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1876 |
|
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1877 |
/****************************************************************************/ |
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1878 |
|
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1879 |
void Master::getData(ec_ioctl_domain_data_t *data, unsigned int domainIndex, |
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1880 |
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
|
1881 |
{ |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1882 |
data->domain_index = domainIndex; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1883 |
data->data_size = dataSize; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1884 |
data->target = mem; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1885 |
|
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1886 |
if (ioctl(fd, EC_IOCTL_DOMAIN_DATA, data) < 0) { |
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1887 |
stringstream err; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1888 |
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
|
1889 |
throw MasterException(err.str()); |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1890 |
} |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1891 |
} |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1892 |
|
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1893 |
/****************************************************************************/ |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1894 |
|
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1895 |
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
|
1896 |
{ |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1897 |
slave->position = slaveIndex; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1898 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1899 |
if (ioctl(fd, EC_IOCTL_SLAVE, slave)) { |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1900 |
stringstream err; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1901 |
err << "Failed to get slave: "; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1902 |
if (errno == EINVAL) |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1903 |
err << "Slave " << slaveIndex << " does not exist!"; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1904 |
else |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1905 |
err << strerror(errno); |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1906 |
throw MasterException(err.str()); |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1907 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1908 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1909 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1910 |
/****************************************************************************/ |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1911 |
|
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1912 |
void Master::getFmmu( |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1913 |
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
|
1914 |
unsigned int domainIndex, |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1915 |
unsigned int fmmuIndex |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1916 |
) |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1917 |
{ |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1918 |
fmmu->domain_index = domainIndex; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1919 |
fmmu->fmmu_index = fmmuIndex; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1920 |
|
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1921 |
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
|
1922 |
stringstream err; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1923 |
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
|
1924 |
if (errno == EINVAL) |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1925 |
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
|
1926 |
<< "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
|
1927 |
<< " FMMus!"; |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1928 |
else |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1929 |
err << strerror(errno); |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1930 |
throw MasterException(err.str()); |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1931 |
} |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1932 |
} |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1933 |
|
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1934 |
/****************************************************************************/ |
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1935 |
|
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1936 |
void Master::getSync( |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1937 |
ec_ioctl_slave_sync_t *sync, |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1938 |
uint16_t slaveIndex, |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1939 |
uint8_t syncIndex |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1940 |
) |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1941 |
{ |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1942 |
sync->slave_position = slaveIndex; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1943 |
sync->sync_index = syncIndex; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1944 |
|
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1945 |
if (ioctl(fd, EC_IOCTL_SLAVE_SYNC, sync)) { |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1946 |
stringstream err; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1947 |
err << "Failed to get sync manager: "; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1948 |
if (errno == EINVAL) |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1949 |
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
|
1950 |
<< "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
|
1951 |
<< " sync managers!"; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1952 |
else |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1953 |
err << strerror(errno); |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1954 |
throw MasterException(err.str()); |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1955 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1956 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1957 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1958 |
/****************************************************************************/ |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1959 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1960 |
void Master::getPdo( |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1961 |
ec_ioctl_slave_sync_pdo_t *pdo, |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1962 |
uint16_t slaveIndex, |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1963 |
uint8_t syncIndex, |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1964 |
uint8_t pdoPos |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1965 |
) |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1966 |
{ |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1967 |
pdo->slave_position = slaveIndex; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1968 |
pdo->sync_index = syncIndex; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1969 |
pdo->pdo_pos = pdoPos; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1970 |
|
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1971 |
if (ioctl(fd, EC_IOCTL_SLAVE_SYNC_PDO, pdo)) { |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1972 |
stringstream err; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1973 |
err << "Failed to get Pdo: "; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1974 |
if (errno == EINVAL) |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1975 |
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
|
1976 |
<< "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
|
1977 |
<< " sync managers, or sync manager " |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1978 |
<< (unsigned int) syncIndex << " contains less than " |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1979 |
<< pdoPos + 1 << " Pdos!" << endl; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1980 |
else |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1981 |
err << strerror(errno); |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1982 |
throw MasterException(err.str()); |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1983 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1984 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1985 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1986 |
/****************************************************************************/ |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1987 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1988 |
void Master::getPdoEntry( |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
1989 |
ec_ioctl_slave_sync_pdo_entry_t *entry, |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1990 |
uint16_t slaveIndex, |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1991 |
uint8_t syncIndex, |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1992 |
uint8_t pdoPos, |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1993 |
uint8_t entryPos |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1994 |
) |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1995 |
{ |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1996 |
entry->slave_position = slaveIndex; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1997 |
entry->sync_index = syncIndex; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1998 |
entry->pdo_pos = pdoPos; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1999 |
entry->entry_pos = entryPos; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2000 |
|
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
2001 |
if (ioctl(fd, EC_IOCTL_SLAVE_SYNC_PDO_ENTRY, entry)) { |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2002 |
stringstream err; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2003 |
err << "Failed to get Pdo entry: "; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2004 |
if (errno == EINVAL) |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2005 |
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
|
2006 |
<< "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
|
2007 |
<< " sync managers, or sync manager " |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2008 |
<< (unsigned int) syncIndex << " contains less than " |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2009 |
<< 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
|
2010 |
<< " contains less than " << (unsigned int) entryPos + 1 |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2011 |
<< " entries!" << endl; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2012 |
else |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2013 |
err << strerror(errno); |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2014 |
throw MasterException(err.str()); |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2015 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2016 |
} |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2017 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2018 |
/****************************************************************************/ |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2019 |
|
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2020 |
void Master::getSdo( |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
2021 |
ec_ioctl_slave_sdo_t *sdo, |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2022 |
uint16_t slaveIndex, |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2023 |
uint16_t sdoPosition |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2024 |
) |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2025 |
{ |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2026 |
sdo->slave_position = slaveIndex; |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2027 |
sdo->sdo_position = sdoPosition; |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2028 |
|
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
2029 |
if (ioctl(fd, EC_IOCTL_SLAVE_SDO, sdo)) { |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2030 |
stringstream err; |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2031 |
err << "Failed to get Sdo: "; |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2032 |
if (errno == EINVAL) |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2033 |
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
|
2034 |
<< "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
|
2035 |
<< endl; |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2036 |
else |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2037 |
err << strerror(errno); |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2038 |
throw MasterException(err.str()); |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2039 |
} |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2040 |
} |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2041 |
|
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2042 |
/****************************************************************************/ |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2043 |
|
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2044 |
void Master::getSdoEntry( |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
2045 |
ec_ioctl_slave_sdo_entry_t *entry, |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2046 |
uint16_t slaveIndex, |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2047 |
int sdoSpec, |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2048 |
uint8_t entrySubindex |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2049 |
) |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2050 |
{ |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2051 |
entry->slave_position = slaveIndex; |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2052 |
entry->sdo_spec = sdoSpec; |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2053 |
entry->sdo_entry_subindex = entrySubindex; |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2054 |
|
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1073
diff
changeset
|
2055 |
if (ioctl(fd, EC_IOCTL_SLAVE_SDO_ENTRY, entry)) { |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2056 |
stringstream err; |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2057 |
err << "Failed to get Sdo entry: "; |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2058 |
err << strerror(errno); |
965
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2059 |
throw MasterException(err.str()); |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2060 |
} |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2061 |
} |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2062 |
|
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2063 |
/****************************************************************************/ |
1aee4aa1def3
Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents:
960
diff
changeset
|
2064 |
|
960
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
2065 |
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
|
2066 |
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
|
2067 |
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
|
2068 |
) |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
2069 |
{ |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
2070 |
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
|
2071 |
|
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
2072 |
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
|
2073 |
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
|
2074 |
|
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
2075 |
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
|
2076 |
stringstream err; |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
2077 |
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
|
2078 |
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
|
2079 |
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
|
2080 |
else |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
2081 |
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
|
2082 |
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
|
2083 |
} |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
2084 |
} |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
2085 |
|
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
2086 |
/****************************************************************************/ |
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
2087 |
|
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
2088 |
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
|
2089 |
{ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2090 |
switch (state) { |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2091 |
case 1: return "INIT"; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2092 |
case 2: return "PREOP"; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2093 |
case 4: return "SAFEOP"; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2094 |
case 8: return "OP"; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2095 |
default: return "???"; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2096 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2097 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2098 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2099 |
/****************************************************************************/ |
968
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2100 |
|
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2101 |
void Master::printRawData( |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2102 |
const uint8_t *data, |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2103 |
unsigned int size) |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2104 |
{ |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2105 |
cout << hex << setfill('0'); |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2106 |
while (size--) { |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2107 |
cout << "0x" << setw(2) << (unsigned int) *data++; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2108 |
if (size) |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2109 |
cout << " "; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2110 |
} |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2111 |
cout << endl; |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2112 |
} |
b0e894257743
Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents:
966
diff
changeset
|
2113 |
|
980
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2114 |
/*****************************************************************************/ |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2115 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2116 |
/** |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2117 |
* 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
|
2118 |
* |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2119 |
* 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
|
2120 |
* 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
|
2121 |
* |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2122 |
* 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
|
2123 |
* 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
|
2124 |
* |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2125 |
* ./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
|
2126 |
* --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
|
2127 |
* |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2128 |
* \return CRC8 |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2129 |
*/ |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2130 |
uint8_t Master::calcSiiCrc( |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2131 |
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
|
2132 |
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
|
2133 |
) |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2134 |
{ |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2135 |
unsigned int i; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2136 |
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
|
2137 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2138 |
while (length--) { |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2139 |
byte = *data++; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2140 |
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
|
2141 |
bit = crc & 0x80; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2142 |
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
|
2143 |
if (bit) crc ^= 0x07; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2144 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2145 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2146 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2147 |
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
|
2148 |
bit = crc & 0x80; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2149 |
crc <<= 1; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2150 |
if (bit) crc ^= 0x07; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2151 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2152 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2153 |
return crc; |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2154 |
} |
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2155 |
|
c07dd38243ba
Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents:
978
diff
changeset
|
2156 |
/*****************************************************************************/ |