Added ec_slave_validate()
authorFlorian Pose <fp@igh-essen.com>
Wed, 18 Oct 2006 08:59:53 +0000
changeset 410 3b8e94d623ab
parent 409 bc4c852e1b93
child 411 42d239bab6ae
Added ec_slave_validate()
master/domain.c
master/slave.c
master/slave.h
--- a/master/domain.c	Tue Oct 17 14:50:04 2006 +0000
+++ b/master/domain.c	Wed Oct 18 08:59:53 2006 +0000
@@ -439,16 +439,9 @@
 
     master = domain->master;
 
-    // translate address
+    // translate address and validate slave
     if (!(slave = ecrt_master_get_slave(master, address))) return NULL;
-
-    if (vendor_id != slave->sii_vendor_id ||
-        product_code != slave->sii_product_code) {
-        EC_ERR("Invalid slave type at position %i - Requested: 0x%08X 0x%08X,"
-               " found: 0x%08X 0x%08X\".\n", slave->ring_position, vendor_id,
-               product_code, slave->sii_vendor_id, slave->sii_product_code);
-        return NULL;
-    }
+    if (ec_slave_validate(slave, vendor_id, product_code)) return NULL;
 
     if (!data_ptr) {
         // data_ptr is NULL => mark slave as "registered" (do not warn)
--- a/master/slave.c	Tue Oct 17 14:50:04 2006 +0000
+++ b/master/slave.c	Wed Oct 18 08:59:53 2006 +0000
@@ -903,6 +903,27 @@
     return 0;
 }
 
+/*****************************************************************************/
+
+/**
+   \return 0 in case of success, else < 0
+*/
+
+int ec_slave_validate(const ec_slave_t *slave, /**< EtherCAT slave */
+                      uint32_t vendor_id, /**< vendor ID */
+                      uint32_t product_code /**< product code */
+                      )
+{
+    if (vendor_id != slave->sii_vendor_id ||
+        product_code != slave->sii_product_code) {
+        EC_ERR("Invalid slave type at position %i - Requested: 0x%08X 0x%08X,"
+               " found: 0x%08X 0x%08X\".\n", slave->ring_position, vendor_id,
+               product_code, slave->sii_vendor_id, slave->sii_product_code);
+        return -1;
+    }
+    return 0;
+}
+
 /******************************************************************************
  *  Realtime interface
  *****************************************************************************/
--- a/master/slave.h	Tue Oct 17 14:50:04 2006 +0000
+++ b/master/slave.h	Wed Oct 18 08:59:53 2006 +0000
@@ -271,6 +271,8 @@
 int ec_slave_is_coupler(const ec_slave_t *);
 int ec_slave_has_subbus(const ec_slave_t *);
 
+int ec_slave_validate(const ec_slave_t *, uint32_t, uint32_t);
+
 /*****************************************************************************/
 
 #endif