From 4a9d9faa6a8d23d1b4716f02f8df70429ee36060 Mon Sep 17 00:00:00 2001
From: Florian Pose <fp@igh-essen.com>
Date: Wed, 18 Jun 2008 11:16:30 +0000
Subject: [PATCH] Output attachment failure messages only when debugging.

---
 TODO                  |  2 --
 master/slave_config.c | 46 +++++++++++++++++++++++--------------------
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/TODO b/TODO
index 8dce3bf7..242edc99 100644
--- a/TODO
+++ b/TODO
@@ -10,8 +10,6 @@ Version 1.4.0:
 
 * Remove get_cycles() calls and references to cpu_khz to increase
   portability.
-* Make ecrt_master_slave_config() return no error when slave is not present
-  or invalid.
 * Make scanning and configuration run parallel (each).
 * Adapt remaining examples.
 * READMEs for examples.
diff --git a/master/slave_config.c b/master/slave_config.c
index 65618590..a7c19ad9 100644
--- a/master/slave_config.c
+++ b/master/slave_config.c
@@ -174,37 +174,39 @@ int ec_slave_config_attach(
 
     if (!(slave = ec_master_find_slave(
                     sc->master, sc->alias, sc->position))) {
-        EC_WARN("Failed to find slave for configuration %u:%u.\n",
-                sc->alias, sc->position);
+        if (sc->master->debug_level)
+            EC_DBG("Failed to find slave for configuration %u:%u.\n",
+                    sc->alias, sc->position);
         return -1;
     }
 
 	if (slave->config) {
-		EC_ERR("Failed to attach slave configuration %u:%u. Slave %u"
-				" already has a configuration!\n", sc->alias,
-				sc->position, slave->ring_position);
-		return -2;
-	}
-	if (slave->sii.vendor_id != sc->vendor_id
-			|| slave->sii.product_code != sc->product_code) {
-		EC_ERR("Slave %u has an invalid type (0x%08X/0x%08X) for"
-				" configuration %u:%u (0x%08X/0x%08X).\n",
-				slave->ring_position, slave->sii.vendor_id,
-				slave->sii.product_code, sc->alias, sc->position,
-				sc->vendor_id, sc->product_code);
-		return -3;
+        if (sc->master->debug_level)
+            EC_DBG("Failed to attach slave configuration %u:%u. Slave %u"
+                    " already has a configuration!\n", sc->alias,
+                    sc->position, slave->ring_position);
+        return -2;
+    }
+    if (slave->sii.vendor_id != sc->vendor_id
+            || slave->sii.product_code != sc->product_code) {
+        if (sc->master->debug_level)
+            EC_DBG("Slave %u has an invalid type (0x%08X/0x%08X) for"
+                    " configuration %u:%u (0x%08X/0x%08X).\n",
+                    slave->ring_position, slave->sii.vendor_id,
+                    slave->sii.product_code, sc->alias, sc->position,
+                    sc->vendor_id, sc->product_code);
+        return -3;
 	}
 
 	// attach slave
 	slave->config = sc;
 	sc->slave = slave;
+    ec_slave_request_state(slave, EC_SLAVE_STATE_OP);
 
     if (sc->master->debug_level)
         EC_DBG("Attached slave %u to config %u:%u.\n",
                 slave->ring_position, sc->alias, sc->position);
 
-    ec_slave_request_state(slave, EC_SLAVE_STATE_OP);
-
 	return 0;
 }
 
@@ -259,14 +261,16 @@ void ec_slave_config_load_default_mapping(
                 " config %u:%u.\n", pdo->index, sc->alias, sc->position);
 
     if (!sc->slave) {
-        EC_WARN("Failed to load default Pdo configuration for %u:%u:"
-                " Slave not found.\n", sc->alias, sc->position);
+        if (sc->master->debug_level)
+            EC_DBG("Failed to load default Pdo configuration for %u:%u:"
+                    " Slave not found.\n", sc->alias, sc->position);
         return;
     }
 
     if (!(sync = ec_slave_get_pdo_sync(sc->slave, pdo->dir))) {
-        EC_WARN("Slave %u does not provide a default Pdo"
-                " configuration!\n", sc->slave->ring_position);
+        if (sc->master->debug_level)
+            EC_DBG("Slave %u does not provide a default Pdo"
+                    " configuration!\n", sc->slave->ring_position);
         return;
     }
 
-- 
GitLab