Skip to content

Crash in heartbeat protocol due to toggle bit #150

@eyalcohen

Description

@eyalcohen

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions