jablotron80 icon indicating copy to clipboard operation
jablotron80 copied to clipboard

Simplify checksum code

Open perexg opened this issue 2 years ago • 5 comments
trafficstars

Hi, the checksum code used in the original Windows application is pretty simple:

        def checksum(msg):
            sum = 0x7f
            for byte in msg:
                for j in range(8):
                    sum <<= 1
                    if (byte & 0x80) == 0x80:
                        sum += 1
                    if (sum & 0x80) == 0x80:
                        sum ^= 0xa3
                    byte <<= 1
            return sum

        # binary message without trailing 0xFF
        if len(msg) > 1 and checksum(msg) != 0:
            raise SomeCheckSumError

perexg avatar Apr 03 '23 19:04 perexg

I presume this is saying it is more complex that necessary in this repo. Can type refer to it by module/line number?

mattsaxon avatar Apr 03 '23 19:04 mattsaxon

The whole https://github.com/tahvane1/jablotron80/commit/1968736d2e500143b295cbc28cf04eea23b2e1ca can be replaced. I am using this code in my own project for many years.

perexg avatar Apr 03 '23 19:04 perexg

That's a whole lot simpler! But can't we check it is as complete..... when you say 'original windows application', what do you refer? Can you reference it please?

mattsaxon avatar Apr 03 '23 19:04 mattsaxon

Original Jablotron O-link software. I was lucky - I found and disassembled this checksum code. Looking to your implementation, it is not perfect (seems just "guessing" on some lines).

perexg avatar Apr 03 '23 19:04 perexg

Quite possibly, I lifted the code from somewhere I found an implementation.

Given your example is O-Link its 'better' IMO.

My code does currently seem to get some CRC issues in normal running. I don't know if others see these issues reported in their logs

mattsaxon avatar Apr 03 '23 20:04 mattsaxon