Skip to content

Commit 96bdf93

Browse files
committed
Fix lower bound check in PDO access by index.
Extend test to cover access via 0x1400 and 0x1600 yielding the same object.
1 parent db9110e commit 96bdf93

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

canopen/pdo/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __getitem__(self, key: Union[int, str]):
4646
raise KeyError("PDO index zero requested for 1-based sequence")
4747
if (
4848
0 < key <= 512 # By PDO Index
49-
or 0x1600 <= key <= 0x1BFF # By RPDO / TPDO mapping or communication record
49+
or 0x1400 <= key <= 0x1BFF # By RPDO / TPDO mapping or communication record
5050
):
5151
return self.map[key]
5252
for pdo_map in self.map.values():

test/test_pdo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def test_pdo_getitem(self):
7373
self.assertIs(node.tpdo[0x2002], by_object_index)
7474
self.assertIs(node.pdo[0x1A00][0x2002], by_object_index)
7575

76+
self.assertIs(node.pdo[0x1400], node.pdo[0x1600])
77+
7678
self.assertRaises(KeyError, lambda: node.pdo[0])
7779
self.assertRaises(KeyError, lambda: node.tpdo[0])
7880
self.assertRaises(KeyError, lambda: node.pdo['DOES NOT EXIST'])

0 commit comments

Comments
 (0)