Skip to content

Commit

Permalink
Add support for loading DCF configuration to remote node
Browse files Browse the repository at this point in the history
  • Loading branch information
meifonglow committed May 26, 2024
1 parent b55ce5c commit b9534aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 9 additions & 1 deletion canopen/node/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,16 @@ def __load_configuration_helper(self, index, subindex, name, value):

def load_configuration(self):
''' Load the configuration of the node from the object dictionary.'''
# First apply PDO configuration from object dictionary
self.pdo.read(from_od=True)
self.pdo.save()

# Now apply all other records in object dictionary
for obj in self.object_dictionary.values():
if isinstance(obj, ODRecord) or isinstance(obj, ODArray):
if 0x1400 <= obj.index < 0x1c00:
# Ignore PDO related objects
logger.debug(f"{obj.index:#06x}: {obj.name} already applied by pdo.save()")
elif isinstance(obj, ODRecord) or isinstance(obj, ODArray):
for subobj in obj.values():
if isinstance(subobj, ODVariable) and subobj.writable and (subobj.value is not None):
self.__load_configuration_helper(subobj.index, subobj.subindex, subobj.name, subobj.value)
Expand Down
13 changes: 11 additions & 2 deletions canopen/pdo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,20 @@ def add_callback(self, callback: Callable[["Map"], None]) -> None:
self.callbacks.append(callback)

def read(self, from_od=False) -> None:
"""Read PDO configuration for this map using SDO."""
"""Read PDO configuration for this map
:param from_od:
Read using SDO if False, read from object dictionary if True.
When reading from object dictionary, if DCF populated a value, the
DCF value will be used, otherwise the EDS default will be used instead.
"""

def _raw_from(param):
if from_od:
return param.od.default
if param.od.value is not None:
return param.od.value
else:
return param.od.default
return param.raw

cob_id = _raw_from(self.com_record[1])
Expand Down

0 comments on commit b9534aa

Please sign in to comment.