Implemented alias and position for configs.
authorFlorian Pose <fp@igh-essen.com>
Mon, 28 Jul 2008 09:12:21 +0000
changeset 1156 ecaf2a896ea3
parent 1155 bd4e5b544473
child 1157 04d1c950cf9d
Implemented alias and position for configs.
TODO
tool/Command.cpp
tool/Command.h
tool/CommandConfig.cpp
tool/CommandConfig.h
--- a/TODO	Mon Jul 28 08:45:28 2008 +0000
+++ b/TODO	Mon Jul 28 09:12:21 2008 +0000
@@ -14,7 +14,6 @@
 * Get original driver for r8169.
 * Race in jiffies frame timeout?
 * ethercat tool:
-    - Implement Alias/Position selection for configs.
     - Update help for --alias and --position.
     - Show Pdos in 'ethercat slave -v'.
     - Accept files from stdin.
--- a/tool/Command.cpp	Mon Jul 28 08:45:28 2008 +0000
+++ b/tool/Command.cpp	Mon Jul 28 09:12:21 2008 +0000
@@ -159,6 +159,69 @@
     return list;
 }
 
+/*****************************************************************************/
+
+bool operator<(
+        const ec_ioctl_config_t &a,
+        const ec_ioctl_config_t &b
+        )
+{
+    return a.alias < b.alias
+        || (a.alias == b.alias && a.position < b.position);
+}
+
+/*****************************************************************************/
+
+Command::ConfigList Command::selectedConfigs(MasterDevice &m)
+{
+    unsigned int i;
+    int effAlias;
+    ec_ioctl_master_t master;
+    ec_ioctl_config_t config;
+    ConfigList list;
+    stringstream err;
+
+    m.getMaster(&master);
+
+    // Assume alias 0 if only position is given.
+    if (alias == -1 && position != -1) {
+        effAlias = 0;
+    } else {
+        effAlias = alias;
+    }
+
+    if (effAlias == -1) { // no alias given
+        if (position == -1) { // no alias and position given
+            // all items
+            for (i = 0; i < master.config_count; i++) {
+                m.getConfig(&config, i);
+                list.push_back(config);
+            }
+        }
+    } else { // alias given
+        if (position == -1) { // alias, but no position given
+            // take all items with a given alias
+            for (i = 0; i < master.config_count; i++) {
+                m.getConfig(&config, i);
+                if (config.alias == effAlias) {
+                    list.push_back(config);
+                }
+            }
+        } else { // alias and position given
+            for (i = 0; i < master.config_count; i++) {
+                m.getConfig(&config, i);
+                if (config.alias == effAlias && config.position == position) {
+                    list.push_back(config);
+                    break; // there can be at most one matching
+                }
+            }
+        }
+    }
+
+    list.sort();
+    return list;
+}
+
 /****************************************************************************/
 
 string Command::alStateString(uint8_t state)
--- a/tool/Command.h	Mon Jul 28 08:45:28 2008 +0000
+++ b/tool/Command.h	Mon Jul 28 09:12:21 2008 +0000
@@ -91,6 +91,8 @@
 
         typedef list<ec_ioctl_slave_t> SlaveList;
         SlaveList selectedSlaves(MasterDevice &);
+        typedef list<ec_ioctl_config_t> ConfigList;
+        ConfigList selectedConfigs(MasterDevice &);
 
         static string alStateString(uint8_t);
 
--- a/tool/CommandConfig.cpp	Mon Jul 28 08:45:28 2008 +0000
+++ b/tool/CommandConfig.cpp	Mon Jul 28 09:12:21 2008 +0000
@@ -58,40 +58,19 @@
 
 /*****************************************************************************/
 
-bool operator<(
-        const ec_ioctl_config_t &a,
-        const ec_ioctl_config_t &b
-        )
-{
-    return a.alias < b.alias
-        || (a.alias == b.alias && a.position < b.position);
-}
-
-/*****************************************************************************/
-
 /** Lists the bus configuration.
  */
 void CommandConfig::execute(MasterDevice &m, const StringVector &args)
 {
-    ec_ioctl_master_t master;
-    unsigned int i;
-    ec_ioctl_config_t config;
-    ConfigList configList;
+    ConfigList configs;
 
     m.open(MasterDevice::Read);
-    m.getMaster(&master);
-
-    for (i = 0; i < master.config_count; i++) {
-        m.getConfig(&config, i);
-        configList.push_back(config);
-    }
-
-    configList.sort();
+    configs = selectedConfigs(m);
 
     if (getVerbosity() == Verbose) {
-        showDetailedConfigs(m, configList);
+        showDetailedConfigs(m, configs);
     } else {
-        listConfigs(m, configList);
+        listConfigs(m, configs);
     }
 }
 
--- a/tool/CommandConfig.h	Mon Jul 28 08:45:28 2008 +0000
+++ b/tool/CommandConfig.h	Mon Jul 28 09:12:21 2008 +0000
@@ -32,8 +32,6 @@
 			string state;
 		};
 
-		typedef list<ec_ioctl_config_t> ConfigList;
-
 		void showDetailedConfigs(MasterDevice &, const ConfigList &);
 		void listConfigs(MasterDevice &m, const ConfigList &);
 };