From c8a8eddad7dfc0392170718d8103c5d6cc353aff Mon Sep 17 00:00:00 2001
From: Florian Pose <fp@igh-essen.com>
Date: Fri, 6 Jun 2008 09:22:57 +0000
Subject: [PATCH] Added ec_slave_get_sdo_by_pos_const() and
 ec_slave_sdo_count().

---
 master/slave.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 master/slave.h |  2 ++
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/master/slave.c b/master/slave.c
index 39525938..d2ab8495 100644
--- a/master/slave.c
+++ b/master/slave.c
@@ -1193,7 +1193,7 @@ void ec_slave_sdo_dict_info(const ec_slave_t *slave, /**< EtherCAT slave */
  */
 
 ec_sdo_t *ec_slave_get_sdo(
-        ec_slave_t *slave /**< EtherCAT slave */,
+        ec_slave_t *slave, /**< EtherCAT slave */
         uint16_t index /**< Sdo index */
         )
 {
@@ -1209,6 +1209,48 @@ ec_sdo_t *ec_slave_get_sdo(
 
 /*****************************************************************************/
 
+/** Get an Sdo from the dictionary, given its position in the list.
+ * \returns The desired Sdo, or NULL.
+ */
+
+const ec_sdo_t *ec_slave_get_sdo_by_pos_const(
+        const ec_slave_t *slave, /**< EtherCAT slave. */
+        uint16_t sdo_position /**< Sdo list position. */
+        )
+{
+    const ec_sdo_t *sdo;
+
+    list_for_each_entry(sdo, &slave->sdo_dictionary, list) {
+        if (sdo_position--)
+            continue;
+        return sdo;
+    }
+
+    return NULL;
+}
+
+/*****************************************************************************/
+
+/** Get the number of Sdos in the dictionary.
+ * \returns Sdo count.
+ */
+
+uint16_t ec_slave_sdo_count(
+        const ec_slave_t *slave /**< EtherCAT slave. */
+        )
+{
+    const ec_sdo_t *sdo;
+    uint16_t count = 0;
+
+    list_for_each_entry(sdo, &slave->sdo_dictionary, list) {
+        count++;
+    }
+
+    return count;
+}
+
+/*****************************************************************************/
+
 /** Finds a mapped Pdo.
  * \returns The desired Pdo object, or NULL.
  */
diff --git a/master/slave.h b/master/slave.h
index 50b44be6..d2dc25f8 100644
--- a/master/slave.h
+++ b/master/slave.h
@@ -223,6 +223,8 @@ ec_sync_t *ec_slave_get_pdo_sync(ec_slave_t *, ec_direction_t);
 void ec_slave_sdo_dict_info(const ec_slave_t *,
         unsigned int *, unsigned int *);
 ec_sdo_t *ec_slave_get_sdo(ec_slave_t *, uint16_t);
+const ec_sdo_t *ec_slave_get_sdo_by_pos_const(const ec_slave_t *, uint16_t);
+uint16_t ec_slave_sdo_count(const ec_slave_t *);
 const ec_pdo_t *ec_slave_find_pdo(const ec_slave_t *, uint16_t);
 
 /*****************************************************************************/
-- 
GitLab