Skip to content

Commit

Permalink
Add 'relative' property for COB-ID vars relative to the node-ID (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikbrixandersen committed Jan 6, 2022
1 parent 89bc634 commit a142fb5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions canopen/objectdictionary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ def __init__(self, name: str, index: int, subindex: int = 0):
self.max: Optional[int] = None
#: Default value at start-up
self.default: Optional[int] = None
#: Is the default value relative to the node-ID (only applies to COB-IDs)
self.relative = False
#: The value of this variable stored in the object dictionary
self.value: Optional[int] = None
#: Data type according to the standard as an :class:`int`
Expand Down
2 changes: 2 additions & 0 deletions canopen/objectdictionary/eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ def build_variable(eds, section, node_id, index, subindex=0):
if eds.has_option(section, "DefaultValue"):
try:
var.default_raw = eds.get(section, "DefaultValue")
if '$NODEID' in var.default_raw:
var.relative = True
var.default = _convert_variable(node_id, var.data_type, eds.get(section, "DefaultValue"))
except ValueError:
pass
Expand Down
6 changes: 6 additions & 0 deletions test/test_eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def test_variable(self):
self.assertEqual(var.data_type, canopen.objectdictionary.UNSIGNED16)
self.assertEqual(var.access_type, 'rw')
self.assertEqual(var.default, 0)
self.assertFalse(var.relative)

def test_relative_variable(self):
var = self.od['Receive PDO 0 Communication Parameter']['COB-ID use by RPDO 1']
self.assertTrue(var.relative)
self.assertEqual(var.default, 512 + self.od.node_id)

def test_record(self):
record = self.od['Identity object']
Expand Down

0 comments on commit a142fb5

Please sign in to comment.