Show attached slave position and state in 'ethercat config'.
authorFlorian Pose <fp@igh-essen.com>
Fri, 25 Jul 2008 08:54:59 +0000
changeset 1147 0eac1ee8512a
parent 1146 f18d124d7fbc
child 1148 1762296870bd
Show attached slave position and state in 'ethercat config'.
TODO
master/cdev.c
master/ioctl.h
tool/CommandConfig.cpp
tool/CommandConfig.h
--- a/TODO	Fri Jul 25 08:52:45 2008 +0000
+++ b/TODO	Fri Jul 25 08:54:59 2008 +0000
@@ -16,7 +16,6 @@
 * ethercat tool:
     - Replace --slave by --position.
     - Add --alias option.
-    - Show attached slave position.
     - Show Pdos in 'ethercat slave -v'.
     - Accept files from stdin.
     - Display attached device's MAC address instead of ff's.
--- a/master/cdev.c	Fri Jul 25 08:52:45 2008 +0000
+++ b/master/cdev.c	Fri Jul 25 08:54:59 2008 +0000
@@ -994,9 +994,7 @@
             ec_pdo_list_count(&sc->sync_configs[i].pdos);
     }
     data.sdo_count = ec_slave_config_sdo_count(sc);
-    data.attached = sc->slave != NULL;
-    data.operational = sc->slave &&
-        sc->slave->current_state == EC_SLAVE_STATE_OP;
+    data.slave_position = sc->slave ? sc->slave->ring_position : -1;
 
     up(&master->master_sem);
 
--- a/master/ioctl.h	Fri Jul 25 08:52:45 2008 +0000
+++ b/master/ioctl.h	Fri Jul 25 08:54:59 2008 +0000
@@ -301,8 +301,7 @@
         uint32_t pdo_count;
     } syncs[EC_MAX_SYNC_MANAGERS];
     uint32_t sdo_count;
-    uint8_t attached    : 1,
-            operational : 1;
+    int32_t slave_position;
 } ec_ioctl_config_t;
 
 /*****************************************************************************/
--- a/tool/CommandConfig.cpp	Fri Jul 25 08:52:45 2008 +0000
+++ b/tool/CommandConfig.cpp	Fri Jul 25 08:54:59 2008 +0000
@@ -33,11 +33,16 @@
     	<< "Without the --verbose option, slave configurations are" << endl
     	<< "output one-per-line. Example:" << endl
     	<< endl
-    	<< "1001:0  0x0000003b/0x02010000  -  -" << endl
+    	<< "1001:0  0x0000003b/0x02010000  3  OP" << endl
     	<< "|       |                      |  |" << endl
-    	<< "|       |                      |  \\- Slave is operational."
-		<< endl
-    	<< "|       |                      \\- Slave has been found." << endl
+    	<< "|       |                      |  \\- Application-layer" << endl
+    	<< "|       |                      |     state of the attached" << endl
+    	<< "|       |                      |     slave, or '-', if no" << endl
+    	<< "|       |                      |     slave is attached." << endl
+    	<< "|       |                      \\- Absolute decimal ring" << endl
+    	<< "|       |                         position of the attached" << endl
+    	<< "|       |                         slave, or '-' if none" << endl
+    	<< "|       |                         attached." << endl
     	<< "|       \\- Vendor ID and product code (both" << endl
     	<< "|          hexadecimal)." << endl
     	<< "\\- Alias and relative position (both decimal)." << endl
@@ -86,7 +91,7 @@
     if (getVerbosity() == Verbose) {
         showDetailedConfigs(m, configList);
     } else {
-        listConfigs(configList);
+        listConfigs(m, configList);
     }
 }
 
@@ -101,6 +106,7 @@
 {
     ConfigList::const_iterator configIter;
     unsigned int j, k, l;
+    ec_ioctl_slave_t slave;
     ec_ioctl_config_pdo_t pdo;
     ec_ioctl_config_pdo_entry_t entry;
     ec_ioctl_config_sdo_t sdo;
@@ -117,8 +123,15 @@
             << setw(8) << configIter->vendor_id << endl
             << "Product code: 0x"
             << setw(8) << configIter->product_code << endl
-            << "Attached: " << (configIter->attached ? "yes" : "no") << endl
-            << "Operational: " << (configIter->operational ? "yes" : "no") << endl;
+            << "Attached slave: ";
+        
+        if (configIter->slave_position != -1) {
+            m.getSlave(&slave, configIter->slave_position);
+            cout << configIter->slave_position
+                << " (" << alStateString(slave.state) << ")" << endl;
+        } else {
+            cout << "none" << endl;
+        }
 
         for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) {
             if (configIter->syncs[j].pdo_count) {
@@ -188,7 +201,10 @@
 
 /** Lists the bus configuration.
  */
-void CommandConfig::listConfigs(const ConfigList &configList)
+void CommandConfig::listConfigs(
+        MasterDevice &m,
+        const ConfigList &configList
+        )
 {
     ConfigList::const_iterator configIter;
     stringstream str;
@@ -197,7 +213,8 @@
     InfoList list;
     InfoList::const_iterator iter;
     unsigned int maxAliasWidth = 0, maxPosWidth = 0,
-                 maxAttWidth = 0, maxOpWidth = 0;
+                 maxSlavePosWidth = 0, maxStateWidth = 0;
+    ec_ioctl_slave_t slave;
 
     for (configIter = configList.begin();
             configIter != configList.end();
@@ -220,15 +237,29 @@
         str.clear();
         str.str("");
 
-        str << (configIter->attached ? "attached" : "-");
-        info.att = str.str();
-        str.clear();
-        str.str("");
-
-        str << (configIter->operational ? "operational" : "-");
-        info.op = str.str();
-        str.clear();
-        str.str("");
+        if (configIter->slave_position != -1) {
+            m.getSlave(&slave, configIter->slave_position);
+
+            str << configIter->slave_position;
+            info.slavePos = str.str();
+            str.clear();
+            str.str("");
+
+            str << alStateString(slave.state);
+            info.state = str.str();
+            str.clear();
+            str.str("");
+        } else {
+            str << "-";
+            info.slavePos = str.str();
+            str.clear();
+            str.str("");
+
+            str << "-";
+            info.state = str.str();
+            str.clear();
+            str.str("");
+        }
 
         list.push_back(info);
 
@@ -236,10 +267,10 @@
             maxAliasWidth = info.alias.length();
         if (info.pos.length() > maxPosWidth)
             maxPosWidth = info.pos.length();
-        if (info.att.length() > maxAttWidth)
-            maxAttWidth = info.att.length();
-        if (info.op.length() > maxOpWidth)
-            maxOpWidth = info.op.length();
+        if (info.slavePos.length() > maxSlavePosWidth)
+            maxSlavePosWidth = info.slavePos.length();
+        if (info.state.length() > maxStateWidth)
+            maxStateWidth = info.state.length();
     }
 
     for (iter = list.begin(); iter != list.end(); iter++) {
@@ -250,8 +281,8 @@
             << "  "
             << iter->ident
             << "  "
-            << setw(maxAttWidth) << iter->att << "  "
-            << setw(maxOpWidth) << iter->op << "  "
+            << setw(maxSlavePosWidth) << iter->slavePos << "  "
+            << setw(maxStateWidth) << iter->state << "  "
             << endl;
     }
 }
--- a/tool/CommandConfig.h	Fri Jul 25 08:52:45 2008 +0000
+++ b/tool/CommandConfig.h	Fri Jul 25 08:54:59 2008 +0000
@@ -28,14 +28,14 @@
 			string alias;
 			string pos;
 			string ident;
-			string att;
-			string op;
+			string slavePos;
+			string state;
 		};
 
 		typedef list<ec_ioctl_config_t> ConfigList;
 
 		void showDetailedConfigs(MasterDevice &, const ConfigList &);
-		void listConfigs(const ConfigList &);
+		void listConfigs(MasterDevice &m, const ConfigList &);
 };
 
 /****************************************************************************/