fp@1142: /***************************************************************************** fp@1142: * fp@1142: * $Id$ fp@1142: * fp@1142: ****************************************************************************/ fp@1142: fp@1142: #include fp@1142: #include fp@1142: using namespace std; fp@1142: fp@1142: #include "CommandSdos.h" fp@1142: #include "coe_datatypes.h" fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: CommandSdos::CommandSdos(): fp@1142: Command("sdos", "List Sdo dictionaries.") fp@1142: { fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: string CommandSdos::helpString() const fp@1142: { fp@1142: stringstream str; fp@1142: fp@1142: str << getName() << " [OPTIONS]" << endl fp@1142: << endl fp@1142: << getBriefDescription() << endl fp@1142: << endl fp@1142: << "Sdo dictionary information is displayed in two layers," << endl fp@1142: << "which are indented accordingly:" << endl fp@1142: << endl fp@1142: << "1) Sdos - Hexadecimal Sdo index and the name. Example:" << endl fp@1142: << endl fp@1142: << " Sdo 0x1018, \"Identity object\"" << endl fp@1142: << endl fp@1142: << "2) Sdo entries - Sdo index and Sdo entry subindex (both" << endl fp@1142: << " hexadecimal) followed by the data type, the length in" << endl fp@1142: << " bit, and the description. Example:" << endl fp@1142: << endl fp@1142: << " 0x1018:01, uint32, 32 bit, \"Vendor id\"" << endl fp@1142: << endl fp@1142: << "If the --quiet option is given, only the Sdos are printed." fp@1142: << endl << endl fp@1142: << "Command-specific options:" << endl fp@1142: << " --slave -s Positive numerical ring position," << endl fp@1142: << " 'all' for all slaves (default)." << endl fp@1142: << " --quiet -q Print only Sdos (without Sdo" << endl fp@1142: << " entries)." << endl fp@1142: << endl fp@1142: << numericInfo(); fp@1142: fp@1142: return str.str(); fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: void CommandSdos::execute(MasterDevice &m, const StringVector &args) fp@1142: { fp@1142: m.open(MasterDevice::Read); fp@1142: fp@1142: if (slavePosition == -1) { fp@1142: unsigned int numSlaves = m.slaveCount(), i; fp@1142: fp@1142: for (i = 0; i < numSlaves; i++) { fp@1142: listSlaveSdos(m, i, true); fp@1142: } fp@1142: } else { fp@1142: listSlaveSdos(m, slavePosition, false); fp@1142: } fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: void CommandSdos::listSlaveSdos( fp@1142: MasterDevice &m, fp@1142: uint16_t slavePosition, fp@1142: bool withHeader fp@1142: ) fp@1142: { fp@1142: ec_ioctl_slave_t slave; fp@1142: ec_ioctl_slave_sdo_t sdo; fp@1142: ec_ioctl_slave_sdo_entry_t entry; fp@1142: unsigned int i, j; fp@1142: const CoEDataType *d; fp@1142: fp@1142: m.getSlave(&slave, slavePosition); fp@1142: fp@1142: if (withHeader) fp@1142: cout << "=== Slave " << slavePosition << " ===" << endl; fp@1142: fp@1142: for (i = 0; i < slave.sdo_count; i++) { fp@1142: m.getSdo(&sdo, slavePosition, i); fp@1142: fp@1142: cout << "Sdo 0x" fp@1142: << hex << setfill('0') fp@1142: << setw(4) << sdo.sdo_index fp@1142: << ", \"" << sdo.name << "\"" << endl; fp@1142: fp@1142: if (getVerbosity() == Quiet) fp@1142: continue; fp@1142: fp@1142: for (j = 0; j <= sdo.max_subindex; j++) { fp@1142: m.getSdoEntry(&entry, slavePosition, -i, j); fp@1142: fp@1142: cout << " 0x" << hex << setfill('0') fp@1142: << setw(4) << sdo.sdo_index << ":" fp@1142: << setw(2) << (unsigned int) entry.sdo_entry_subindex fp@1142: << ", "; fp@1142: fp@1142: if ((d = findDataType(entry.data_type))) { fp@1142: cout << d->name; fp@1142: } else { fp@1142: cout << "type " << setw(4) << entry.data_type; fp@1142: } fp@1142: fp@1142: cout << ", " << dec << entry.bit_length << " bit, \"" fp@1142: << entry.description << "\"" << endl; fp@1142: } fp@1142: } fp@1142: } fp@1142: fp@1142: /*****************************************************************************/