From 2cb26dd5f5b0b7ed029ede0cd3b0d084589ed0bf Mon Sep 17 00:00:00 2001 From: alessandro <3762382+potaito@users.noreply.github.com> Date: Sat, 24 Aug 2019 01:12:20 +0200 Subject: [PATCH] GPS: Prevent injection from choking the driver (#12710) Sending a continuous stream of injection messages can cause the GPS driver to get stuck indefinitely in the handling loop. --- src/drivers/gps/gps.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/drivers/gps/gps.cpp b/src/drivers/gps/gps.cpp index 75dd3bad50..737a45e934 100644 --- a/src/drivers/gps/gps.cpp +++ b/src/drivers/gps/gps.cpp @@ -416,7 +416,15 @@ void GPS::handleInjectDataTopic() { bool updated = false; + // Limit maximum number of GPS injections to 6 since usually + // GPS injections should consist of 1-4 packets (GPS, Glonass, Baidu, Galileo). + // Looking at 6 packets thus guarantees, that at least a full injection + // data set is evaluated. + const size_t max_num_injections = 6; + size_t num_injections = 0; + do { + num_injections++; updated = _orb_inject_data_sub.updated(); if (updated) { @@ -431,7 +439,7 @@ void GPS::handleInjectDataTopic() ++_last_rate_rtcm_injection_count; } - } while (updated); + } while (updated && num_injections < max_num_injections); } bool GPS::injectData(uint8_t *data, size_t len)