mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 02:36:37 +08:00
drivers/gps: prioritize non-blocking reads over injection (#25535)
This commit is contained in:
+11
-3
@@ -472,10 +472,16 @@ int GPS::pollOrRead(uint8_t *buf, size_t buf_length, int timeout)
|
|||||||
const int max_timeout = 50;
|
const int max_timeout = 50;
|
||||||
int timeout_adjusted = math::min(max_timeout, timeout);
|
int timeout_adjusted = math::min(max_timeout, timeout);
|
||||||
|
|
||||||
handleInjectDataTopic();
|
|
||||||
|
|
||||||
if (_interface == GPSHelper::Interface::UART) {
|
if (_interface == GPSHelper::Interface::UART) {
|
||||||
ret = _uart.readAtLeast(buf, buf_length, math::min(character_count, buf_length), timeout_adjusted);
|
|
||||||
|
const ssize_t read_at_least = math::min(character_count, buf_length);
|
||||||
|
|
||||||
|
// handle injection data before read if caught up
|
||||||
|
if (_uart.bytesAvailable() < read_at_least) {
|
||||||
|
handleInjectDataTopic();
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = _uart.readAtLeast(buf, buf_length, read_at_least, timeout_adjusted);
|
||||||
|
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
_num_bytes_read += ret;
|
_num_bytes_read += ret;
|
||||||
@@ -486,6 +492,8 @@ int GPS::pollOrRead(uint8_t *buf, size_t buf_length, int timeout)
|
|||||||
|
|
||||||
} else if ((_interface == GPSHelper::Interface::SPI) && (_spi_fd >= 0)) {
|
} else if ((_interface == GPSHelper::Interface::SPI) && (_spi_fd >= 0)) {
|
||||||
|
|
||||||
|
handleInjectDataTopic();
|
||||||
|
|
||||||
//Poll only for the SPI data. In the same thread we also need to handle orb messages,
|
//Poll only for the SPI data. In the same thread we also need to handle orb messages,
|
||||||
//so ideally we would poll on both, the SPI fd and orb subscription. Unfortunately the
|
//so ideally we would poll on both, the SPI fd and orb subscription. Unfortunately the
|
||||||
//two pollings use different underlying mechanisms (at least under posix), which makes this
|
//two pollings use different underlying mechanisms (at least under posix), which makes this
|
||||||
|
|||||||
Reference in New Issue
Block a user