Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 8 additions & 7 deletions canopen/emcy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ def __init__(self):

def on_emcy(self, can_id, data, timestamp):
code, register, data = self.EMCY_STRUCT.unpack(data)
if code & 0xFF == 0:
entry = EmcyError(code, register, data, timestamp)

with self.emcy_received:
self.log.append(entry)
self.active.append(entry)
self.emcy_received.notify_all()

if code & 0xFFFF == 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that I made a mistake masking out the lower byte when I actually meant to mask out the higher byte as specified here for example (reset = 00xx). So I think it should be:

if code & 0xFF00 == 0:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Sorry, I did not check DS-301 error codes.

# Error reset
self.active = []
for callback in self.callbacks:
callback(None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking it may be better skip using None as a representation for reset and just use the same emcy object regardless if it is a reset or an actual error. Then you can get timestamp for the reset and so on. What do you think? Then the documentation would have to be changed slightly as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

else:
entry = EmcyError(code, register, data, timestamp)
#print("EMCY received for node %d: %s" % (can_id & 0x7F, entry))
with self.emcy_received:
self.log.append(entry)
self.active.append(entry)
self.emcy_received.notify_all()
for callback in self.callbacks:
callback(entry)

Expand Down
2 changes: 1 addition & 1 deletion test/test_emcy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_emcy_list(self):
self.assertEqual(emcy_node.active[1], error)

emcy_node.on_emcy(0x81, b'\x00\x00\x00\x00\x00\x00\x00\x00', 1473418397.0)
self.assertEqual(len(emcy_node.log), 2)
self.assertEqual(len(emcy_node.log), 3)
self.assertEqual(len(emcy_node.active), 0)

def test_str(self):
Expand Down