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