Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in heartbeat protocol due to toggle bit #150

Closed
eyalcohen opened this issue Mar 19, 2019 · 1 comment
Closed

Crash in heartbeat protocol due to toggle bit #150

eyalcohen opened this issue Mar 19, 2019 · 1 comment
Milestone

Comments

@eyalcohen
Copy link

Hi, great library, thanks for the effort.

When reading NMT messages under the heartbeat protocol, occasionally the highest bit is set for state. I believe this is resulting in a crash because bit 8 is set for the state (PRE-OPERATIONAL state is 0xFF instead of 0x7F for example):

  File "/home/user/miniconda2/envs/abc/lib/python2.7/site-packages/canopen/nmt.py", line 103, in state
    self.send_command(code)
  File "/home/user/miniconda2/envs/abc/lib/python2.7/site-packages/canopen/nmt.py", line 138, in send_command
    super(NmtMaster, self).send_command(code)
  File "/home/user/miniconda2/envs/abc/lib/python2.7/site-packages/canopen/nmt.py", line 72, in send_command
    NMT_STATES[self._state], NMT_STATES[new_state])
KeyError: 255

nmt.py defines the codes for states as below 128

NMT_STATES = {
    0: 'INITIALISING',
    4: 'STOPPED',
    5: 'OPERATIONAL',
    80: 'SLEEP',
    96: 'STANDBY',
    127: 'PRE-OPERATIONAL'
}

The CANopen docs in section 7.2.8.3.2.2 Protocol heartbeat say that bit 8 of slave state is a toggle bit which is toggled with two consecutive NMT messages, so seeing a slave send 0xFF for PRE-OPERATIONAL state could be expected.

If I understand the issue correctly, can we have the above error mask out the toggle bit?

@eyalcohen
Copy link
Author

Thanks!

@christiansandberg christiansandberg added this to the v0.9.0 milestone Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants