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

Checksum incorrectly calculated... sometimes. #25

Open
Zebble opened this issue Jan 20, 2015 · 1 comment
Open

Checksum incorrectly calculated... sometimes. #25

Zebble opened this issue Jan 20, 2015 · 1 comment

Comments

@Zebble
Copy link

Zebble commented Jan 20, 2015

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

jeffmelville added a commit to jeffmelville/python-ant that referenced this issue Mar 24, 2015
@SamyCookie
Copy link

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 added a commit to SamyCookie/python-ant that referenced this issue Apr 3, 2015
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