|
1 /***************************************************************************** |
|
2 * |
|
3 * $Id$ |
|
4 * |
|
5 ****************************************************************************/ |
|
6 |
|
7 #include <iostream> |
|
8 #include <iomanip> |
|
9 #include <list> |
|
10 using namespace std; |
|
11 |
|
12 #include "globals.h" |
|
13 |
|
14 /****************************************************************************/ |
|
15 |
|
16 const char *help_slaves = |
|
17 "[OPTIONS]\n" |
|
18 "\n" |
|
19 "\n" |
|
20 "Command-specific options:\n"; |
|
21 |
|
22 void listSlaves(int); |
|
23 void showSlave(uint16_t); |
|
24 |
|
25 /****************************************************************************/ |
|
26 |
|
27 void command_slaves() |
|
28 { |
|
29 masterDev.open(MasterDevice::Read); |
|
30 |
|
31 if (verbosity == Verbose) { |
|
32 if (slavePosition == -1) { |
|
33 unsigned int numSlaves = masterDev.slaveCount(), i; |
|
34 |
|
35 for (i = 0; i < numSlaves; i++) { |
|
36 showSlave(i); |
|
37 } |
|
38 } else { |
|
39 showSlave(slavePosition); |
|
40 } |
|
41 } else { |
|
42 listSlaves(slavePosition); |
|
43 } |
|
44 } |
|
45 |
|
46 /****************************************************************************/ |
|
47 |
|
48 string slaveState(uint8_t state) |
|
49 { |
|
50 switch (state) { |
|
51 case 1: return "INIT"; |
|
52 case 2: return "PREOP"; |
|
53 case 4: return "SAFEOP"; |
|
54 case 8: return "OP"; |
|
55 default: return "???"; |
|
56 } |
|
57 } |
|
58 |
|
59 /****************************************************************************/ |
|
60 |
|
61 struct SlaveInfo { |
|
62 string pos; |
|
63 string alias; |
|
64 string relPos; |
|
65 string state; |
|
66 string flag; |
|
67 string name; |
|
68 }; |
|
69 |
|
70 void listSlaves(int slavePosition) |
|
71 { |
|
72 unsigned int numSlaves, i; |
|
73 ec_ioctl_slave_t slave; |
|
74 uint16_t lastAlias, aliasIndex; |
|
75 SlaveInfo slaveInfo; |
|
76 typedef list<SlaveInfo> SlaveInfoList; |
|
77 SlaveInfoList slaveInfoList; |
|
78 SlaveInfoList::const_iterator iter; |
|
79 stringstream str; |
|
80 unsigned int maxPosWidth = 0, maxAliasWidth = 0, |
|
81 maxRelPosWidth = 0, maxStateWidth = 0; |
|
82 |
|
83 numSlaves = masterDev.slaveCount(); |
|
84 |
|
85 lastAlias = 0; |
|
86 aliasIndex = 0; |
|
87 for (i = 0; i < numSlaves; i++) { |
|
88 masterDev.getSlave(&slave, i); |
|
89 |
|
90 if (slave.alias) { |
|
91 lastAlias = slave.alias; |
|
92 aliasIndex = 0; |
|
93 } |
|
94 |
|
95 if (slavePosition == -1 || i == (unsigned int) slavePosition) { |
|
96 str << dec << i; |
|
97 slaveInfo.pos = str.str(); |
|
98 str.clear(); |
|
99 str.str(""); |
|
100 |
|
101 str << lastAlias; |
|
102 slaveInfo.alias = str.str(); |
|
103 str.str(""); |
|
104 |
|
105 str << aliasIndex; |
|
106 slaveInfo.relPos = str.str(); |
|
107 str.str(""); |
|
108 |
|
109 slaveInfo.state = slaveState(slave.state); |
|
110 slaveInfo.flag = (slave.error_flag ? 'E' : '+'); |
|
111 |
|
112 if (strlen(slave.name)) { |
|
113 slaveInfo.name = slave.name; |
|
114 } else { |
|
115 str << "0x" << hex << setfill('0') |
|
116 << setw(8) << slave.vendor_id << ":0x" |
|
117 << setw(8) << slave.product_code; |
|
118 slaveInfo.name = str.str(); |
|
119 str.str(""); |
|
120 } |
|
121 |
|
122 |
|
123 slaveInfoList.push_back(slaveInfo); |
|
124 |
|
125 if (slaveInfo.pos.length() > maxPosWidth) |
|
126 maxPosWidth = slaveInfo.pos.length(); |
|
127 if (slaveInfo.alias.length() > maxAliasWidth) |
|
128 maxAliasWidth = slaveInfo.alias.length(); |
|
129 if (slaveInfo.relPos.length() > maxRelPosWidth) |
|
130 maxRelPosWidth = slaveInfo.relPos.length(); |
|
131 if (slaveInfo.state.length() > maxStateWidth) |
|
132 maxStateWidth = slaveInfo.state.length(); |
|
133 } |
|
134 |
|
135 aliasIndex++; |
|
136 } |
|
137 |
|
138 for (iter = slaveInfoList.begin(); iter != slaveInfoList.end(); iter++) { |
|
139 cout << setfill(' ') << right |
|
140 << setw(maxPosWidth) << iter->pos << " " |
|
141 << setw(maxAliasWidth) << iter->alias |
|
142 << ":" << left |
|
143 << setw(maxRelPosWidth) << iter->relPos << " " |
|
144 << setw(maxStateWidth) << iter->state << " " |
|
145 << iter->flag << " " |
|
146 << iter->name << endl; |
|
147 } |
|
148 } |
|
149 |
|
150 /****************************************************************************/ |
|
151 |
|
152 void showSlave(uint16_t slavePosition) |
|
153 { |
|
154 ec_ioctl_slave_t slave; |
|
155 list<string> protoList; |
|
156 list<string>::const_iterator protoIter; |
|
157 |
|
158 masterDev.getSlave(&slave, slavePosition); |
|
159 |
|
160 cout << "=== Slave " << dec << slavePosition << " ===" << endl; |
|
161 |
|
162 if (slave.alias) |
|
163 cout << "Alias: " << slave.alias << endl; |
|
164 |
|
165 cout |
|
166 << "State: " << slaveState(slave.state) << endl |
|
167 << "Flag: " << (slave.error_flag ? 'E' : '+') << endl |
|
168 << "Identity:" << endl |
|
169 << " Vendor Id: 0x" |
|
170 << hex << setfill('0') |
|
171 << setw(8) << slave.vendor_id << endl |
|
172 << " Product code: 0x" |
|
173 << setw(8) << slave.product_code << endl |
|
174 << " Revision number: 0x" |
|
175 << setw(8) << slave.revision_number << endl |
|
176 << " Serial number: 0x" |
|
177 << setw(8) << slave.serial_number << endl; |
|
178 |
|
179 if (slave.mailbox_protocols) { |
|
180 cout << "Mailboxes:" << endl |
|
181 << " RX: 0x" |
|
182 << hex << setw(4) << slave.rx_mailbox_offset << "/" |
|
183 << dec << slave.rx_mailbox_size |
|
184 << ", TX: 0x" |
|
185 << hex << setw(4) << slave.tx_mailbox_offset << "/" |
|
186 << dec << slave.tx_mailbox_size << endl |
|
187 << " Supported protocols: "; |
|
188 |
|
189 if (slave.mailbox_protocols & EC_MBOX_AOE) { |
|
190 protoList.push_back("AoE"); |
|
191 } |
|
192 if (slave.mailbox_protocols & EC_MBOX_EOE) { |
|
193 protoList.push_back("EoE"); |
|
194 } |
|
195 if (slave.mailbox_protocols & EC_MBOX_COE) { |
|
196 protoList.push_back("CoE"); |
|
197 } |
|
198 if (slave.mailbox_protocols & EC_MBOX_FOE) { |
|
199 protoList.push_back("FoE"); |
|
200 } |
|
201 if (slave.mailbox_protocols & EC_MBOX_SOE) { |
|
202 protoList.push_back("SoE"); |
|
203 } |
|
204 if (slave.mailbox_protocols & EC_MBOX_VOE) { |
|
205 protoList.push_back("VoE"); |
|
206 } |
|
207 |
|
208 for (protoIter = protoList.begin(); protoIter != protoList.end(); |
|
209 protoIter++) { |
|
210 if (protoIter != protoList.begin()) |
|
211 cout << ", "; |
|
212 cout << *protoIter; |
|
213 } |
|
214 cout << endl; |
|
215 } |
|
216 |
|
217 if (slave.has_general_category) { |
|
218 cout << "General:" << endl |
|
219 << " Group: " << slave.group << endl |
|
220 << " Image name: " << slave.image << endl |
|
221 << " Order number: " << slave.order << endl |
|
222 << " Device name: " << slave.name << endl; |
|
223 |
|
224 if (slave.mailbox_protocols & EC_MBOX_COE) { |
|
225 cout << " CoE details:" << endl |
|
226 << " Enable Sdo: " |
|
227 << (slave.coe_details.enable_sdo ? "yes" : "no") << endl |
|
228 << " Enable Sdo Info: " |
|
229 << (slave.coe_details.enable_sdo_info ? "yes" : "no") << endl |
|
230 << " Enable Pdo Assign: " |
|
231 << (slave.coe_details.enable_pdo_assign |
|
232 ? "yes" : "no") << endl |
|
233 << " Enable Pdo Configuration: " |
|
234 << (slave.coe_details.enable_pdo_configuration |
|
235 ? "yes" : "no") << endl |
|
236 << " Enable Upload at startup: " |
|
237 << (slave.coe_details.enable_upload_at_startup |
|
238 ? "yes" : "no") << endl |
|
239 << " Enable Sdo complete access: " |
|
240 << (slave.coe_details.enable_sdo_complete_access |
|
241 ? "yes" : "no") << endl; |
|
242 } |
|
243 |
|
244 cout << " Flags:" << endl |
|
245 << " Enable SafeOp: " |
|
246 << (slave.general_flags.enable_safeop ? "yes" : "no") << endl |
|
247 << " Enable notLRW: " |
|
248 << (slave.general_flags.enable_not_lrw ? "yes" : "no") << endl |
|
249 << " Current consumption: " |
|
250 << dec << slave.current_on_ebus << " mA" << endl; |
|
251 } |
|
252 } |
|
253 |
|
254 /*****************************************************************************/ |