# HG changeset patch # User Florian Pose # Date 1212417619 0 # Node ID 5b936e8e39faadcc249b859397c73c299e8ebeb5 # Parent e2ee1bed5bd6d45b75a02d97448cae0b4ff1d5ef Added 'xml' command to generate a slave description file from a real slave. diff -r e2ee1bed5bd6 -r 5b936e8e39fa master/cdev.c --- a/master/cdev.c Mon Jun 02 13:55:46 2008 +0000 +++ b/master/cdev.c Mon Jun 02 14:40:19 2008 +0000 @@ -165,6 +165,8 @@ data.vendor_id = slave->sii.vendor_id; data.product_code = slave->sii.product_code; + data.revision_number = slave->sii.revision_number; + data.serial_number = slave->sii.serial_number; data.alias = slave->sii.alias; data.state = slave->current_state; diff -r e2ee1bed5bd6 -r 5b936e8e39fa master/ioctl.h --- a/master/ioctl.h Mon Jun 02 13:55:46 2008 +0000 +++ b/master/ioctl.h Mon Jun 02 14:40:19 2008 +0000 @@ -62,6 +62,8 @@ // outputs uint32_t vendor_id; uint32_t product_code; + uint32_t revision_number; + uint32_t serial_number; uint16_t alias; uint8_t state; uint8_t sync_count; diff -r e2ee1bed5bd6 -r 5b936e8e39fa tools/Master.cpp --- a/tools/Master.cpp Mon Jun 02 13:55:46 2008 +0000 +++ b/tools/Master.cpp Mon Jun 02 14:40:19 2008 +0000 @@ -112,6 +112,21 @@ /****************************************************************************/ +void Master::generateXml(int slavePosition) +{ + if (slavePosition == -1) { + unsigned int numSlaves = slaveCount(), i; + + for (i = 0; i < numSlaves; i++) { + generateSlaveXml(i); + } + } else { + generateSlaveXml(slavePosition); + } +} + +/****************************************************************************/ + void Master::listSlavePdos(uint16_t slavePosition, bool printSlave) { ec_ioctl_slave_t slave; @@ -162,6 +177,104 @@ /****************************************************************************/ +void Master::generateSlaveXml(uint16_t slavePosition) +{ + ec_ioctl_slave_t slave; + ec_ioctl_sync_t sync; + ec_ioctl_pdo_t pdo; + ec_ioctl_pdo_entry_t entry; + unsigned int i, j, k; + + getSlave(&slave, slavePosition); + + cout + << "" << endl + << " " << endl + << " " << endl + << " " << endl + << " " << slave.vendor_id << "" << endl + << " " << endl + << " " << endl + << " " << endl + << " " << endl + << " " << endl; + + for (i = 0; i < slave.sync_count; i++) { + getSync(&sync, slavePosition, i); + + for (j = 0; j < sync.pdo_count; j++) { + getPdo(&pdo, slavePosition, i, j); + + cout + << " <" << (pdo.dir ? "T" : "R") << "xPdo>" << endl + << " #x" + << hex << setfill('0') << setw(4) << pdo.index + << "" << endl + << " " << pdo.name << "" << endl; + + for (k = 0; k < pdo.entry_count; k++) { + 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 + << " " + << (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; +} + +/****************************************************************************/ + unsigned int Master::slaveCount() { int ret; diff -r e2ee1bed5bd6 -r 5b936e8e39fa tools/Master.h --- a/tools/Master.h Mon Jun 02 13:55:46 2008 +0000 +++ b/tools/Master.h Mon Jun 02 14:40:19 2008 +0000 @@ -42,9 +42,11 @@ void listSlaves(); void listPdos(int); + void generateXml(int); protected: void listSlavePdos(uint16_t, bool = false); + void generateSlaveXml(uint16_t); unsigned int slaveCount(); void slaveSyncs(uint16_t); void getSlave(ec_ioctl_slave_t *, uint16_t); diff -r e2ee1bed5bd6 -r 5b936e8e39fa tools/main.cpp --- a/tools/main.cpp Mon Jun 02 13:55:46 2008 +0000 +++ b/tools/main.cpp Mon Jun 02 14:40:19 2008 +0000 @@ -31,6 +31,7 @@ << "Commands:" << endl << " list (ls, slaves) List all slaves (former 'lsec')." << endl << " pdos List Pdo mapping of given slaves." << endl + << " xml Generate slave information xml." << endl << "Global options:" << endl << " --master -m Index of the master to use. Default: " << DEFAULT_MASTER << endl @@ -121,9 +122,10 @@ if (command == "list" || command == "ls" || command == "slaves") { master.listSlaves(); - } else if (command == "pdos") { master.listPdos(slavePosition); + } else if (command == "xml") { + master.generateXml(slavePosition); } else { cerr << "Unknown command " << command << "!" << endl; printUsage();