99 |
100 |
100 /*****************************************************************************/ |
101 /*****************************************************************************/ |
101 |
102 |
102 /** Lists the bus configuration. |
103 /** Lists the bus configuration. |
103 */ |
104 */ |
104 void CommandConfig::execute(MasterDevice &m, const StringVector &args) |
105 void CommandConfig::execute(const StringVector &args) |
105 { |
106 { |
106 ConfigList configs; |
107 ConfigList configs; |
|
108 bool doIndent; |
107 |
109 |
108 if (args.size()) { |
110 if (args.size()) { |
109 stringstream err; |
111 stringstream err; |
110 err << "'" << getName() << "' takes no arguments!"; |
112 err << "'" << getName() << "' takes no arguments!"; |
111 throwInvalidUsageException(err); |
113 throwInvalidUsageException(err); |
112 } |
114 } |
113 |
115 |
114 m.open(MasterDevice::Read); |
116 doIndent = getMasterIndices().size() > 1; |
115 configs = selectedConfigs(m); |
117 MasterIndexList::const_iterator mi; |
116 |
118 for (mi = getMasterIndices().begin(); |
117 if (getVerbosity() == Verbose) { |
119 mi != getMasterIndices().end(); mi++) { |
118 showDetailedConfigs(m, configs); |
120 MasterDevice m(*mi); |
119 } else { |
121 m.open(MasterDevice::Read); |
120 listConfigs(m, configs); |
122 configs = selectedConfigs(m); |
|
123 |
|
124 if (doIndent) { |
|
125 cout << "Master" << dec << *mi << endl; |
|
126 } |
|
127 |
|
128 if (getVerbosity() == Verbose) { |
|
129 showDetailedConfigs(m, configs, doIndent); |
|
130 } else { |
|
131 listConfigs(m, configs, doIndent); |
|
132 } |
121 } |
133 } |
122 } |
134 } |
123 |
135 |
124 /*****************************************************************************/ |
136 /*****************************************************************************/ |
125 |
137 |
126 /** Lists the complete bus configuration. |
138 /** Lists the complete bus configuration. |
127 */ |
139 */ |
128 void CommandConfig::showDetailedConfigs( |
140 void CommandConfig::showDetailedConfigs( |
129 MasterDevice &m, |
141 MasterDevice &m, |
130 const ConfigList &configList |
142 const ConfigList &configList, |
|
143 bool doIndent |
131 ) |
144 ) |
132 { |
145 { |
133 ConfigList::const_iterator configIter; |
146 ConfigList::const_iterator configIter; |
134 unsigned int i, j, k, l; |
147 unsigned int i, j, k, l; |
135 ec_ioctl_slave_t slave; |
148 ec_ioctl_slave_t slave; |
136 ec_ioctl_config_pdo_t pdo; |
149 ec_ioctl_config_pdo_t pdo; |
137 ec_ioctl_config_pdo_entry_t entry; |
150 ec_ioctl_config_pdo_entry_t entry; |
138 ec_ioctl_config_sdo_t sdo; |
151 ec_ioctl_config_sdo_t sdo; |
|
152 string indent(doIndent ? " " : ""); |
139 |
153 |
140 for (configIter = configList.begin(); |
154 for (configIter = configList.begin(); |
141 configIter != configList.end(); |
155 configIter != configList.end(); |
142 configIter++) { |
156 configIter++) { |
143 |
157 |
144 cout << "Alias: " |
158 cout << indent |
145 << dec << configIter->alias << endl |
159 << "Alias: " |
146 << "Position: " << configIter->position << endl |
160 << dec << configIter->alias << endl << indent |
|
161 << "Position: " << configIter->position << endl << indent |
147 << "Vendor Id: 0x" |
162 << "Vendor Id: 0x" |
148 << hex << setfill('0') |
163 << hex << setfill('0') |
149 << setw(8) << configIter->vendor_id << endl |
164 << setw(8) << configIter->vendor_id << endl << indent |
150 << "Product code: 0x" |
165 << "Product code: 0x" |
151 << setw(8) << configIter->product_code << endl |
166 << setw(8) << configIter->product_code << endl << indent |
152 << "Attached slave: "; |
167 << "Attached slave: "; |
153 |
168 |
154 if (configIter->slave_position != -1) { |
169 if (configIter->slave_position != -1) { |
155 m.getSlave(&slave, configIter->slave_position); |
170 m.getSlave(&slave, configIter->slave_position); |
156 cout << dec << configIter->slave_position |
171 cout << dec << configIter->slave_position |
157 << " (" << alStateString(slave.al_state) << ")" << endl; |
172 << " (" << alStateString(slave.al_state) << ")" << endl; |
158 } else { |
173 } else { |
159 cout << "none" << endl; |
174 cout << "none" << endl; |
160 } |
175 } |
161 |
176 |
162 cout << "Watchdog divider: "; |
177 cout << indent << "Watchdog divider: "; |
163 if (configIter->watchdog_divider) { |
178 if (configIter->watchdog_divider) { |
164 cout << dec << configIter->watchdog_divider; |
179 cout << dec << configIter->watchdog_divider; |
165 } else { |
180 } else { |
166 cout << "(Default)"; |
181 cout << "(Default)"; |
167 } |
182 } |
168 cout << endl |
183 cout << endl << indent |
169 << "Watchdog intervals: "; |
184 << "Watchdog intervals: "; |
170 if (configIter->watchdog_intervals) { |
185 if (configIter->watchdog_intervals) { |
171 cout << dec << configIter->watchdog_intervals; |
186 cout << dec << configIter->watchdog_intervals; |
172 } else { |
187 } else { |
173 cout << "(Default)"; |
188 cout << "(Default)"; |
174 } |
189 } |
175 cout << endl; |
190 cout << endl; |
176 |
191 |
177 for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) { |
192 for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) { |
178 if (configIter->syncs[j].pdo_count) { |
193 if (configIter->syncs[j].pdo_count) { |
179 cout << "SM" << dec << j << ", Dir: " |
194 cout << indent << "SM" << dec << j << ", Dir: " |
180 << (configIter->syncs[j].dir == EC_DIR_INPUT |
195 << (configIter->syncs[j].dir == EC_DIR_INPUT |
181 ? "Input" : "Output") << ", Watchdog: "; |
196 ? "Input" : "Output") << ", Watchdog: "; |
182 switch (configIter->syncs[j].watchdog_mode) { |
197 switch (configIter->syncs[j].watchdog_mode) { |
183 case EC_WD_DEFAULT: cout << "Default"; break; |
198 case EC_WD_DEFAULT: cout << "Default"; break; |
184 case EC_WD_ENABLE: cout << "Enable"; break; |
199 case EC_WD_ENABLE: cout << "Enable"; break; |
188 cout << endl; |
203 cout << endl; |
189 |
204 |
190 for (k = 0; k < configIter->syncs[j].pdo_count; k++) { |
205 for (k = 0; k < configIter->syncs[j].pdo_count; k++) { |
191 m.getConfigPdo(&pdo, configIter->config_index, j, k); |
206 m.getConfigPdo(&pdo, configIter->config_index, j, k); |
192 |
207 |
193 cout << " PDO 0x" << hex << setfill('0') |
208 cout << indent << " PDO 0x" << hex << setfill('0') |
194 << setw(4) << pdo.index << endl; |
209 << setw(4) << pdo.index << endl; |
195 |
210 |
196 for (l = 0; l < pdo.entry_count; l++) { |
211 for (l = 0; l < pdo.entry_count; l++) { |
197 m.getConfigPdoEntry(&entry, |
212 m.getConfigPdoEntry(&entry, |
198 configIter->config_index, j, k, l); |
213 configIter->config_index, j, k, l); |
199 |
214 |
200 cout << " PDO entry 0x" << hex << setfill('0') |
215 cout << indent << " PDO entry 0x" |
|
216 << hex << setfill('0') |
201 << setw(4) << entry.index << ":" |
217 << setw(4) << entry.index << ":" |
202 << setw(2) << (unsigned int) entry.subindex |
218 << setw(2) << (unsigned int) entry.subindex |
203 << ", " << dec << setfill(' ') |
219 << ", " << dec << setfill(' ') |
204 << setw(2) << (unsigned int) entry.bit_length |
220 << setw(2) << (unsigned int) entry.bit_length |
205 << " bit" << endl; |
221 << " bit" << endl; |
206 } |
222 } |
207 } |
223 } |
208 } |
224 } |
209 } |
225 } |
210 |
226 |
211 cout << "SDO configuration:" << endl; |
227 cout << indent << "SDO configuration:" << endl; |
212 if (configIter->sdo_count) { |
228 if (configIter->sdo_count) { |
213 for (j = 0; j < configIter->sdo_count; j++) { |
229 for (j = 0; j < configIter->sdo_count; j++) { |
214 m.getConfigSdo(&sdo, configIter->config_index, j); |
230 m.getConfigSdo(&sdo, configIter->config_index, j); |
215 |
231 |
216 cout << " 0x" |
232 cout << indent << " 0x" |
217 << hex << setfill('0') |
233 << hex << setfill('0') |
218 << setw(4) << sdo.index << ":" |
234 << setw(4) << sdo.index << ":" |
219 << setw(2) << (unsigned int) sdo.subindex |
235 << setw(2) << (unsigned int) sdo.subindex |
220 << ", " << dec << sdo.size << " byte" << endl; |
236 << ", " << dec << sdo.size << " byte" << endl; |
221 |
237 |
222 cout << " " << hex; |
238 cout << indent << " " << hex; |
223 for (i = 0; i < min((uint32_t) sdo.size, |
239 for (i = 0; i < min((uint32_t) sdo.size, |
224 (uint32_t) EC_MAX_SDO_DATA_SIZE); i++) { |
240 (uint32_t) EC_MAX_SDO_DATA_SIZE); i++) { |
225 cout << setw(2) << (unsigned int) sdo.data[i]; |
241 cout << setw(2) << (unsigned int) sdo.data[i]; |
226 if ((i + 1) % 16 == 0 && i < sdo.size - 1) { |
242 if ((i + 1) % 16 == 0 && i < sdo.size - 1) { |
227 cout << endl << " "; |
243 cout << endl << indent << " "; |
228 } else { |
244 } else { |
229 cout << " "; |
245 cout << " "; |
230 } |
246 } |
231 } |
247 } |
232 |
248 |
233 cout << endl; |
249 cout << endl; |
234 if (sdo.size > EC_MAX_SDO_DATA_SIZE) { |
250 if (sdo.size > EC_MAX_SDO_DATA_SIZE) { |
235 cout << " ..." << endl; |
251 cout << indent << " ..." << endl; |
236 } |
252 } |
237 } |
253 } |
238 } else { |
254 } else { |
239 cout << " None." << endl; |
255 cout << indent << " None." << endl; |
240 } |
256 } |
241 |
257 |
242 if (configIter->dc_assign_activate) { |
258 if (configIter->dc_assign_activate) { |
243 int i; |
259 int i; |
244 |
260 |
245 cout << "DC configuration:" << endl |
261 cout << indent << "DC configuration:" << endl |
246 << " AssignActivate: 0x" << hex << setfill('0') |
262 << indent << " AssignActivate: 0x" << hex << setfill('0') |
247 << setw(4) << configIter->dc_assign_activate << endl; |
263 << setw(4) << configIter->dc_assign_activate << endl; |
248 |
264 |
249 cout << " Cycle [ns] Shift [ns]" << endl; |
265 cout << indent << " Cycle [ns] Shift [ns]" << endl; |
250 for (i = 0; i < EC_SYNC_SIGNAL_COUNT; i++) { |
266 for (i = 0; i < EC_SYNC_SIGNAL_COUNT; i++) { |
251 cout << " SYNC" << dec << i << " " |
267 cout << indent << " SYNC" << dec << i << " " |
252 << setfill(' ') << right |
268 << setfill(' ') << right |
253 << setw(11) << configIter->dc_sync[i].cycle_time |
269 << setw(11) << configIter->dc_sync[i].cycle_time |
254 << " " |
270 << " " |
255 << setw(11) << configIter->dc_sync[i].shift_time |
271 << setw(11) << configIter->dc_sync[i].shift_time |
256 << endl; |
272 << endl; |