'ethercat xml' creates <EtherCATInfoList> for more than one slave.
authorFlorian Pose <fp@igh-essen.com>
Tue, 16 Jun 2009 08:04:50 +0000
changeset 1474 758a9bd3e549
parent 1473 2558a35a65ef
child 1475 d76ae2389eab
'ethercat xml' creates <EtherCATInfoList> for more than one slave.
NEWS
tool/CommandXml.cpp
tool/CommandXml.h
--- a/NEWS	Tue Jun 16 07:42:29 2009 +0000
+++ b/NEWS	Tue Jun 16 08:04:50 2009 +0000
@@ -40,6 +40,8 @@
   an application transfer SDOs before activating the master. Thanks to Stefan
   Weiser.
 * Changed EC_MAX_SII_SIZE to 4096.
+* 'ethercat xml' creates valid XML <EtherCATInfoList> for more than one slave
+  (thanks to E. Burgstaller).
 
 Changes in 1.4.0:
 
--- a/tool/CommandXml.cpp	Tue Jun 16 07:42:29 2009 +0000
+++ b/tool/CommandXml.cpp	Tue Jun 16 08:04:50 2009 +0000
@@ -82,8 +82,17 @@
     m.open(MasterDevice::Read);
     slaves = selectedSlaves(m);
 
+    cout << "<?xml version=\"1.0\" ?>" << endl;
+    if (slaves.size() > 1) {
+        cout << "<EtherCATInfoList>" << endl;
+    }
+
     for (si = slaves.begin(); si != slaves.end(); si++) {
-        generateSlaveXml(m, *si);
+        generateSlaveXml(m, *si, slaves.size() > 1 ? 1 : 0);
+    }
+
+    if (slaves.size() > 1) {
+        cout << "</EtherCATInfoList>" << endl;
     }
 }
 
@@ -91,26 +100,30 @@
 
 void CommandXml::generateSlaveXml(
         MasterDevice &m,
-        const ec_ioctl_slave_t &slave
+        const ec_ioctl_slave_t &slave,
+        unsigned int indent
         )
 {
     ec_ioctl_slave_sync_t sync;
     ec_ioctl_slave_sync_pdo_t pdo;
-    string pdoType;
+    string pdoType, in;
     ec_ioctl_slave_sync_pdo_entry_t entry;
     unsigned int i, j, k;
+
+    for (i = 0; i < indent; i++) {
+        in += "  ";
+    }
     
     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"
+        << in << "<EtherCATInfo>" << endl
+        << in << "  <!-- Slave " << slave.position << " -->" << endl
+        << in << "  <Vendor>" << endl
+        << in << "    <Id>" << slave.vendor_id << "</Id>" << endl
+        << in << "  </Vendor>" << endl
+        << in << "  <Descriptions>" << endl
+        << in << "    <Devices>" << endl
+        << in << "      <Device>" << endl
+        << in << "        <Type ProductCode=\"#x"
         << hex << setfill('0') << setw(8) << slave.product_code
         << "\" RevisionNo=\"#x"
         << hex << setfill('0') << setw(8) << slave.revision_number
@@ -118,7 +131,7 @@
 
     if (strlen(slave.name)) {
         cout
-            << "          <Name><![CDATA["
+            << in << "        <Name><![CDATA["
             << slave.name
             << "]]></Name>" << endl;
     }
@@ -127,7 +140,7 @@
         m.getSync(&sync, slave.position, i);
 
         cout
-            << "          <Sm Enable=\"" << dec << (unsigned int) sync.enable
+            << in << "        <Sm Enable=\"" << dec << (unsigned int) sync.enable
             << "\" StartAddress=\"" << sync.physical_start_address
             << "\" ControlByte=\"" << (unsigned int) sync.control_register
             << "\" DefaultSize=\"" << sync.default_size
@@ -143,37 +156,37 @@
             pdoType += "xPdo"; // last 2 letters lowercase in XML!
 
             cout
-                << "          <" << pdoType
+                << in << "        <" << pdoType
                 << " Sm=\"" << i << "\" Fixed=\"1\" Mandatory=\"1\">" << endl
-                << "            <Index>#x"
+                << in << "          <Index>#x"
                 << hex << setfill('0') << setw(4) << pdo.index
                 << "</Index>" << endl
-                << "            <Name>" << pdo.name << "</Name>" << endl;
+                << in << "          <Name>" << pdo.name << "</Name>" << endl;
 
             for (k = 0; k < pdo.entry_count; k++) {
                 m.getPdoEntry(&entry, slave.position, i, j, k);
 
                 cout
-                    << "            <Entry>" << endl
-                    << "              <Index>#x"
+                    << in << "          <Entry>" << endl
+                    << in << "            <Index>#x"
                     << hex << setfill('0') << setw(4) << entry.index
                     << "</Index>" << endl;
                 if (entry.index)
                     cout
-                        << "              <SubIndex>"
+                        << in << "            <SubIndex>"
                         << dec << (unsigned int) entry.subindex
                         << "</SubIndex>" << endl;
                 
                 cout
-                    << "              <BitLen>"
+                    << in << "            <BitLen>"
                     << dec << (unsigned int) entry.bit_length
                     << "</BitLen>" << endl;
 
                 if (entry.index) {
                     cout
-                        << "              <Name>" << entry.name
+                        << in << "            <Name>" << entry.name
                         << "</Name>" << endl
-                        << "              <DataType>";
+                        << in << "            <DataType>";
 
                     if (entry.bit_length == 1) {
                         cout << "BOOL";
@@ -192,18 +205,19 @@
                         cout << "</DataType>" << endl;
                 }
 
-                cout << "            </Entry>" << endl;
+                cout << in << "          </Entry>" << endl;
             }
 
             cout
-                << "          </" << pdoType << ">" << endl;
+                << in << "        </" << pdoType << ">" << endl;
         }
     }
 
     cout
-        << "        </Device>" << endl
-        << "     </Devices>" << endl
-        << "  </Descriptions>" << endl
-        << "</EtherCATInfo>" << endl;
-}
+        << in << "      </Device>" << endl
+        << in << "    </Devices>" << endl
+        << in << "  </Descriptions>" << endl
+        << in << "</EtherCATInfo>" << endl;
+}
+
 /*****************************************************************************/
--- a/tool/CommandXml.h	Tue Jun 16 07:42:29 2009 +0000
+++ b/tool/CommandXml.h	Tue Jun 16 08:04:50 2009 +0000
@@ -44,7 +44,8 @@
         void execute(MasterDevice &, const StringVector &);
 
     protected:
-        void generateSlaveXml(MasterDevice &, const ec_ioctl_slave_t &);
+        void generateSlaveXml(MasterDevice &, const ec_ioctl_slave_t &,
+                unsigned int);
 };
 
 /****************************************************************************/