author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Sat, 29 Sep 2018 23:58:09 +0200 | |
branch | stable-1.5 |
changeset 2714 | ec417efca1fd |
parent 2421 | bc2d4bf9cbe5 |
permissions | -rw-r--r-- |
1142 | 1 |
/***************************************************************************** |
2 |
* |
|
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
3 |
* $Id$ |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
4 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
6 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
8 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
11 |
* published by the Free Software Foundation. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
12 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
16 |
* Public License for more details. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
17 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
21 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
1142 | 27 |
* |
28 |
****************************************************************************/ |
|
29 |
||
30 |
#include <iostream> |
|
31 |
#include <iomanip> |
|
32 |
using namespace std; |
|
33 |
||
34 |
#include "CommandSiiRead.h" |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
35 |
#include "MasterDevice.h" |
1142 | 36 |
|
37 |
/*****************************************************************************/ |
|
38 |
||
39 |
CommandSiiRead::CommandSiiRead(): |
|
40 |
Command("sii_read", "Output a slave's SII contents.") |
|
41 |
{ |
|
42 |
} |
|
43 |
||
44 |
/*****************************************************************************/ |
|
45 |
||
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1870
diff
changeset
|
46 |
string CommandSiiRead::helpString(const string &binaryBaseName) const |
1142 | 47 |
{ |
48 |
stringstream str; |
|
49 |
||
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1870
diff
changeset
|
50 |
str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl |
1804 | 51 |
<< endl |
52 |
<< getBriefDescription() << endl |
|
53 |
<< endl |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
54 |
<< "This command requires a single slave to be selected." << endl |
1804 | 55 |
<< endl |
56 |
<< "Without the --verbose option, binary SII contents are" << endl |
|
57 |
<< "output." << endl |
|
58 |
<< endl |
|
59 |
<< "With the --verbose option given, a textual representation" << endl |
|
60 |
<< "of the data is output, that is separated by SII category" << endl |
|
61 |
<< "names." << endl |
|
62 |
<< endl |
|
63 |
<< "Command-specific options:" << endl |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
64 |
<< " --alias -a <alias>" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
65 |
<< " --position -p <pos> Slave selection. See the help of" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
66 |
<< " the 'slaves' command." << endl |
1804 | 67 |
<< " --verbose -v Output textual data with" << endl |
68 |
<< " category names." << endl |
|
69 |
<< endl |
|
70 |
<< numericInfo(); |
|
71 |
||
72 |
return str.str(); |
|
1142 | 73 |
} |
74 |
||
75 |
/****************************************************************************/ |
|
76 |
||
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
77 |
void CommandSiiRead::execute(const StringVector &args) |
1142 | 78 |
{ |
1151 | 79 |
SlaveList slaves; |
80 |
ec_ioctl_slave_t *slave; |
|
1142 | 81 |
ec_ioctl_slave_sii_t data; |
82 |
unsigned int i; |
|
83 |
const uint16_t *categoryHeader; |
|
84 |
uint16_t categoryType, categorySize; |
|
85 |
stringstream err; |
|
86 |
||
1373
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
87 |
if (args.size()) { |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
88 |
err << "'" << getName() << "' takes no arguments!"; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
89 |
throwInvalidUsageException(err); |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
90 |
} |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
91 |
|
1870
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
92 |
MasterDevice m(getSingleMasterIndex()); |
1151 | 93 |
m.open(MasterDevice::Read); |
94 |
slaves = selectedSlaves(m); |
|
95 |
||
96 |
if (slaves.size() != 1) { |
|
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
97 |
throwSingleSlaveRequired(slaves.size()); |
1142 | 98 |
} |
1151 | 99 |
slave = &slaves.front(); |
100 |
data.slave_position = slave->position; |
|
1142 | 101 |
|
1151 | 102 |
if (!slave->sii_nwords) |
1142 | 103 |
return; |
104 |
||
105 |
data.offset = 0; |
|
1151 | 106 |
data.nwords = slave->sii_nwords; |
1142 | 107 |
data.words = new uint16_t[data.nwords]; |
108 |
||
1804 | 109 |
try { |
110 |
m.readSii(&data); |
|
111 |
} catch (MasterDeviceException &e) { |
|
1142 | 112 |
delete [] data.words; |
1804 | 113 |
throw e; |
114 |
} |
|
1142 | 115 |
|
116 |
if (getVerbosity() == Verbose) { |
|
117 |
cout << "SII Area:" << hex << setfill('0'); |
|
118 |
for (i = 0; i < min(data.nwords, 0x0040U) * 2; i++) { |
|
119 |
if (i % BreakAfterBytes) { |
|
120 |
cout << " "; |
|
121 |
} else { |
|
122 |
cout << endl << " "; |
|
123 |
} |
|
124 |
cout << setw(2) << (unsigned int) *((uint8_t *) data.words + i); |
|
125 |
} |
|
126 |
cout << endl; |
|
127 |
||
128 |
if (data.nwords > 0x0040U) { |
|
129 |
// cycle through categories |
|
130 |
categoryHeader = data.words + 0x0040U; |
|
1254
c19d273a9e76
Moved byteorder macros to ecrt.h.
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
131 |
categoryType = le16_to_cpup(categoryHeader); |
1142 | 132 |
while (categoryType != 0xffff) { |
133 |
cout << "SII Category 0x" << hex |
|
134 |
<< setw(4) << categoryType |
|
135 |
<< " (" << getCategoryName(categoryType) << ")" << flush; |
|
136 |
||
137 |
if (categoryHeader + 1 > data.words + data.nwords) { |
|
138 |
err << "SII data seem to be corrupted!"; |
|
139 |
throwCommandException(err); |
|
140 |
} |
|
1254
c19d273a9e76
Moved byteorder macros to ecrt.h.
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
141 |
categorySize = le16_to_cpup(categoryHeader + 1); |
1142 | 142 |
cout << ", " << dec << categorySize << " words" << flush; |
143 |
||
144 |
if (categoryHeader + 2 + categorySize |
|
145 |
> data.words + data.nwords) { |
|
146 |
err << "SII data seem to be corrupted!"; |
|
147 |
throwCommandException(err); |
|
148 |
} |
|
149 |
||
150 |
cout << hex; |
|
151 |
for (i = 0; i < categorySize * 2U; i++) { |
|
152 |
if (i % BreakAfterBytes) { |
|
153 |
cout << " "; |
|
154 |
} else { |
|
155 |
cout << endl << " "; |
|
156 |
} |
|
157 |
cout << setw(2) << (unsigned int) |
|
158 |
*((uint8_t *) (categoryHeader + 2) + i); |
|
159 |
} |
|
160 |
cout << endl; |
|
161 |
||
162 |
if (categoryHeader + 2 + categorySize + 1 |
|
163 |
> data.words + data.nwords) { |
|
2421 | 164 |
err << "SII data seem to be corrupted!"; |
1142 | 165 |
throwCommandException(err); |
166 |
} |
|
167 |
categoryHeader += 2 + categorySize; |
|
1254
c19d273a9e76
Moved byteorder macros to ecrt.h.
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
168 |
categoryType = le16_to_cpup(categoryHeader); |
1142 | 169 |
} |
170 |
} |
|
171 |
} else { |
|
172 |
for (i = 0; i < data.nwords; i++) { |
|
173 |
uint16_t *w = data.words + i; |
|
174 |
cout << *(uint8_t *) w << *((uint8_t *) w + 1); |
|
175 |
} |
|
176 |
} |
|
177 |
||
178 |
delete [] data.words; |
|
179 |
} |
|
180 |
||
181 |
/****************************************************************************/ |
|
182 |
||
183 |
const CommandSiiRead::CategoryName CommandSiiRead::categoryNames[] = { |
|
184 |
{0x000a, "STRINGS"}, |
|
185 |
{0x0014, "DataTypes"}, |
|
186 |
{0x001e, "General"}, |
|
187 |
{0x0028, "FMMU"}, |
|
188 |
{0x0029, "SyncM"}, |
|
189 |
{0x0032, "TXPDO"}, |
|
190 |
{0x0033, "RXPDO"}, |
|
191 |
{0x003c, "DC"}, |
|
192 |
{} |
|
193 |
}; |
|
194 |
||
195 |
/****************************************************************************/ |
|
196 |
||
197 |
const char *CommandSiiRead::getCategoryName(uint16_t type) |
|
198 |
{ |
|
199 |
const CategoryName *cn = categoryNames; |
|
200 |
||
201 |
while (cn->type) { |
|
202 |
if (cn->type == type) { |
|
203 |
return cn->name; |
|
204 |
} |
|
205 |
cn++; |
|
206 |
} |
|
207 |
||
208 |
return "unknown"; |
|
209 |
} |
|
210 |
||
211 |
/*****************************************************************************/ |