Skip to content

Commit 216fd85

Browse files
committed
drivers/gps: prioritize non-blocking reads over injection (#25535)
1 parent 3995125 commit 216fd85

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/drivers/gps/gps.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,16 @@ int GPS::pollOrRead(uint8_t *buf, size_t buf_length, int timeout)
472472
const int max_timeout = 50;
473473
int timeout_adjusted = math::min(max_timeout, timeout);
474474

475-
handleInjectDataTopic();
476-
477475
if (_interface == GPSHelper::Interface::UART) {
478-
ret = _uart.readAtLeast(buf, buf_length, math::min(character_count, buf_length), timeout_adjusted);
476+
477+
const ssize_t read_at_least = math::min(character_count, buf_length);
478+
479+
// handle injection data before read if caught up
480+
if (_uart.bytesAvailable() < read_at_least) {
481+
handleInjectDataTopic();
482+
}
483+
484+
ret = _uart.readAtLeast(buf, buf_length, read_at_least, timeout_adjusted);
479485

480486
if (ret > 0) {
481487
_num_bytes_read += ret;
@@ -486,6 +492,8 @@ int GPS::pollOrRead(uint8_t *buf, size_t buf_length, int timeout)
486492

487493
} else if ((_interface == GPSHelper::Interface::SPI) && (_spi_fd >= 0)) {
488494

495+
handleInjectDataTopic();
496+
489497
//Poll only for the SPI data. In the same thread we also need to handle orb messages,
490498
//so ideally we would poll on both, the SPI fd and orb subscription. Unfortunately the
491499
//two pollings use different underlying mechanisms (at least under posix), which makes this

0 commit comments

Comments
 (0)