python-ant icon indicating copy to clipboard operation
python-ant copied to clipboard

Checksum incorrectly calculated... sometimes.

Open Zebble opened this issue 11 years ago • 1 comments

Changed in getChecksum in message.py:

checksum = (checksum ^ ord(byte)) % 0xFF

To:

checksum = (checksum ^ ord(byte))

Wasn't properly creating checksum on some streams. Here's an example. getChecksum would fail on the "A4" checksum in the Read response. This was on a Dynastream ANTUSB-m.

Write:

A4 02 4D 00 54 BF

Read:

A4 07 54 08 08 00 BA 36 00 DF A4

-wade

Zebble avatar Jan 20 '15 03:01 Zebble

More precisely, I think the author wanted to write: checksum = (checksum ^ ord(byte)) & 0xFF for preventing some errors with integer overflow superior to 0xFF, however I think that case seems to be impossible with a range of bytes. With the current algorithm, if the first operand return 0xFF, the result will be 0, but the expected result should be 0xFF. This is the only value which fail with the used operator %. 0xAB % 0xFF => 0xAB (Good) 0xFF % 0xFF => 0 (failed, expected 0xFF) with &: 0xAB & 0xFF => 0xAB 0xFF & 0xFF => 0xFF

SamyCookie avatar Apr 02 '15 16:04 SamyCookie