Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions canopen/nmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,13 @@ def __init__(self, node_id: int):
self._callbacks: List[Callable[[int], None]] = []

def on_heartbeat(self, can_id, data, timestamp):
new_state, = struct.unpack_from("B", data)
# Mask out toggle bit
new_state &= 0x7F
logger.debug("Received heartbeat can-id %d, state is %d", can_id, new_state)

with self.state_update:
self.timestamp = timestamp
new_state, = struct.unpack_from("B", data)
# Mask out toggle bit
new_state &= 0x7F
logger.debug("Received heartbeat can-id %d, state is %d", can_id, new_state)
for callback in self._callbacks:
callback(new_state)
if new_state == 0:
# Boot-up, will go to PRE-OPERATIONAL automatically
self._state = 127
Expand All @@ -136,6 +135,9 @@ def on_heartbeat(self, can_id, data, timestamp):
self._state_received = new_state
self.state_update.notify_all()

for callback in self._callbacks:
callback(new_state)

def send_command(self, code: int):
"""Send an NMT command code to the node.

Expand Down
Loading