From b54c44bd377ecd2ef9620406b53e93791234d890 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Thu, 28 May 2020 14:05:45 +0200 Subject: [PATCH] mavlink: don't send streams with interval 0 We only need to send them immediately if the interval is < 0 meaning unlimited. --- src/modules/mavlink/mavlink_stream.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/modules/mavlink/mavlink_stream.cpp b/src/modules/mavlink/mavlink_stream.cpp index af7c9fb3fd..ac1b5a822a 100644 --- a/src/modules/mavlink/mavlink_stream.cpp +++ b/src/modules/mavlink/mavlink_stream.cpp @@ -82,12 +82,19 @@ MavlinkStream::update(const hrt_abstime &t) } int64_t dt = t - _last_sent; - int interval = (_interval > 0) ? _interval : 0; + int interval = _interval; if (!const_rate()) { interval /= _mavlink->get_rate_mult(); } + // We don't need to send anything if the inverval is 0. send() will be called manually. + if (interval == 0) { + return 0; + } + + const bool unlimited_rate = interval < 0; + // Send the message if it is due or // if it will overrun the next scheduled send interval // by 30% of the interval time. This helps to avoid @@ -98,7 +105,7 @@ MavlinkStream::update(const hrt_abstime &t) // This method is not theoretically optimal but a suitable // stopgap as it hits its deadlines well (0.5 Hz, 50 Hz and 250 Hz) - if (interval == 0 || (dt > (interval - (_mavlink->get_main_loop_delay() / 10) * 3))) { + if (unlimited_rate || (dt > (interval - (_mavlink->get_main_loop_delay() / 10) * 3))) { // interval expired, send message // If the interval is non-zero and dt is smaller than 1.5 times the interval