Skip to content

Conversation

acolomb
Copy link
Member

@acolomb acolomb commented Sep 4, 2025

Fix mixed up mapping parameter record index numbers in class PDO. The access by this index number mixed up the two number ranges. The CiA 301 standard defines:

  • Object 1600h to 17FFh: RPDO mapping parameter
  • Object 1A00h to 1BFFh: TPDO mapping parameter

The test was also wrong, because it added the two tested variables to the TPDO1, while testing the __getitem__ lookup with index 0x1600.

Support lookup by mapping record and communication parameter record index in TPDO and RPDO classes, by storing record index offsets for each PdoMaps collection. These two PdoBase-derived classes only supported numeric access based on the sequential index, not with the mapping parameter record index like the PDO class. Implement a fallback to check those if the regular index lookup fails. Fix docstrings to cover whole RPDO / TPDO parameter index ranges.

Support lookup by communication parameter record index in generic PDO class, by storing each PDO under two different index numbers in the dummy PdoMaps object's maps attribute. That would duplicate them in sequential access while iterating / counting though, so override the PdoBase dunder methods to explicitly chain just the two sub-sequences rx and tx. This class now uses a proper PdoMaps proxy object as well, instead of overwriting it with a custom dictionary. To allow this dummy usage, adjust its constructor to skip generating entries. Add some explanation why relative indices cannot be used here.

Copy link

codecov bot commented Sep 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@acolomb
Copy link
Member Author

acolomb commented Sep 4, 2025

This is currently based on, and includes the changes from #609, after basically factoring out the unrelated fixes from that PR.

@acolomb acolomb linked an issue Sep 4, 2025 that may be closed by this pull request
The access by this index number mixed up the two number ranges.  The
CiA 301 standard defines:

* Object 1600h to 17FFh: RPDO mapping parameter
* Object 1A00h to 1BFFh: TPDO mapping parameter

The test was also wrong, because it added the two tested variables to
the TPDO1, while testing the __getitem__ lookup with index 0x1600.
These two PdoBase-derived classes only supported numeric access based
on the sequential index, not with the mapping parameter record index
like the PDO class.  Implement a fallback to check that if the regular
index lookup fails.
The mechanisms to lookup objects, implemented in class PdoMaps, did
not apply to the PDO class itself, because it simply used a dictionary
instead of a PdoMaps object.  That also violates the static typing
rules.

Make the PdoBase.maps attribute mandatory and accept only type
PdoMaps.  To allow a basically "empty" PdoMaps object, adjust its
constructor to skip adding entries when neither offset parameter is
given as non-zero.  Instead, access the PdoMaps.maps attribute
directly to inject the offset-based TX and RX PdoMap objects in the
PDO class constructor.  Add some explanation why relative indices
cannot be used here.
This does not work for the generic, joined accessor class PDO yet.
Store each PDO under two different index numbers in the dummy PdoMaps
object's "maps" attribute.  That would duplicate them in sequential
access while iterating / counting though, so override the PdoBase
dunder methods to explicitly chain just the two sub-sequences rx and
tx.
The base iterators of rx and tx return a 1-based sequence, while the
wrapping PDO class allows only mapping or communication record index
numbers to identify a PdoMap object.  Return the mapping record's
index from the iterator to avoid ambiguity.

Add tests to verify the returned objects are actually the RPDO and
TPDO members (in this order), with strictly increasing index numbers.
@acolomb acolomb force-pushed the pdo-getitem-access-patterns branch from 2635b3f to 7e67d90 Compare September 22, 2025 19:31
@acolomb acolomb merged commit e58a653 into canopen-python:master Sep 22, 2025
4 of 5 checks passed
@acolomb acolomb deleted the pdo-getitem-access-patterns branch September 22, 2025 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't access T/RPDO via ID

1 participant