author | Florian Pose <fp@igh-essen.com> |
Wed, 18 Feb 2009 13:47:08 +0000 | |
changeset 1355 | df9be2b80b9a |
parent 1337 | 0253c74d0940 |
child 1363 | 11c0b2caa253 |
permissions | -rw-r--r-- |
1142 | 1 |
/***************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
5 |
****************************************************************************/ |
|
6 |
||
7 |
#include <iostream> |
|
8 |
#include <iomanip> |
|
9 |
#include <list> |
|
1222
7348d6abb6cb
Applied patch by Karsten Schwinne, adding a few header files necessary
Florian Pose <fp@igh-essen.com>
parents:
1220
diff
changeset
|
10 |
#include <string.h> |
1142 | 11 |
using namespace std; |
12 |
||
13 |
#include "CommandSlaves.h" |
|
14 |
||
15 |
/*****************************************************************************/ |
|
16 |
||
17 |
CommandSlaves::CommandSlaves(): |
|
18 |
Command("slaves", "Display slaves on the bus.") |
|
19 |
{ |
|
20 |
} |
|
21 |
||
22 |
/*****************************************************************************/ |
|
23 |
||
24 |
string CommandSlaves::helpString() const |
|
25 |
{ |
|
26 |
stringstream str; |
|
27 |
||
28 |
str << getName() << " [OPTIONS]" << endl |
|
29 |
<< endl |
|
30 |
<< getBriefDescription() << endl |
|
31 |
<< endl |
|
32 |
<< "If the --verbose option is not given, the slaves are" << endl |
|
33 |
<< "displayed one-per-line. Example:" << endl |
|
34 |
<< endl |
|
35 |
<< "1 5555:0 PREOP + EL3162 2C. Ana. Input 0-10V" << endl |
|
36 |
<< "| | | | | |" << endl |
|
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
37 |
<< "| | | | | \\- Name from the SII if avaliable," << endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
38 |
<< "| | | | | otherwise vendor ID and product" << endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
39 |
<< "| | | | | code (both hexadecimal)." << endl |
1142 | 40 |
<< "| | | | \\- Error flag. '+' means no error," << endl |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
41 |
<< "| | | | 'E' means that scan or" << endl |
1142 | 42 |
<< "| | | | configuration failed." << endl |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
43 |
<< "| | | \\- Current application-layer state." << endl |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
44 |
<< "| | \\- Decimal relative position to the last" << endl |
1142 | 45 |
<< "| | slave with an alias address set." << endl |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
46 |
<< "| \\- Decimal alias address of this slave (if set)," << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
47 |
<< "| otherwise of the last slave with an alias set," << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
48 |
<< "| or zero, if no alias was encountered up to this" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
49 |
<< "| position." << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
50 |
<< "\\- Absolute ring position in the bus." << endl |
1142 | 51 |
<< endl |
52 |
<< "If the --verbose option is given, a detailed (multi-line)" << endl |
|
53 |
<< "description is output for each slave." << endl |
|
54 |
<< endl |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
55 |
<< "Slave selection:" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
56 |
<< " Slaves for this and other commands can be selected with" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
57 |
<< " the --alias and --position parameters as follows:" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
58 |
<< endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
59 |
<< " 1) If neither the --alias nor the --position option" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
60 |
<< " is given, all slaves are selected." << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
61 |
<< " 2) If only the --position option is given, it is" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
62 |
<< " interpreted as an absolute ring position and" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
63 |
<< " a slave with this position is matched." << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
64 |
<< " 3) If only the --alias option is given, all slaves" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
65 |
<< " with the given alias address and subsequent" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
66 |
<< " slaves before a slave with a different alias" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
67 |
<< " address match (use -p0 if only the slaves" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
68 |
<< " with the given alias are desired, see 4))." << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
69 |
<< " 4) If both the --alias and the --position option are" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
70 |
<< " given, the latter is interpreted as relative" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
71 |
<< " position behind any slave with the given alias." << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
72 |
<< endl |
1142 | 73 |
<< "Command-specific options:" << endl |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
74 |
<< " --alias -a <alias> Slave alias (see above)." << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
75 |
<< " --position -p <pos> Slave position (see above)." << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
76 |
<< " --verbose -v Show detailed slave information." << endl |
1142 | 77 |
<< endl |
78 |
<< numericInfo(); |
|
79 |
||
80 |
return str.str(); |
|
81 |
} |
|
82 |
||
83 |
/****************************************************************************/ |
|
84 |
||
85 |
void CommandSlaves::execute(MasterDevice &m, const StringVector &args) |
|
86 |
{ |
|
1151 | 87 |
SlaveList slaves; |
88 |
||
1142 | 89 |
m.open(MasterDevice::Read); |
1151 | 90 |
slaves = selectedSlaves(m); |
1142 | 91 |
|
92 |
if (getVerbosity() == Verbose) { |
|
1151 | 93 |
showSlaves(m, slaves); |
1142 | 94 |
} else { |
1151 | 95 |
listSlaves(m, slaves); |
1142 | 96 |
} |
97 |
} |
|
98 |
||
99 |
/****************************************************************************/ |
|
100 |
||
101 |
void CommandSlaves::listSlaves( |
|
102 |
MasterDevice &m, |
|
1151 | 103 |
const SlaveList &slaves |
1142 | 104 |
) |
105 |
{ |
|
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
106 |
ec_ioctl_master_t master; |
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
107 |
unsigned int i; |
1142 | 108 |
ec_ioctl_slave_t slave; |
109 |
uint16_t lastAlias, aliasIndex; |
|
110 |
Info info; |
|
111 |
typedef list<Info> InfoList; |
|
112 |
InfoList infoList; |
|
113 |
InfoList::const_iterator iter; |
|
114 |
stringstream str; |
|
115 |
unsigned int maxPosWidth = 0, maxAliasWidth = 0, |
|
116 |
maxRelPosWidth = 0, maxStateWidth = 0; |
|
117 |
||
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
118 |
m.getMaster(&master); |
1142 | 119 |
|
120 |
lastAlias = 0; |
|
121 |
aliasIndex = 0; |
|
1160
f02ff486b313
Removed MasterDevice::slaveCount().
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
122 |
for (i = 0; i < master.slave_count; i++) { |
1142 | 123 |
m.getSlave(&slave, i); |
124 |
||
125 |
if (slave.alias) { |
|
126 |
lastAlias = slave.alias; |
|
127 |
aliasIndex = 0; |
|
128 |
} |
|
129 |
||
1151 | 130 |
if (slaveInList(slave, slaves)) { |
1142 | 131 |
str << dec << i; |
132 |
info.pos = str.str(); |
|
133 |
str.clear(); |
|
134 |
str.str(""); |
|
135 |
||
136 |
str << lastAlias; |
|
137 |
info.alias = str.str(); |
|
138 |
str.str(""); |
|
139 |
||
140 |
str << aliasIndex; |
|
141 |
info.relPos = str.str(); |
|
142 |
str.str(""); |
|
143 |
||
1148
1762296870bd
Renamed state field to al_state.
Florian Pose <fp@igh-essen.com>
parents:
1146
diff
changeset
|
144 |
info.state = alStateString(slave.al_state); |
1142 | 145 |
info.flag = (slave.error_flag ? 'E' : '+'); |
146 |
||
147 |
if (strlen(slave.name)) { |
|
148 |
info.name = slave.name; |
|
149 |
} else { |
|
150 |
str << "0x" << hex << setfill('0') |
|
151 |
<< setw(8) << slave.vendor_id << ":0x" |
|
152 |
<< setw(8) << slave.product_code; |
|
153 |
info.name = str.str(); |
|
154 |
str.str(""); |
|
155 |
} |
|
156 |
||
157 |
||
158 |
infoList.push_back(info); |
|
159 |
||
160 |
if (info.pos.length() > maxPosWidth) |
|
161 |
maxPosWidth = info.pos.length(); |
|
162 |
if (info.alias.length() > maxAliasWidth) |
|
163 |
maxAliasWidth = info.alias.length(); |
|
164 |
if (info.relPos.length() > maxRelPosWidth) |
|
165 |
maxRelPosWidth = info.relPos.length(); |
|
166 |
if (info.state.length() > maxStateWidth) |
|
167 |
maxStateWidth = info.state.length(); |
|
168 |
} |
|
169 |
||
170 |
aliasIndex++; |
|
171 |
} |
|
172 |
||
173 |
for (iter = infoList.begin(); iter != infoList.end(); iter++) { |
|
174 |
cout << setfill(' ') << right |
|
175 |
<< setw(maxPosWidth) << iter->pos << " " |
|
176 |
<< setw(maxAliasWidth) << iter->alias |
|
177 |
<< ":" << left |
|
178 |
<< setw(maxRelPosWidth) << iter->relPos << " " |
|
179 |
<< setw(maxStateWidth) << iter->state << " " |
|
180 |
<< iter->flag << " " |
|
181 |
<< iter->name << endl; |
|
182 |
} |
|
183 |
} |
|
184 |
||
185 |
/****************************************************************************/ |
|
186 |
||
1151 | 187 |
void CommandSlaves::showSlaves( |
1142 | 188 |
MasterDevice &m, |
1151 | 189 |
const SlaveList &slaves |
1142 | 190 |
) |
191 |
{ |
|
1151 | 192 |
SlaveList::const_iterator si; |
193 |
||
194 |
for (si = slaves.begin(); si != slaves.end(); si++) { |
|
195 |
cout << "=== Slave " << dec << si->position << " ===" << endl; |
|
196 |
||
197 |
if (si->alias) |
|
198 |
cout << "Alias: " << si->alias << endl; |
|
199 |
||
200 |
cout |
|
201 |
<< "State: " << alStateString(si->al_state) << endl |
|
202 |
<< "Flag: " << (si->error_flag ? 'E' : '+') << endl |
|
203 |
<< "Identity:" << endl |
|
204 |
<< " Vendor Id: 0x" |
|
205 |
<< hex << setfill('0') |
|
206 |
<< setw(8) << si->vendor_id << endl |
|
207 |
<< " Product code: 0x" |
|
208 |
<< setw(8) << si->product_code << endl |
|
209 |
<< " Revision number: 0x" |
|
210 |
<< setw(8) << si->revision_number << endl |
|
211 |
<< " Serial number: 0x" |
|
212 |
<< setw(8) << si->serial_number << endl; |
|
213 |
||
214 |
if (si->mailbox_protocols) { |
|
1220
15e8768b304f
Fixed minor supported mailbox protocol display bug.
Florian Pose <fp@igh-essen.com>
parents:
1160
diff
changeset
|
215 |
list<string> protoList; |
15e8768b304f
Fixed minor supported mailbox protocol display bug.
Florian Pose <fp@igh-essen.com>
parents:
1160
diff
changeset
|
216 |
list<string>::const_iterator protoIter; |
15e8768b304f
Fixed minor supported mailbox protocol display bug.
Florian Pose <fp@igh-essen.com>
parents:
1160
diff
changeset
|
217 |
|
1151 | 218 |
cout << "Mailboxes:" << endl |
1337
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
219 |
<< " Bootstrap RX: 0x" |
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
220 |
<< hex << setw(4) << si->boot_rx_mailbox_offset << "/" |
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
221 |
<< dec << si->boot_rx_mailbox_size |
1151 | 222 |
<< ", TX: 0x" |
1337
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
223 |
<< hex << setw(4) << si->boot_tx_mailbox_offset << "/" |
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
224 |
<< dec << si->boot_tx_mailbox_size << endl |
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
225 |
<< " Standard RX: 0x" |
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
226 |
<< hex << setw(4) << si->std_rx_mailbox_offset << "/" |
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
227 |
<< dec << si->std_rx_mailbox_size |
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
228 |
<< ", TX: 0x" |
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
229 |
<< hex << setw(4) << si->std_tx_mailbox_offset << "/" |
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
230 |
<< dec << si->std_tx_mailbox_size << endl |
1151 | 231 |
<< " Supported protocols: "; |
232 |
||
233 |
if (si->mailbox_protocols & EC_MBOX_AOE) { |
|
234 |
protoList.push_back("AoE"); |
|
235 |
} |
|
236 |
if (si->mailbox_protocols & EC_MBOX_EOE) { |
|
237 |
protoList.push_back("EoE"); |
|
238 |
} |
|
239 |
if (si->mailbox_protocols & EC_MBOX_COE) { |
|
240 |
protoList.push_back("CoE"); |
|
241 |
} |
|
242 |
if (si->mailbox_protocols & EC_MBOX_FOE) { |
|
243 |
protoList.push_back("FoE"); |
|
244 |
} |
|
245 |
if (si->mailbox_protocols & EC_MBOX_SOE) { |
|
246 |
protoList.push_back("SoE"); |
|
247 |
} |
|
248 |
if (si->mailbox_protocols & EC_MBOX_VOE) { |
|
249 |
protoList.push_back("VoE"); |
|
250 |
} |
|
251 |
||
252 |
for (protoIter = protoList.begin(); protoIter != protoList.end(); |
|
253 |
protoIter++) { |
|
254 |
if (protoIter != protoList.begin()) |
|
255 |
cout << ", "; |
|
256 |
cout << *protoIter; |
|
257 |
} |
|
258 |
cout << endl; |
|
259 |
} |
|
260 |
||
261 |
if (si->has_general_category) { |
|
262 |
cout << "General:" << endl |
|
263 |
<< " Group: " << si->group << endl |
|
264 |
<< " Image name: " << si->image << endl |
|
265 |
<< " Order number: " << si->order << endl |
|
266 |
<< " Device name: " << si->name << endl; |
|
267 |
||
268 |
if (si->mailbox_protocols & EC_MBOX_COE) { |
|
269 |
cout << " CoE details:" << endl |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1222
diff
changeset
|
270 |
<< " Enable SDO: " |
1151 | 271 |
<< (si->coe_details.enable_sdo ? "yes" : "no") << endl |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1222
diff
changeset
|
272 |
<< " Enable SDO Info: " |
1151 | 273 |
<< (si->coe_details.enable_sdo_info ? "yes" : "no") << endl |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1222
diff
changeset
|
274 |
<< " Enable PDO Assign: " |
1151 | 275 |
<< (si->coe_details.enable_pdo_assign |
276 |
? "yes" : "no") << endl |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1222
diff
changeset
|
277 |
<< " Enable PDO Configuration: " |
1151 | 278 |
<< (si->coe_details.enable_pdo_configuration |
279 |
? "yes" : "no") << endl |
|
280 |
<< " Enable Upload at startup: " |
|
281 |
<< (si->coe_details.enable_upload_at_startup |
|
282 |
? "yes" : "no") << endl |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1222
diff
changeset
|
283 |
<< " Enable SDO complete access: " |
1151 | 284 |
<< (si->coe_details.enable_sdo_complete_access |
285 |
? "yes" : "no") << endl; |
|
286 |
} |
|
287 |
||
288 |
cout << " Flags:" << endl |
|
289 |
<< " Enable SafeOp: " |
|
290 |
<< (si->general_flags.enable_safeop ? "yes" : "no") << endl |
|
291 |
<< " Enable notLRW: " |
|
292 |
<< (si->general_flags.enable_not_lrw ? "yes" : "no") << endl |
|
293 |
<< " Current consumption: " |
|
294 |
<< dec << si->current_on_ebus << " mA" << endl; |
|
295 |
} |
|
296 |
} |
|
297 |
} |
|
298 |
||
299 |
/****************************************************************************/ |
|
300 |
||
301 |
bool CommandSlaves::slaveInList( |
|
302 |
const ec_ioctl_slave_t &slave, |
|
303 |
const SlaveList &slaves |
|
304 |
) |
|
305 |
{ |
|
306 |
SlaveList::const_iterator si; |
|
307 |
||
308 |
for (si = slaves.begin(); si != slaves.end(); si++) { |
|
309 |
if (si->position == slave.position) { |
|
310 |
return true; |
|
311 |
} |
|
312 |
} |
|
313 |
||
314 |
return false; |
|
1142 | 315 |
} |
316 |
||
317 |
/*****************************************************************************/ |