Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
communication: minimize time spent waiting for serial bytes
The previous implementation would always block until an unrealistic 1000 bytes had been read from the serial port, causing the read() call to end with the configured timeout (100ms) for every message. This put a limit to the throughput at 10 messages per second, and imposed a latency of about 100ms since even after receiving a complete SLIP packet the read() call would block waiting to reach 1000 bytes. By waiting for a single byte, we make sure to unblock the read as soon as some data is available, while avoiding a CPU-heavy busy loop (if the firmware is completely silent, the read() call will block for 100ms each time, like it did before). To avoid extra read passes, we try to pull as many bytes as are available in the serial buffer once we have received at least one byte. Also, in the case where we have received multiple messages in a single read, we avoid blocking on a wait for more data by only going to the serial port once we have consumed all already-read messages.
- Loading branch information