diff -r 957f21465052 -r 1aee4aa1def3 tools/Master.cpp --- a/tools/Master.cpp Fri Jun 06 09:22:57 2008 +0000 +++ b/tools/Master.cpp Fri Jun 06 09:27:24 2008 +0000 @@ -224,6 +224,21 @@ /****************************************************************************/ +void Master::listSdos(int slavePosition) +{ + if (slavePosition == -1) { + unsigned int numSlaves = slaveCount(), i; + + for (i = 0; i < numSlaves; i++) { + listSlaveSdos(i, true); + } + } else { + listSlaveSdos(slavePosition, false); + } +} + +/****************************************************************************/ + void Master::requestStates( int slavePosition, const vector &commandArgs @@ -375,7 +390,7 @@ /****************************************************************************/ -void Master::listSlavePdos(uint16_t slavePosition, bool printSlave) +void Master::listSlavePdos(uint16_t slavePosition, bool withHeader) { ec_ioctl_slave_t slave; ec_ioctl_sync_t sync; @@ -385,7 +400,7 @@ getSlave(&slave, slavePosition); - if (printSlave) + if (withHeader) cout << "=== Slave " << slavePosition << " ===" << endl; for (i = 0; i < slave.sync_count; i++) { @@ -425,6 +440,40 @@ /****************************************************************************/ +void Master::listSlaveSdos(uint16_t slavePosition, bool withHeader) +{ + ec_ioctl_slave_t slave; + ec_ioctl_sdo_t sdo; + ec_ioctl_sdo_entry_t entry; + unsigned int i, j, k; + + getSlave(&slave, slavePosition); + + if (withHeader) + cout << "=== Slave " << slavePosition << " ===" << endl; + + for (i = 0; i < slave.sdo_count; i++) { + getSdo(&sdo, slavePosition, i); + + cout << "Sdo 0x" + << hex << setfill('0') << setw(4) << sdo.sdo_index + << ", \"" << sdo.name << "\"" << endl; + + for (j = 0; j <= sdo.max_subindex; j++) { + getSdoEntry(&entry, slavePosition, i, j); + + cout << " Entry 0x" + << hex << setfill('0') << setw(2) + << (unsigned int) entry.sdo_entry_subindex + << ", type 0x" << setw(4) << entry.data_type + << ", " << dec << entry.bit_length << " bit, \"" + << entry.description << "\"" << endl; + } + } +} + +/****************************************************************************/ + void Master::generateSlaveXml(uint16_t slavePosition) { ec_ioctl_slave_t slave; @@ -717,6 +766,58 @@ /****************************************************************************/ +void Master::getSdo( + ec_ioctl_sdo_t *sdo, + uint16_t slaveIndex, + uint16_t sdoPosition + ) +{ + sdo->slave_position = slaveIndex; + sdo->sdo_position = sdoPosition; + + if (ioctl(fd, EC_IOCTL_SDO, sdo)) { + stringstream err; + err << "Failed to get Sdo: "; + if (errno == EINVAL) + err << "Either slave " << slaveIndex << " does not exist, " + << "or it contains less than " << sdoPosition + 1 << " Sdos!" + << endl; + else + err << strerror(errno); + throw MasterException(err.str()); + } +} + +/****************************************************************************/ + +void Master::getSdoEntry( + ec_ioctl_sdo_entry_t *entry, + uint16_t slaveIndex, + uint16_t sdoPosition, + uint8_t entrySubindex + ) +{ + entry->slave_position = slaveIndex; + entry->sdo_position = sdoPosition; + entry->sdo_entry_subindex = entrySubindex; + + if (ioctl(fd, EC_IOCTL_SDO_ENTRY, entry)) { + stringstream err; + err << "Failed to get Sdo entry: "; + if (errno == EINVAL) + err << "Either slave " << slaveIndex << " does not exist, " + << "or it contains less than " << sdoPosition + 1 + << " Sdos, or the Sdo at position " << sdoPosition + << " contains less than " << (unsigned int) entrySubindex + 1 + << " entries!" << endl; + else + err << strerror(errno); + throw MasterException(err.str()); + } +} + +/****************************************************************************/ + void Master::requestState( uint16_t slavePosition, uint8_t state