Fix detection of zero payload length packets #71
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 subsequentif self.payIndex < self.bytesToRec
would never trigger asself.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.