166 writeSlaveAlias(i, alias); |
166 writeSlaveAlias(i, alias); |
167 } |
167 } |
168 } else { |
168 } else { |
169 open(ReadWrite); |
169 open(ReadWrite); |
170 writeSlaveAlias(slavePosition, alias); |
170 writeSlaveAlias(slavePosition, alias); |
|
171 } |
|
172 } |
|
173 |
|
174 /*****************************************************************************/ |
|
175 |
|
176 /** |
|
177 * Lists the bus configuration. |
|
178 */ |
|
179 void Master::showConfig() |
|
180 { |
|
181 ec_ioctl_master_t master; |
|
182 unsigned int i, j, k, l; |
|
183 ec_ioctl_config_t config; |
|
184 ec_ioctl_config_pdo_t pdo; |
|
185 ec_ioctl_config_pdo_entry_t entry; |
|
186 ec_ioctl_config_sdo_t sdo; |
|
187 |
|
188 open(Read); |
|
189 getMaster(&master); |
|
190 |
|
191 for (i = 0; i < master.config_count; i++) { |
|
192 getConfig(&config, i); |
|
193 |
|
194 cout << "Alias: 0x" |
|
195 << hex << setfill('0') << setw(4) << config.alias << endl |
|
196 << "Position: " << dec << config.position << endl |
|
197 << "Vendor Id: 0x" |
|
198 << hex << setw(8) << config.vendor_id << endl |
|
199 << "Product code: 0x" |
|
200 << hex << setw(8) << config.product_code << endl |
|
201 << "Attached: " << (config.attached ? "yes" : "no") << endl; |
|
202 |
|
203 for (j = 0; j < 2; j++) { |
|
204 if (config.pdo_count[j]) { |
|
205 cout << (j ? "Input" : "Output") |
|
206 << " Pdo assignment / mapping " << endl; |
|
207 for (k = 0; k < config.pdo_count[j]; k++) { |
|
208 getConfigPdo(&pdo, i, j, k); |
|
209 |
|
210 cout << " Pdo 0x" |
|
211 << hex << setfill('0') << setw(4) << pdo.index |
|
212 << " \"" << pdo.name << "\"" << endl; |
|
213 |
|
214 for (l = 0; l < pdo.entry_count; l++) { |
|
215 getConfigPdoEntry(&entry, i, j, k, l); |
|
216 |
|
217 cout << " Pdo entry 0x" |
|
218 << hex << setfill('0') << setw(4) << entry.index |
|
219 << ":" << setw(2) << (unsigned int) entry.subindex |
|
220 << ", " << dec << (unsigned int) entry.bit_length |
|
221 << " bit, \"" << entry.name << "\"" << endl; |
|
222 } |
|
223 } |
|
224 } |
|
225 } |
|
226 |
|
227 if (config.sdo_count) { |
|
228 cout << "Sdo configuration:" << endl; |
|
229 for (j = 0; j < config.sdo_count; j++) { |
|
230 getConfigSdo(&sdo, i, j); |
|
231 |
|
232 cout << " 0x" |
|
233 << hex << setfill('0') << setw(4) << sdo.index |
|
234 << ":" << setw(2) << (unsigned int) sdo.subindex |
|
235 << ", " << sdo.size << " byte: " << hex; |
|
236 |
|
237 switch (sdo.size) { |
|
238 case 1: |
|
239 cout << "0x" << setw(2) |
|
240 << (unsigned int) *(uint8_t *) &sdo.data; |
|
241 break; |
|
242 case 2: |
|
243 cout << "0x" << setw(4) |
|
244 << le16tocpu(*(uint16_t *) &sdo.data); |
|
245 break; |
|
246 case 4: |
|
247 cout << "0x" << setw(8) |
|
248 << le32tocpu(*(uint32_t *) &sdo.data); |
|
249 break; |
|
250 default: |
|
251 cout << "???"; |
|
252 } |
|
253 |
|
254 cout << endl; |
|
255 } |
|
256 } |
|
257 |
|
258 cout << endl; |
171 } |
259 } |
172 } |
260 } |
173 |
261 |
174 /****************************************************************************/ |
262 /****************************************************************************/ |
175 |
263 |
1154 for (k = 0; k < pdo.entry_count; k++) { |
1242 for (k = 0; k < pdo.entry_count; k++) { |
1155 getPdoEntry(&entry, slavePosition, i, j, k); |
1243 getPdoEntry(&entry, slavePosition, i, j, k); |
1156 |
1244 |
1157 cout << " Pdo entry 0x" |
1245 cout << " Pdo entry 0x" |
1158 << hex << setfill('0') << setw(4) << entry.index |
1246 << hex << setfill('0') << setw(4) << entry.index |
1159 << ":" << hex << setfill('0') << setw(2) |
1247 << ":" << setw(2) << (unsigned int) entry.subindex |
1160 << (unsigned int) entry.subindex |
|
1161 << ", " << dec << (unsigned int) entry.bit_length |
1248 << ", " << dec << (unsigned int) entry.bit_length |
1162 << " bit, \"" << entry.name << "\"" << endl; |
1249 << " bit, \"" << entry.name << "\"" << endl; |
1163 } |
1250 } |
1164 } |
1251 } |
1165 } |
1252 } |
1304 << " Enable SafeOp: " |
1391 << " Enable SafeOp: " |
1305 << (slave.general_flags.enable_safeop ? "yes" : "no") << endl |
1392 << (slave.general_flags.enable_safeop ? "yes" : "no") << endl |
1306 << " Enable notLRW: " |
1393 << " Enable notLRW: " |
1307 << (slave.general_flags.enable_not_lrw ? "yes" : "no") << endl |
1394 << (slave.general_flags.enable_not_lrw ? "yes" : "no") << endl |
1308 << " Current consumption: " |
1395 << " Current consumption: " |
1309 << dec << slave.current_on_ebus << " mA" << endl << sizeof(slave); |
1396 << dec << slave.current_on_ebus << " mA" << endl; |
1310 } |
1397 } |
1311 cout << endl; |
1398 cout << endl; |
1312 } |
1399 } |
1313 |
1400 |
1314 /****************************************************************************/ |
1401 /****************************************************************************/ |
1439 void Master::getMaster(ec_ioctl_master_t *data) |
1526 void Master::getMaster(ec_ioctl_master_t *data) |
1440 { |
1527 { |
1441 if (ioctl(fd, EC_IOCTL_MASTER, data) < 0) { |
1528 if (ioctl(fd, EC_IOCTL_MASTER, data) < 0) { |
1442 stringstream err; |
1529 stringstream err; |
1443 err << "Failed to get master information: " << strerror(errno); |
1530 err << "Failed to get master information: " << strerror(errno); |
|
1531 throw MasterException(err.str()); |
|
1532 } |
|
1533 } |
|
1534 |
|
1535 /****************************************************************************/ |
|
1536 |
|
1537 void Master::getConfig(ec_ioctl_config_t *data, unsigned int index) |
|
1538 { |
|
1539 data->config_index = index; |
|
1540 |
|
1541 if (ioctl(fd, EC_IOCTL_CONFIG, data) < 0) { |
|
1542 stringstream err; |
|
1543 err << "Failed to get slave configuration: " << strerror(errno); |
|
1544 throw MasterException(err.str()); |
|
1545 } |
|
1546 } |
|
1547 |
|
1548 /****************************************************************************/ |
|
1549 |
|
1550 void Master::getConfigPdo( |
|
1551 ec_ioctl_config_pdo_t *data, |
|
1552 unsigned int index, |
|
1553 unsigned int dir, |
|
1554 unsigned int pdo_pos |
|
1555 ) |
|
1556 { |
|
1557 data->config_index = index; |
|
1558 data->direction = dir; |
|
1559 data->pdo_pos = pdo_pos; |
|
1560 |
|
1561 if (ioctl(fd, EC_IOCTL_CONFIG_PDO, data) < 0) { |
|
1562 stringstream err; |
|
1563 err << "Failed to get slave config Pdo: " << strerror(errno); |
|
1564 throw MasterException(err.str()); |
|
1565 } |
|
1566 } |
|
1567 |
|
1568 /****************************************************************************/ |
|
1569 |
|
1570 void Master::getConfigPdoEntry( |
|
1571 ec_ioctl_config_pdo_entry_t *data, |
|
1572 unsigned int index, |
|
1573 unsigned int dir, |
|
1574 unsigned int pdo_pos, |
|
1575 unsigned int entry_pos |
|
1576 ) |
|
1577 { |
|
1578 data->config_index = index; |
|
1579 data->direction = dir; |
|
1580 data->pdo_pos = pdo_pos; |
|
1581 data->entry_pos = entry_pos; |
|
1582 |
|
1583 if (ioctl(fd, EC_IOCTL_CONFIG_PDO_ENTRY, data) < 0) { |
|
1584 stringstream err; |
|
1585 err << "Failed to get slave config Pdo entry: " << strerror(errno); |
|
1586 throw MasterException(err.str()); |
|
1587 } |
|
1588 } |
|
1589 |
|
1590 /****************************************************************************/ |
|
1591 |
|
1592 void Master::getConfigSdo( |
|
1593 ec_ioctl_config_sdo_t *data, |
|
1594 unsigned int index, |
|
1595 unsigned int sdo_pos |
|
1596 ) |
|
1597 { |
|
1598 data->config_index = index; |
|
1599 data->sdo_pos = sdo_pos; |
|
1600 |
|
1601 if (ioctl(fd, EC_IOCTL_CONFIG_SDO, data) < 0) { |
|
1602 stringstream err; |
|
1603 err << "Failed to get slave config Sdo: " << strerror(errno); |
1444 throw MasterException(err.str()); |
1604 throw MasterException(err.str()); |
1445 } |
1605 } |
1446 } |
1606 } |
1447 |
1607 |
1448 /****************************************************************************/ |
1608 /****************************************************************************/ |