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

Problem with getStructuredPacket when receiving large payloads (> 62 bytes) #137

Open
filipecustodio opened this issue Oct 11, 2024 · 0 comments

Comments

@filipecustodio
Copy link

When using the getStructuredPacket() utility function to receive a payload over 62 bytes, a bug will be triggered where the result is always FINGERPRINT_BADPACKET.

The end condition of the function is (lines 606 - 611):

  if ((idx - 8) == packet->length) {

#ifdef FINGERPRINT_DEBUG
Serial.println(" OK ");
#endif
return FINGERPRINT_OK;
}

Which should terminate the read when "length" bytes have been read. However, "length" is not the length of the payload, as it contains 2 extra bytes for the checksum. The correct end condition should be: (idx-8) == packet->length - 2, and before exiting it should read the two additional bytes and validate the checksum.
As it is now, the error condition in line 615 is always triggered if the data being received is >= 62 bytes.

A possible solution would be:

if ((idx-8) == (packet->length - 2) {
// Read the checksum
int8_t hiChecksum = mySerial->read();
int8_t loCheckxum = mySerial->read();
// Validate the checksum of the array packet->data[]
if ( (((int16_t) hiChecksum) << 8) | (int16_t loChecksum) != calcChecksum ) return FINGERPRINT_BADPACKET;
return FINGERPRINT_OK;
}

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

1 participant