@@ -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