tfmini icon indicating copy to clipboard operation
tfmini copied to clipboard

Issue with checksum calculation

Open jonsinfinity1 opened this issue 5 years ago • 1 comments

Using TFMini v1.8 device the frame size is 7. The code that calculates the checksum adds all positions that are less than frame size - 2. I found that the checksum was always 9 greater than the calculation. Position 5 is always 9 but not included in the calculation.

This caused the following error: TF Mini error: too many measurement attempts Last error: ERROR_SERIAL_BADCHECKSUM 65535 cm sigstr: 65535

After changing the calculation to include position 5 like so: if (i < TFMINI_FRAME_SIZE-1) { checksum += frame[i]; }

instead of: if (i < TFMINI_FRAME_SIZE-2) { checksum += frame[i]; }

Things are now working.

I'm not sure what the frame size is of other TF Devices. Are they different? Maybe older versions have a frame size of 8? Anyway, just wanted to report what I found.

jonsinfinity1 avatar Jul 14 '20 00:07 jonsinfinity1

Hmmm, that's very interesting. It's certainly possible that they've changed the protocol slightly in the latest revisions of their devices.

Would you like to submit a pull request that:

  1. Adds a version parameter passed to the class constructor, and some defines (e.g. VER_1_0, VER_1_8) for the version
  2. Performs the checksum calculation based on the version
  3. Includes the parameter in the example?

PeterAJansen avatar Jul 14 '20 05:07 PeterAJansen