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

Fix detection of zero payload length packets #71

Merged
merged 1 commit into from
Jan 19, 2024
Merged

Fix detection of zero payload length packets #71

merged 1 commit into from
Jan 19, 2024

Conversation

alpyen
Copy link
Contributor

@alpyen alpyen commented Jan 19, 2024

I encountered some strange behaviour during the usage of this library, especially when sending good amounts of data quite often. The status would sometimes return me CRC_ERROR, etc. but after a while the program would simply hang.

I traced this back to the state machine which does not discard packets whose packet length is 0.
This way the fsm would always hang in find_payload because the subsequent if self.payIndex < self.bytesToRec would never trigger as self.bytesToRec was zero.

While the library cannot send packets with zero payload length I believe, this fault can still occur during transmissions.
Since the fsm locks itself out from proceeding to the next states, the library keeps spinning in the same state forever.

My change adds the check to acknowledge a packet as valid if it's payload length is bigger than zero but smaller or equal the maximum packet size, otherwise discard it.
I checked the Arduino implementation of this library and the 'greater than zero' check is present there, but not here.

@PowerBroker2
Copy link
Owner

Good catch - thanks!

@PowerBroker2 PowerBroker2 merged commit ccedcec into PowerBroker2:master Jan 19, 2024
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

Successfully merging this pull request may close these issues.

None yet

2 participants