From 85995b5bf16157e9e61d044366c7924db16a1fe9 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Wed, 27 Mar 2024 17:01:24 +1300 Subject: [PATCH] gps: fix Septentrino serial read For Septententrino we seem to sometimes fill the buffer pretty full. If we ask for too much, readAtLeast will fail completely and make the GPS discovery logic fall over. Therefore, let's not ask for too much and just read what we can given the available buffer. Signed-off-by: Julian Oes --- src/drivers/gps/gps.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/drivers/gps/gps.cpp b/src/drivers/gps/gps.cpp index 766be323d719..1c9a7b49f48c 100644 --- a/src/drivers/gps/gps.cpp +++ b/src/drivers/gps/gps.cpp @@ -471,14 +471,14 @@ int GPS::callback(GPSCallbackType type, void *data1, int data2, void *user) int GPS::pollOrRead(uint8_t *buf, size_t buf_length, int timeout) { int ret = 0; - const unsigned character_count = 32; // minimum bytes that we want to read + const size_t character_count = 32; // minimum bytes that we want to read const int max_timeout = 50; int timeout_adjusted = math::min(max_timeout, timeout); handleInjectDataTopic(); if ((_interface == GPSHelper::Interface::UART) && (_uart)) { - ret = _uart->readAtLeast(buf, buf_length, character_count, timeout_adjusted); + ret = _uart->readAtLeast(buf, buf_length, math::min(character_count, buf_length), timeout_adjusted); // SPI is only supported on LInux #if defined(__PX4_LINUX) @@ -1566,4 +1566,4 @@ int gps_main(int argc, char *argv[]) { return GPS::main(argc, argv); -} +} \ No newline at end of file