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