From 808ad3e2f1d924d71be01988cea55d6ba3418bc0 Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Fri, 10 Aug 2007 13:46:34 +0000 Subject: [PATCH] Added ecrt_master_get_slave_by_pos(). --- NEWS | 2 ++ TODO | 1 - include/ecrt.h | 2 ++ master/master.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index dd8ab964..0264bce7 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,8 @@ Changes in version 1.3.0: - 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 diff --git a/TODO b/TODO index c6e3a5db..efe76bbc 100644 --- a/TODO +++ b/TODO @@ -8,7 +8,6 @@ $Id$ * 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: diff --git a/include/ecrt.h b/include/ecrt.h index 57829301..9a90db99 100644 --- a/include/ecrt.h +++ b/include/ecrt.h @@ -147,6 +147,8 @@ ec_domain_t *ecrt_master_create_domain(ec_master_t *master); 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); diff --git a/master/master.c b/master/master.c index 1ae6a8db..06526dd4 100644 --- a/master/master.c +++ b/master/master.c @@ -1556,6 +1556,41 @@ ec_slave_t *ecrt_master_get_slave( /*****************************************************************************/ +/** + * 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 @@ -1602,6 +1637,7 @@ EXPORT_SYMBOL(ecrt_master_send); 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 */