author | Florian Pose <fp@igh-essen.com> |
Wed, 05 Nov 2008 10:36:18 +0000 | |
branch | stable-1.4 |
changeset 1657 | 3dbdb7392d7b |
parent 1636 | b26170e168d9 |
child 1327 | 4d179b06dd3c |
permissions | -rw-r--r-- |
1142 | 1 |
/***************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
5 |
****************************************************************************/ |
|
6 |
||
7 |
#include <iostream> |
|
8 |
#include <iomanip> |
|
9 |
#include <list> |
|
1636
b26170e168d9
merge -c1452 trunk: Headers.
Florian Pose <fp@igh-essen.com>
parents:
1634
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) { |
|
1634
ae4c73f4c56d
merge -r1446:1448 trunk: Plugfest6 fixes.
Florian Pose <fp@igh-essen.com>
parents:
1160
diff
changeset
|
215 |
list<string> protoList; |
ae4c73f4c56d
merge -r1446:1448 trunk: Plugfest6 fixes.
Florian Pose <fp@igh-essen.com>
parents:
1160
diff
changeset
|
216 |
list<string>::const_iterator protoIter; |
ae4c73f4c56d
merge -r1446:1448 trunk: Plugfest6 fixes.
Florian Pose <fp@igh-essen.com>
parents:
1160
diff
changeset
|
217 |
|
1151 | 218 |
cout << "Mailboxes:" << endl |
219 |
<< " RX: 0x" |
|
220 |
<< hex << setw(4) << si->rx_mailbox_offset << "/" |
|
221 |
<< dec << si->rx_mailbox_size |
|
222 |
<< ", TX: 0x" |
|
223 |
<< hex << setw(4) << si->tx_mailbox_offset << "/" |
|
224 |
<< dec << si->tx_mailbox_size << endl |
|
225 |
<< " Supported protocols: "; |
|
226 |
||
227 |
if (si->mailbox_protocols & EC_MBOX_AOE) { |
|
228 |
protoList.push_back("AoE"); |
|
229 |
} |
|
230 |
if (si->mailbox_protocols & EC_MBOX_EOE) { |
|
231 |
protoList.push_back("EoE"); |
|
232 |
} |
|
233 |
if (si->mailbox_protocols & EC_MBOX_COE) { |
|
234 |
protoList.push_back("CoE"); |
|
235 |
} |
|
236 |
if (si->mailbox_protocols & EC_MBOX_FOE) { |
|
237 |
protoList.push_back("FoE"); |
|
238 |
} |
|
239 |
if (si->mailbox_protocols & EC_MBOX_SOE) { |
|
240 |
protoList.push_back("SoE"); |
|
241 |
} |
|
242 |
if (si->mailbox_protocols & EC_MBOX_VOE) { |
|
243 |
protoList.push_back("VoE"); |
|
244 |
} |
|
245 |
||
246 |
for (protoIter = protoList.begin(); protoIter != protoList.end(); |
|
247 |
protoIter++) { |
|
248 |
if (protoIter != protoList.begin()) |
|
249 |
cout << ", "; |
|
250 |
cout << *protoIter; |
|
251 |
} |
|
252 |
cout << endl; |
|
253 |
} |
|
254 |
||
255 |
if (si->has_general_category) { |
|
256 |
cout << "General:" << endl |
|
257 |
<< " Group: " << si->group << endl |
|
258 |
<< " Image name: " << si->image << endl |
|
259 |
<< " Order number: " << si->order << endl |
|
260 |
<< " Device name: " << si->name << endl; |
|
261 |
||
262 |
if (si->mailbox_protocols & EC_MBOX_COE) { |
|
263 |
cout << " CoE details:" << endl |
|
264 |
<< " Enable Sdo: " |
|
265 |
<< (si->coe_details.enable_sdo ? "yes" : "no") << endl |
|
266 |
<< " Enable Sdo Info: " |
|
267 |
<< (si->coe_details.enable_sdo_info ? "yes" : "no") << endl |
|
268 |
<< " Enable Pdo Assign: " |
|
269 |
<< (si->coe_details.enable_pdo_assign |
|
270 |
? "yes" : "no") << endl |
|
271 |
<< " Enable Pdo Configuration: " |
|
272 |
<< (si->coe_details.enable_pdo_configuration |
|
273 |
? "yes" : "no") << endl |
|
274 |
<< " Enable Upload at startup: " |
|
275 |
<< (si->coe_details.enable_upload_at_startup |
|
276 |
? "yes" : "no") << endl |
|
277 |
<< " Enable Sdo complete access: " |
|
278 |
<< (si->coe_details.enable_sdo_complete_access |
|
279 |
? "yes" : "no") << endl; |
|
280 |
} |
|
281 |
||
282 |
cout << " Flags:" << endl |
|
283 |
<< " Enable SafeOp: " |
|
284 |
<< (si->general_flags.enable_safeop ? "yes" : "no") << endl |
|
285 |
<< " Enable notLRW: " |
|
286 |
<< (si->general_flags.enable_not_lrw ? "yes" : "no") << endl |
|
287 |
<< " Current consumption: " |
|
288 |
<< dec << si->current_on_ebus << " mA" << endl; |
|
289 |
} |
|
290 |
} |
|
291 |
} |
|
292 |
||
293 |
/****************************************************************************/ |
|
294 |
||
295 |
bool CommandSlaves::slaveInList( |
|
296 |
const ec_ioctl_slave_t &slave, |
|
297 |
const SlaveList &slaves |
|
298 |
) |
|
299 |
{ |
|
300 |
SlaveList::const_iterator si; |
|
301 |
||
302 |
for (si = slaves.begin(); si != slaves.end(); si++) { |
|
303 |
if (si->position == slave.position) { |
|
304 |
return true; |
|
305 |
} |
|
306 |
} |
|
307 |
||
308 |
return false; |
|
1142 | 309 |
} |
310 |
||
311 |
/*****************************************************************************/ |