fp@1142: /***************************************************************************** fp@1142: * fp@1142: * $Id$ fp@1142: * fp@1142: ****************************************************************************/ fp@1142: fp@1142: #include fp@1142: #include fp@1636: #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@1157: << " --alias -a " << endl fp@1157: << " --position -p Slave selection. See the help of" << endl fp@1157: << " the 'slaves' command." << 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@1151: SlaveList slaves; fp@1151: SlaveList::const_iterator si; fp@1151: fp@1142: m.open(MasterDevice::Read); fp@1151: slaves = selectedSlaves(m); fp@1142: fp@1151: for (si = slaves.begin(); si != slaves.end(); si++) { fp@1151: generateSlaveXml(m, *si); fp@1142: } fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1151: void CommandXml::generateSlaveXml( fp@1151: MasterDevice &m, fp@1151: const ec_ioctl_slave_t &slave fp@1151: ) fp@1142: { 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: 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@1151: m.getSync(&sync, slave.position, i); fp@1142: fp@1142: cout fp@1142: << " " << endl; fp@1142: } fp@1142: fp@1142: for (i = 0; i < slave.sync_count; i++) { fp@1151: m.getSync(&sync, slave.position, i); fp@1142: fp@1142: for (j = 0; j < sync.pdo_count; j++) { fp@1151: m.getPdo(&pdo, slave.position, 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@1151: m.getPdoEntry(&entry, slave.position, 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: /*****************************************************************************/