From da186877c91d70a9fd3228c80ff11c1a492d641f Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Fri, 8 May 2020 10:27:57 -0400 Subject: [PATCH] gps: only use injected data if copy successful --- src/drivers/gps/gps.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/drivers/gps/gps.cpp b/src/drivers/gps/gps.cpp index 9ade4619f9..01b3944379 100644 --- a/src/drivers/gps/gps.cpp +++ b/src/drivers/gps/gps.cpp @@ -430,15 +430,17 @@ void GPS::handleInjectDataTopic() if (updated) { gps_inject_data_s msg; - _orb_inject_data_sub.copy(&msg); - /* Write the message to the gps device. Note that the message could be fragmented. - * But as we don't write anywhere else to the device during operation, we don't - * need to assemble the message first. - */ - injectData(msg.data, msg.len); + if (_orb_inject_data_sub.copy(&msg)) { - ++_last_rate_rtcm_injection_count; + /* Write the message to the gps device. Note that the message could be fragmented. + * But as we don't write anywhere else to the device during operation, we don't + * need to assemble the message first. + */ + injectData(msg.data, msg.len); + + ++_last_rate_rtcm_injection_count; + } } } while (updated && num_injections < max_num_injections); }