From d4f3ad82f91dc9c032a37110ffe0abd11cb39464 Mon Sep 17 00:00:00 2001 From: Andreas Fritiofson Date: Tue, 6 Feb 2024 18:42:27 +0100 Subject: [PATCH] Fix PDO mapping with OD_ARRAY entries The second entry is returned from co_entry_find(), for array or record objects, when that entry has the OD_ARRAY flag set. So for these objects the mapped entry pointer in the PDO will always point to the same entry regardless of the subindex of the mapping. Therefore, the PDO packing and unpacking must not consider the subindex field of the mapped entry when storing or fetching the value. Instead it needs to look at the actual mapped subindex to access the correct data. Change-Id: I983f25bdeb10de72f7522d7a2f912e0c885e59fb --- src/co_pdo.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/co_pdo.c b/src/co_pdo.c index 6eb18a2..7a74238 100644 --- a/src/co_pdo.c +++ b/src/co_pdo.c @@ -84,11 +84,12 @@ void co_pdo_pack (co_net_t * net, co_pdo_t * pdo) const co_entry_t * entry = pdo->entries[ix]; const co_obj_t * obj = pdo->objs[ix]; size_t bitlength = pdo->mappings[ix] & 0xFF; + uint8_t subindex = (pdo->mappings[ix] >> 8) & 0xFF; uint64_t value = 0; if (entry != NULL) { - co_od_get_value (net, obj, entry, entry->subindex, &value); + co_od_get_value (net, obj, entry, subindex, &value); } bitslice_set (&pdo->frame, offset, bitlength, value); @@ -106,12 +107,13 @@ void co_pdo_unpack (co_net_t * net, co_pdo_t * pdo) const co_entry_t * entry = pdo->entries[ix]; const co_obj_t * obj = pdo->objs[ix]; size_t bitlength = pdo->mappings[ix] & 0xFF; + uint8_t subindex = (pdo->mappings[ix] >> 8) & 0xFF; uint64_t value; if (entry != NULL) { value = bitslice_get (&pdo->frame, offset, bitlength); - co_od_set_value (net, obj, entry, entry->subindex, value); + co_od_set_value (net, obj, entry, subindex, value); } offset += bitlength;