Added 'xml' command to generate a slave description file from a real
authorFlorian Pose <fp@igh-essen.com>
Mon, 02 Jun 2008 14:40:19 +0000
changeset 938 5b936e8e39fa
parent 937 e2ee1bed5bd6
child 939 6a3b0be56498
Added 'xml' command to generate a slave description file from a real
slave.
master/cdev.c
master/ioctl.h
tools/Master.cpp
tools/Master.h
tools/main.cpp
--- 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;
 
--- 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;
--- 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
+        << "<?xml version=\"1.0\" ?>" << endl
+        << "  <EtherCATInfo>" << endl
+        << "    <!-- Slave " << slave.position << " -->" << endl
+        << "    <Vendor>" << endl
+        << "      <Id>" << slave.vendor_id << "</Id>" << endl
+        << "    </Vendor>" << endl
+        << "    <Descriptions>" << endl
+        << "      <Devices>" << endl
+        << "        <Device>" << endl
+        << "          <Type ProductCode=\"#x"
+        << hex << setfill('0') << setw(8) << slave.product_code
+        << "\" RevisionNo=\"#x"
+        << hex << setfill('0') << setw(8) << slave.revision_number
+        << "\"/>" << 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
+                << "            <Index>#x"
+                << hex << setfill('0') << setw(4) << pdo.index
+                << "</Index>" << endl
+                << "            <Name>" << pdo.name << "</Name>" << endl;
+
+            for (k = 0; k < pdo.entry_count; k++) {
+                getPdoEntry(&entry, slavePosition, i, j, k);
+
+                cout
+                    << "            <Entry>" << endl
+                    << "              <Index>#x"
+                    << hex << setfill('0') << setw(4) << entry.index
+                    << "</Index>" << endl;
+                if (entry.index)
+                    cout
+                        << "              <SubIndex>"
+                        << dec << (unsigned int) entry.subindex
+                        << "</SubIndex>" << endl;
+                
+                cout
+                    << "              <BitLen>"
+                    << (unsigned int) entry.bit_length
+                    << "</BitLen>" << endl;
+
+                if (entry.index) {
+                    cout
+                        << "              <Name>" << entry.name
+                        << "</Name>" << endl
+                        << "              <DataType>";
+
+                    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 << "</DataType>" << endl;
+                }
+
+                cout << "            </Entry>" << endl;
+            }
+
+            cout
+                << "          </" << (pdo.dir ? "T" : "R") << "xPdo>" << endl;
+        }
+    }
+
+    cout
+        << "        </Device>" << endl
+        << "     </Devices>" << endl
+        << "  </Descriptions>" << endl
+        << "</EtherCATInfo>" << endl;
+}
+
+/****************************************************************************/
+
 unsigned int Master::slaveCount()
 {
     int ret;
--- 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);
--- 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 <master>  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();