author | Florian Pose <fp@igh-essen.com> |
Fri, 25 Jul 2008 14:10:04 +0000 | |
changeset 1149 | f1fce286d53b |
parent 1148 | 1762296870bd |
child 1151 | 1fc1535dec29 |
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 |
1142 | 43 |
<< "| | \\- Relative position (decimal) after the last" << endl |
44 |
<< "| | slave with an alias address set." << endl |
|
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
45 |
<< "| \\- Alias address of the slave (if set), or the alias" << endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
46 |
<< "| of the last slave with an alias, or zero if not" << endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
47 |
<< "| applicable" << endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
48 |
<< "\\- Absolute ring position in the bus (use this with any" << endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
49 |
<< " --slave option)." << 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 |
|
54 |
<< "Command-specific options:" << endl |
|
55 |
<< " --slave -s <index> Positive numerical ring position," << endl |
|
56 |
<< " or 'all' for all slaves (default)." << endl |
|
57 |
<< " --verbose -v Show detailed slave information." << endl |
|
58 |
<< endl |
|
59 |
<< numericInfo(); |
|
60 |
||
61 |
return str.str(); |
|
62 |
} |
|
63 |
||
64 |
/****************************************************************************/ |
|
65 |
||
66 |
void CommandSlaves::execute(MasterDevice &m, const StringVector &args) |
|
67 |
{ |
|
68 |
m.open(MasterDevice::Read); |
|
69 |
||
70 |
if (getVerbosity() == Verbose) { |
|
71 |
if (slavePosition == -1) { |
|
72 |
unsigned int numSlaves = m.slaveCount(), i; |
|
73 |
||
74 |
for (i = 0; i < numSlaves; i++) { |
|
75 |
showSlave(m, i); |
|
76 |
} |
|
77 |
} else { |
|
78 |
showSlave(m, slavePosition); |
|
79 |
} |
|
80 |
} else { |
|
81 |
listSlaves(m, slavePosition); |
|
82 |
} |
|
83 |
} |
|
84 |
||
85 |
/****************************************************************************/ |
|
86 |
||
87 |
void CommandSlaves::listSlaves( |
|
88 |
MasterDevice &m, |
|
89 |
int slavePosition |
|
90 |
) |
|
91 |
{ |
|
92 |
unsigned int numSlaves, i; |
|
93 |
ec_ioctl_slave_t slave; |
|
94 |
uint16_t lastAlias, aliasIndex; |
|
95 |
Info info; |
|
96 |
typedef list<Info> InfoList; |
|
97 |
InfoList infoList; |
|
98 |
InfoList::const_iterator iter; |
|
99 |
stringstream str; |
|
100 |
unsigned int maxPosWidth = 0, maxAliasWidth = 0, |
|
101 |
maxRelPosWidth = 0, maxStateWidth = 0; |
|
102 |
||
103 |
numSlaves = m.slaveCount(); |
|
104 |
||
105 |
lastAlias = 0; |
|
106 |
aliasIndex = 0; |
|
107 |
for (i = 0; i < numSlaves; i++) { |
|
108 |
m.getSlave(&slave, i); |
|
109 |
||
110 |
if (slave.alias) { |
|
111 |
lastAlias = slave.alias; |
|
112 |
aliasIndex = 0; |
|
113 |
} |
|
114 |
||
115 |
if (slavePosition == -1 || i == (unsigned int) slavePosition) { |
|
116 |
str << dec << i; |
|
117 |
info.pos = str.str(); |
|
118 |
str.clear(); |
|
119 |
str.str(""); |
|
120 |
||
121 |
str << lastAlias; |
|
122 |
info.alias = str.str(); |
|
123 |
str.str(""); |
|
124 |
||
125 |
str << aliasIndex; |
|
126 |
info.relPos = str.str(); |
|
127 |
str.str(""); |
|
128 |
||
1148
1762296870bd
Renamed state field to al_state.
Florian Pose <fp@igh-essen.com>
parents:
1146
diff
changeset
|
129 |
info.state = alStateString(slave.al_state); |
1142 | 130 |
info.flag = (slave.error_flag ? 'E' : '+'); |
131 |
||
132 |
if (strlen(slave.name)) { |
|
133 |
info.name = slave.name; |
|
134 |
} else { |
|
135 |
str << "0x" << hex << setfill('0') |
|
136 |
<< setw(8) << slave.vendor_id << ":0x" |
|
137 |
<< setw(8) << slave.product_code; |
|
138 |
info.name = str.str(); |
|
139 |
str.str(""); |
|
140 |
} |
|
141 |
||
142 |
||
143 |
infoList.push_back(info); |
|
144 |
||
145 |
if (info.pos.length() > maxPosWidth) |
|
146 |
maxPosWidth = info.pos.length(); |
|
147 |
if (info.alias.length() > maxAliasWidth) |
|
148 |
maxAliasWidth = info.alias.length(); |
|
149 |
if (info.relPos.length() > maxRelPosWidth) |
|
150 |
maxRelPosWidth = info.relPos.length(); |
|
151 |
if (info.state.length() > maxStateWidth) |
|
152 |
maxStateWidth = info.state.length(); |
|
153 |
} |
|
154 |
||
155 |
aliasIndex++; |
|
156 |
} |
|
157 |
||
158 |
for (iter = infoList.begin(); iter != infoList.end(); iter++) { |
|
159 |
cout << setfill(' ') << right |
|
160 |
<< setw(maxPosWidth) << iter->pos << " " |
|
161 |
<< setw(maxAliasWidth) << iter->alias |
|
162 |
<< ":" << left |
|
163 |
<< setw(maxRelPosWidth) << iter->relPos << " " |
|
164 |
<< setw(maxStateWidth) << iter->state << " " |
|
165 |
<< iter->flag << " " |
|
166 |
<< iter->name << endl; |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
/****************************************************************************/ |
|
171 |
||
172 |
void CommandSlaves::showSlave( |
|
173 |
MasterDevice &m, |
|
174 |
uint16_t slavePosition |
|
175 |
) |
|
176 |
{ |
|
177 |
ec_ioctl_slave_t slave; |
|
178 |
list<string> protoList; |
|
179 |
list<string>::const_iterator protoIter; |
|
180 |
||
181 |
m.getSlave(&slave, slavePosition); |
|
182 |
||
183 |
cout << "=== Slave " << dec << slavePosition << " ===" << endl; |
|
184 |
||
185 |
if (slave.alias) |
|
186 |
cout << "Alias: " << slave.alias << endl; |
|
187 |
||
188 |
cout |
|
1148
1762296870bd
Renamed state field to al_state.
Florian Pose <fp@igh-essen.com>
parents:
1146
diff
changeset
|
189 |
<< "State: " << alStateString(slave.al_state) << endl |
1142 | 190 |
<< "Flag: " << (slave.error_flag ? 'E' : '+') << endl |
191 |
<< "Identity:" << endl |
|
192 |
<< " Vendor Id: 0x" |
|
193 |
<< hex << setfill('0') |
|
194 |
<< setw(8) << slave.vendor_id << endl |
|
195 |
<< " Product code: 0x" |
|
196 |
<< setw(8) << slave.product_code << endl |
|
197 |
<< " Revision number: 0x" |
|
198 |
<< setw(8) << slave.revision_number << endl |
|
199 |
<< " Serial number: 0x" |
|
200 |
<< setw(8) << slave.serial_number << endl; |
|
201 |
||
202 |
if (slave.mailbox_protocols) { |
|
203 |
cout << "Mailboxes:" << endl |
|
204 |
<< " RX: 0x" |
|
205 |
<< hex << setw(4) << slave.rx_mailbox_offset << "/" |
|
206 |
<< dec << slave.rx_mailbox_size |
|
207 |
<< ", TX: 0x" |
|
208 |
<< hex << setw(4) << slave.tx_mailbox_offset << "/" |
|
209 |
<< dec << slave.tx_mailbox_size << endl |
|
210 |
<< " Supported protocols: "; |
|
211 |
||
212 |
if (slave.mailbox_protocols & EC_MBOX_AOE) { |
|
213 |
protoList.push_back("AoE"); |
|
214 |
} |
|
215 |
if (slave.mailbox_protocols & EC_MBOX_EOE) { |
|
216 |
protoList.push_back("EoE"); |
|
217 |
} |
|
218 |
if (slave.mailbox_protocols & EC_MBOX_COE) { |
|
219 |
protoList.push_back("CoE"); |
|
220 |
} |
|
221 |
if (slave.mailbox_protocols & EC_MBOX_FOE) { |
|
222 |
protoList.push_back("FoE"); |
|
223 |
} |
|
224 |
if (slave.mailbox_protocols & EC_MBOX_SOE) { |
|
225 |
protoList.push_back("SoE"); |
|
226 |
} |
|
227 |
if (slave.mailbox_protocols & EC_MBOX_VOE) { |
|
228 |
protoList.push_back("VoE"); |
|
229 |
} |
|
230 |
||
231 |
for (protoIter = protoList.begin(); protoIter != protoList.end(); |
|
232 |
protoIter++) { |
|
233 |
if (protoIter != protoList.begin()) |
|
234 |
cout << ", "; |
|
235 |
cout << *protoIter; |
|
236 |
} |
|
237 |
cout << endl; |
|
238 |
} |
|
239 |
||
240 |
if (slave.has_general_category) { |
|
241 |
cout << "General:" << endl |
|
242 |
<< " Group: " << slave.group << endl |
|
243 |
<< " Image name: " << slave.image << endl |
|
244 |
<< " Order number: " << slave.order << endl |
|
245 |
<< " Device name: " << slave.name << endl; |
|
246 |
||
247 |
if (slave.mailbox_protocols & EC_MBOX_COE) { |
|
248 |
cout << " CoE details:" << endl |
|
249 |
<< " Enable Sdo: " |
|
250 |
<< (slave.coe_details.enable_sdo ? "yes" : "no") << endl |
|
251 |
<< " Enable Sdo Info: " |
|
252 |
<< (slave.coe_details.enable_sdo_info ? "yes" : "no") << endl |
|
253 |
<< " Enable Pdo Assign: " |
|
254 |
<< (slave.coe_details.enable_pdo_assign |
|
255 |
? "yes" : "no") << endl |
|
256 |
<< " Enable Pdo Configuration: " |
|
257 |
<< (slave.coe_details.enable_pdo_configuration |
|
258 |
? "yes" : "no") << endl |
|
259 |
<< " Enable Upload at startup: " |
|
260 |
<< (slave.coe_details.enable_upload_at_startup |
|
261 |
? "yes" : "no") << endl |
|
262 |
<< " Enable Sdo complete access: " |
|
263 |
<< (slave.coe_details.enable_sdo_complete_access |
|
264 |
? "yes" : "no") << endl; |
|
265 |
} |
|
266 |
||
267 |
cout << " Flags:" << endl |
|
268 |
<< " Enable SafeOp: " |
|
269 |
<< (slave.general_flags.enable_safeop ? "yes" : "no") << endl |
|
270 |
<< " Enable notLRW: " |
|
271 |
<< (slave.general_flags.enable_not_lrw ? "yes" : "no") << endl |
|
272 |
<< " Current consumption: " |
|
273 |
<< dec << slave.current_on_ebus << " mA" << endl; |
|
274 |
} |
|
275 |
} |
|
276 |
||
277 |
/*****************************************************************************/ |