235 } |
236 } |
236 } |
237 } |
237 |
238 |
238 /****************************************************************************/ |
239 /****************************************************************************/ |
239 |
240 |
|
241 struct SlaveInfo { |
|
242 string pos; |
|
243 string alias; |
|
244 string relPos; |
|
245 string state; |
|
246 string flag; |
|
247 string name; |
|
248 }; |
|
249 |
240 void Master::listSlaves() |
250 void Master::listSlaves() |
241 { |
251 { |
242 unsigned int numSlaves, i; |
252 unsigned int numSlaves, i; |
243 ec_ioctl_slave_t slave; |
253 ec_ioctl_slave_t slave; |
244 uint16_t lastAlias, aliasIndex; |
254 uint16_t lastAlias, aliasIndex; |
|
255 SlaveInfo slaveInfo; |
|
256 typedef list<SlaveInfo> SlaveInfoList; |
|
257 SlaveInfoList slaveInfoList; |
|
258 SlaveInfoList::const_iterator iter; |
|
259 stringstream str; |
|
260 unsigned int maxPosWidth = 0, maxAliasWidth = 0, |
|
261 maxRelPosWidth = 0, maxStateWidth = 0; |
245 |
262 |
246 open(Read); |
263 open(Read); |
247 |
264 |
248 numSlaves = slaveCount(); |
265 numSlaves = slaveCount(); |
249 |
266 |
250 lastAlias = 0; |
267 lastAlias = 0; |
251 aliasIndex = 0; |
268 aliasIndex = 0; |
252 for (i = 0; i < numSlaves; i++) { |
269 for (i = 0; i < numSlaves; i++) { |
253 getSlave(&slave, i); |
270 getSlave(&slave, i); |
254 cout << setfill(' ') << setw(2) << i << " "; |
271 |
|
272 str << dec << i; |
|
273 slaveInfo.pos = str.str(); |
|
274 str.clear(); |
|
275 str.str(""); |
255 |
276 |
256 if (slave.alias) { |
277 if (slave.alias) { |
257 lastAlias = slave.alias; |
278 lastAlias = slave.alias; |
258 aliasIndex = 0; |
279 aliasIndex = 0; |
259 } |
280 } |
260 if (lastAlias) { |
281 if (lastAlias) { |
261 cout << "#" |
282 str << "#" << hex << lastAlias; |
262 << hex << setfill('0') << setw(4) << lastAlias |
283 slaveInfo.alias = str.str(); |
263 << ":" << dec << aliasIndex; |
284 str.str(""); |
|
285 str << ":" << dec << aliasIndex; |
|
286 slaveInfo.relPos = str.str(); |
|
287 str.str(""); |
264 aliasIndex++; |
288 aliasIndex++; |
265 } |
289 } else { |
266 |
290 slaveInfo.alias = ""; |
267 cout << " " << slaveState(slave.state) |
291 slaveInfo.relPos = ""; |
268 << " " << (slave.error_flag ? 'E' : '+') << " "; |
292 } |
|
293 |
|
294 slaveInfo.state = slaveState(slave.state); |
|
295 slaveInfo.flag = (slave.error_flag ? 'E' : '+'); |
269 |
296 |
270 if (strlen(slave.name)) { |
297 if (strlen(slave.name)) { |
271 cout << slave.name; |
298 slaveInfo.name = slave.name; |
272 } else { |
299 } else { |
273 cout << hex << setfill('0') |
300 str << hex << setfill('0') |
274 << setw(8) << slave.vendor_id << ":" |
301 << setw(8) << slave.vendor_id << ":" |
275 << setw(8) << slave.product_code << dec; |
302 << setw(8) << slave.product_code; |
276 } |
303 slaveInfo.name = str.str(); |
277 |
304 str.str(""); |
278 cout << endl; |
305 } |
|
306 |
|
307 slaveInfoList.push_back(slaveInfo); |
|
308 if (slaveInfo.pos.length() > maxPosWidth) |
|
309 maxPosWidth = slaveInfo.pos.length(); |
|
310 if (slaveInfo.alias.length() > maxAliasWidth) |
|
311 maxAliasWidth = slaveInfo.alias.length(); |
|
312 if (slaveInfo.relPos.length() > maxRelPosWidth) |
|
313 maxRelPosWidth = slaveInfo.relPos.length(); |
|
314 if (slaveInfo.state.length() > maxStateWidth) |
|
315 maxStateWidth = slaveInfo.state.length(); |
|
316 } |
|
317 |
|
318 for (iter = slaveInfoList.begin(); iter != slaveInfoList.end(); iter++) { |
|
319 cout << setfill(' ') << right |
|
320 << setw(maxPosWidth) << iter->pos << " " |
|
321 << setw(maxAliasWidth) << iter->alias |
|
322 << left |
|
323 << setw(maxRelPosWidth) << iter->relPos << " " |
|
324 << setw(maxStateWidth) << iter->state << " " |
|
325 << iter->flag << " " |
|
326 << iter->name << endl; |
279 } |
327 } |
280 } |
328 } |
281 |
329 |
282 /****************************************************************************/ |
330 /****************************************************************************/ |
283 |
331 |