Stream.find() functions don't find bytes as of 0x80 from HardwareSerial/SoftwareSerial
- Dominant language
- Java
- Stars
- 14.6k
- Forks
- 7k
- PR merge metrics
- No merged PRs in 30d
Description
HardwareSerial/SoftwareSerial::read() return a byte where the functions are defined to return an int. The implicit conversion from "unsigned char/uint8_t" to int returns 0xFFAA (= -86) for the received byte 0xAA.
The function Stream::findMulti() then tests the integer returned by Stream::timedRead() with "c < 0" instead of "c == -1" to distinguish between a received byte and -1 for still nothing available on the stream.
Therefore the function Stream.find() comes back with -1 after timeout, although read() received the byte 0xAA.
It took a lot of time to find out the reason why I didn't found the start byte 0xAA on the stream from my MP3 module response.
Contributor guide
Research direction
Start with HardwareSerial::read(), SoftwareSerial::read(), and Stream::findMulti(), especially the call through Stream::timedRead(). Trace how received bytes at or above 0x80 are converted and distinguished from -1; done means Stream.find() recognizes such bytes instead of timing out.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100