Skip to content

Commit

Permalink
Allow using event timer for tpdo timing
Browse files Browse the repository at this point in the history
  • Loading branch information
grantweiss-RaymondCorp committed Jul 29, 2024
1 parent 822009c commit 2305314
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
22 changes: 14 additions & 8 deletions canopen/node/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,21 @@ def _tpdo_configuration_write(self, index, subindex, od, data):
logger.warning("Tried to configure tpdo when not in pre-op")
return

tpdoNum = (index - 0x1800) + 1
if tpdoNum not in self.tpdo.map.keys():
return

if subindex == 0x01:
if len(data) == 4:
tpdoNum = (index - 0x1800) + 1
if tpdoNum in self.tpdo.map.keys():
PDO_NOT_VALID = 1 << 31
RTR_NOT_ALLOWED = 1 << 30
PDO_NOT_VALID = 1 << 31
RTR_NOT_ALLOWED = 1 << 30

cob_id = int.from_bytes(data, 'little') & 0x7FF

cob_id = int.from_bytes(data, 'little') & 0x7FF
self.tpdo.map[tpdoNum].cob_id = cob_id & 0x1FFFFFFF
self.tpdo.map[tpdoNum].enabled = cob_id & PDO_NOT_VALID == 0
self.tpdo.map[tpdoNum].rtr_allowed = cob_id & RTR_NOT_ALLOWED == 0

self.tpdo.map[tpdoNum].cob_id = cob_id & 0x1FFFFFFF
self.tpdo.map[tpdoNum].enabled = cob_id & PDO_NOT_VALID == 0
self.tpdo.map[tpdoNum].rtr_allowed = cob_id & RTR_NOT_ALLOWED == 0
elif subindex == 0x05:
if len(data) == 2:
self.tpdo.map[tpdoNum].event_timer = int.from_bytes(data, 'little')
3 changes: 3 additions & 0 deletions canopen/pdo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,11 @@ def start(self, period: Optional[float] = None) -> None:
# overwrite the reference and can lose our handle to shut it down
self.stop()

# Prefer period, then self.period, then use self.event_timer
if period is not None:
self.period = period
elif self.period is None and self.event_timer and self.trans_type >= 254:
self.period = self.event_timer / 1000

if not self.period:
raise ValueError("A valid transmission period has not been given")
Expand Down

0 comments on commit 2305314

Please sign in to comment.