diff --git a/master/pdo.c b/master/pdo.c index 73c034eb32142fc346552d2513e42dc2d9c1f162..9271f59373358cdd4bb1bba479aa754e78f8326f 100644 --- a/master/pdo.c +++ b/master/pdo.c @@ -229,3 +229,43 @@ int ec_pdo_equal_entries( } /*****************************************************************************/ + +/** + */ +unsigned int ec_pdo_entry_count( + const ec_pdo_t *pdo /**< Pdo. */ + ) +{ + const ec_pdo_entry_t *entry; + unsigned int num = 0; + + list_for_each_entry(entry, &pdo->entries, list) { + num++; + } + + return num; +} + +/*****************************************************************************/ + +/** Finds a Pdo entry via its position in the list. + * + * Const version. + */ +const ec_pdo_entry_t *ec_pdo_find_entry_by_pos_const( + const ec_pdo_t *pdo, /**< Pdo. */ + unsigned int pos /**< Position in the list. */ + ) +{ + const ec_pdo_entry_t *entry; + + list_for_each_entry(entry, &pdo->entries, list) { + if (pos--) + continue; + return entry; + } + + return NULL; +} + +/*****************************************************************************/ diff --git a/master/pdo.h b/master/pdo.h index 1571b39ca4d88bd993b8454193b0c95f44643b91..3c7ecd2d0ea16ccd989bd14559c4bb04d34b2a18 100644 --- a/master/pdo.h +++ b/master/pdo.h @@ -73,6 +73,9 @@ int ec_pdo_set_name(ec_pdo_t *, const char *); ec_pdo_entry_t *ec_pdo_add_entry(ec_pdo_t *, uint16_t, uint8_t, uint8_t); int ec_pdo_copy_entries(ec_pdo_t *, const ec_pdo_t *); int ec_pdo_equal_entries(const ec_pdo_t *, const ec_pdo_t *); +unsigned int ec_pdo_entry_count(const ec_pdo_t *); +const ec_pdo_entry_t *ec_pdo_find_entry_by_pos_const( + const ec_pdo_t *, unsigned int); /*****************************************************************************/