Added ecrt_master_get_slave_by_pos().
authorFlorian Pose <fp@igh-essen.com>
Fri, 10 Aug 2007 13:46:34 +0000
changeset 697 6f658c2082fd
parent 696 24fac09b5b26
child 698 6693ea7c9047
Added ecrt_master_get_slave_by_pos().
NEWS
TODO
include/ecrt.h
master/master.c
--- a/NEWS	Fri Aug 10 13:35:11 2007 +0000
+++ b/NEWS	Fri Aug 10 13:46:34 2007 +0000
@@ -26,6 +26,8 @@
   - ecrt_master_get_slave() got additional parameters to check for vendor ID
     and product code.
   - Removed addressing scheme "X:Y" for ecrt_master_get_slave().
+  - Added ecrt_master_get_slave_by_pos() to avoid the string handling of
+    ecrt_master_get_slave().
   - Added ecrt_master_get_status() to get status information about the bus.
   - Added functions to set up an alternative PDO mapping for a slave, i. e.
     ec_slave_pdo_mapping_clear(), ec_slave_pdo_mapping_add() and
--- a/TODO	Fri Aug 10 13:35:11 2007 +0000
+++ b/TODO	Fri Aug 10 13:46:34 2007 +0000
@@ -8,7 +8,6 @@
 
 * Issues for release 1.3.0:
   - Take broadcast MAC address to register the first ethernet device.
-  - Implement ecrt_get_slave() with integer argument as ring position.
   - Handle missing rc_status in init script.
 
 * Future features:
--- a/include/ecrt.h	Fri Aug 10 13:35:11 2007 +0000
+++ b/include/ecrt.h	Fri Aug 10 13:46:34 2007 +0000
@@ -147,6 +147,8 @@
 
 ec_slave_t *ecrt_master_get_slave(const ec_master_t *, const char *,
         uint32_t vendor_id, uint32_t product_code);
+ec_slave_t *ecrt_master_get_slave_by_pos(const ec_master_t *, uint16_t,
+        uint32_t vendor_id, uint32_t product_code);
 
 int ecrt_master_activate(ec_master_t *master);
 
--- a/master/master.c	Fri Aug 10 13:35:11 2007 +0000
+++ b/master/master.c	Fri Aug 10 13:46:34 2007 +0000
@@ -1557,6 +1557,41 @@
 /*****************************************************************************/
 
 /**
+ * Obtains a slave pointer by its ring position.
+ * A valid slave pointer is only returned, if vendor ID and product code are
+ * matching.
+ * \return pointer to the slave on success, else NULL
+ * \ingroup RealtimeInterface
+ */
+
+ec_slave_t *ecrt_master_get_slave_by_pos(
+        const ec_master_t *master, /**< EtherCAT master */
+        uint16_t ring_position, /**< ring position */
+        uint32_t vendor_id, /**< vendor ID */
+        uint32_t product_code /**< product code */
+        )
+{
+    ec_slave_t *slave;
+    unsigned int found = 0;
+
+    list_for_each_entry(slave, &master->slaves, list) {
+        if (slave->ring_position == ring_position) {
+            found = 1;
+            break;
+        }
+    }
+
+    if (!found) {
+        EC_ERR("Slave index out of range!\n");
+        return NULL;
+    }
+
+    return ec_slave_validate(slave, vendor_id, product_code) ? NULL : slave;
+}
+
+/*****************************************************************************/
+
+/**
    Sets the locking callbacks.
    The request_cb function must return zero, to allow another instance
    (the EoE process for example) to access the master. Non-zero means,
@@ -1602,6 +1637,7 @@
 EXPORT_SYMBOL(ecrt_master_receive);
 EXPORT_SYMBOL(ecrt_master_callbacks);
 EXPORT_SYMBOL(ecrt_master_get_slave);
+EXPORT_SYMBOL(ecrt_master_get_slave_by_pos);
 EXPORT_SYMBOL(ecrt_master_get_status);
 
 /** \endcond */