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 "CommandXml.h" fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: CommandXml::CommandXml(): fp@1142: Command("xml", "Generate slave information XML.") fp@1142: { fp@1142: } fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: string CommandXml::helpString() const fp@1142: { fp@1142: stringstream str; fp@1142: fp@1144: str << getName() << " [OPTIONS]" << endl fp@1142: << endl fp@1142: << getBriefDescription() << endl fp@1142: << endl fp@1142: << "Note that the Pdo information can either originate" << endl fp@1142: << "from the SII or from the CoE communication area. For" << endl fp@1144: << "slaves, that support configuring Pdo assignment and" << endl fp@1144: << "mapping, the output depends on the last configuration." << endl fp@1142: << endl fp@1142: << "Command-specific options:" << endl fp@1142: << " --slave -s Positive numerical ring position," << endl fp@1142: << " or 'all' for all slaves (default)." << 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 CommandXml::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: generateSlaveXml(m, i); fp@1142: } fp@1142: } else { fp@1142: generateSlaveXml(m, slavePosition); fp@1142: } fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: void CommandXml::generateSlaveXml(MasterDevice &m, uint16_t slavePosition) fp@1142: { fp@1142: ec_ioctl_slave_t slave; fp@1142: ec_ioctl_slave_sync_t sync; fp@1142: ec_ioctl_slave_sync_pdo_t pdo; fp@1142: string pdoType; fp@1142: ec_ioctl_slave_sync_pdo_entry_t entry; fp@1142: unsigned int i, j, k; fp@1142: fp@1142: m.getSlave(&slave, slavePosition); fp@1142: fp@1142: cout fp@1142: << "" << endl fp@1142: << " " << endl fp@1142: << " " << endl fp@1142: << " " << endl fp@1142: << " " << slave.vendor_id << "" << endl fp@1142: << " " << endl fp@1142: << " " << endl fp@1142: << " " << endl fp@1142: << " " << endl fp@1142: << " " << slave.order << "" << endl; fp@1142: fp@1142: if (strlen(slave.name)) { fp@1142: cout fp@1142: << " " << endl; fp@1142: } fp@1142: fp@1142: for (i = 0; i < slave.sync_count; i++) { fp@1142: m.getSync(&sync, slavePosition, i); fp@1142: fp@1142: cout fp@1142: << " " << endl; fp@1142: } fp@1142: fp@1142: for (i = 0; i < slave.sync_count; i++) { fp@1142: m.getSync(&sync, slavePosition, i); fp@1142: fp@1142: for (j = 0; j < sync.pdo_count; j++) { fp@1142: m.getPdo(&pdo, slavePosition, i, j); fp@1142: pdoType = (sync.control_register & 0x04 ? "R" : "T"); fp@1142: pdoType += "xPdo"; fp@1142: fp@1142: cout fp@1142: << " <" << pdoType fp@1142: << " Sm=\"" << i << "\" Fixed=\"1\" Mandatory=\"1\">" << endl fp@1142: << " #x" fp@1142: << hex << setfill('0') << setw(4) << pdo.index fp@1142: << "" << endl fp@1142: << " " << pdo.name << "" << endl; fp@1142: fp@1142: for (k = 0; k < pdo.entry_count; k++) { fp@1142: m.getPdoEntry(&entry, slavePosition, i, j, k); fp@1142: fp@1142: cout fp@1142: << " " << endl fp@1142: << " #x" fp@1142: << hex << setfill('0') << setw(4) << entry.index fp@1142: << "" << endl; fp@1142: if (entry.index) fp@1142: cout fp@1142: << " " fp@1142: << dec << (unsigned int) entry.subindex fp@1142: << "" << endl; fp@1142: fp@1142: cout fp@1142: << " " fp@1142: << dec << (unsigned int) entry.bit_length fp@1142: << "" << endl; fp@1142: fp@1142: if (entry.index) { fp@1142: cout fp@1142: << " " << entry.name fp@1142: << "" << endl fp@1142: << " "; fp@1142: fp@1142: if (entry.bit_length == 1) { fp@1142: cout << "BOOL"; fp@1142: } else if (!(entry.bit_length % 8)) { fp@1142: if (entry.bit_length <= 64) fp@1142: cout << "UINT" << (unsigned int) entry.bit_length; fp@1142: else fp@1142: cout << "STRING(" fp@1142: << (unsigned int) (entry.bit_length / 8) fp@1142: << ")"; fp@1142: } else { fp@1142: cerr << "Invalid bit length " fp@1142: << (unsigned int) entry.bit_length << endl; fp@1142: } fp@1142: fp@1142: cout << "" << endl; fp@1142: } fp@1142: fp@1142: cout << " " << endl; fp@1142: } fp@1142: fp@1142: cout fp@1142: << " " << endl; fp@1142: } fp@1142: } fp@1142: fp@1142: cout fp@1142: << " " << endl fp@1142: << " " << endl fp@1142: << " " << endl fp@1142: << "" << endl; fp@1142: } fp@1142: /*****************************************************************************/