Skip to content

Commit ad68c17

Browse files
nattgrishefloryd
authored andcommitted
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
1 parent d78cccc commit ad68c17

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/co_pdo.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ void co_pdo_pack (co_net_t * net, co_pdo_t * pdo)
8484
const co_entry_t * entry = pdo->entries[ix];
8585
const co_obj_t * obj = pdo->objs[ix];
8686
size_t bitlength = pdo->mappings[ix] & 0xFF;
87+
uint8_t subindex = (pdo->mappings[ix] >> 8) & 0xFF;
8788
uint64_t value = 0;
8889

8990
if (entry != NULL)
9091
{
91-
co_od_get_value (net, obj, entry, entry->subindex, &value);
92+
co_od_get_value (net, obj, entry, subindex, &value);
9293
}
9394

9495
bitslice_set (&pdo->frame, offset, bitlength, value);
@@ -106,12 +107,13 @@ void co_pdo_unpack (co_net_t * net, co_pdo_t * pdo)
106107
const co_entry_t * entry = pdo->entries[ix];
107108
const co_obj_t * obj = pdo->objs[ix];
108109
size_t bitlength = pdo->mappings[ix] & 0xFF;
110+
uint8_t subindex = (pdo->mappings[ix] >> 8) & 0xFF;
109111
uint64_t value;
110112

111113
if (entry != NULL)
112114
{
113115
value = bitslice_get (&pdo->frame, offset, bitlength);
114-
co_od_set_value (net, obj, entry, entry->subindex, value);
116+
co_od_set_value (net, obj, entry, subindex, value);
115117
}
116118

117119
offset += bitlength;

0 commit comments

Comments
 (0)