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

read_packet needs to check for leftover data in self._buffer #9

Open
kevinjwalters opened this issue Dec 9, 2018 · 3 comments
Open
Labels
bug Something isn't working

Comments

@kevinjwalters
Copy link

I've noticed a strange buffering phenomena documented in https://forums.adafruit.com/viewtopic.php?f=60&t=144694

I've had a quick glance at the code but my first guess is this is because read_packet() returns None if there's no data coming back from a presumably non-blocking self.uart_rx(). I think the lack of checking for data leftover in self._buffer from a previous call to read_packet() is the problem. That previous call could have picked up two (or more) commands and read_packet() only returns first by design. I've not executed/single-stepped the code here, i'm just guessing from inspection but it seems to match observed behaviour.

@jerryneedell
Copy link
Contributor

FYI - I have reproduced this using the IOS app as well.
This buffering issue does not appear to occur when using the "rugged echo" example https://github.com/adafruit/Adafruit_CircuitPython_BluefruitSPI/blob/master/examples/bluefruitspi_ruggedechotest.py since that code reads the entire receive buffer where the "muny.py" code from the forum post reads one "packet" but there may be multiple packets in the buffer.
I think the issue is with the "muny.py" example and not with the basic module. The example appears to only be anticipating for single color picker requests, not rapid fire button presses.

@kevinjwalters
Copy link
Author

I'm not sure on that. I think any code which deals with a fairly fast or bursty producer and uses read_packet() in a loop will experience this. More so if other things are done in the loop or there are delays meaning that read_packet() isn't hammered away at.

@jerryneedell
Copy link
Contributor

yes, I was just about to correct my post after more testing and thinking about this. It does appear the read_packet is not handling the buffered packets correctly.

@kattni kattni added the bug Something isn't working label May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants