From 3917eb2d002011af62decdf97a4a3eaae0986279 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Fri, 23 Feb 2018 15:07:58 +0100 Subject: [PATCH] mavlink: don't send wrong time This prevents the autopilot from sending an invalid unix timestamp. Usually, if no time is set yet by a GPS, the date is somehow set to 2000-01-01, therefore we can ignore anything earlier than 2001. --- src/modules/mavlink/mavlink_messages.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/mavlink/mavlink_messages.cpp b/src/modules/mavlink/mavlink_messages.cpp index 19a9613700..67def31e0e 100644 --- a/src/modules/mavlink/mavlink_messages.cpp +++ b/src/modules/mavlink/mavlink_messages.cpp @@ -1225,9 +1225,14 @@ protected: msg.time_boot_ms = hrt_absolute_time() / 1000; msg.time_unix_usec = (uint64_t)tv.tv_sec * 1000000 + tv.tv_nsec / 1000; - mavlink_msg_system_time_send_struct(_mavlink->get_channel(), &msg); + // If the time is before 2001-01-01, it's probably the default 2000 + // and we don't need to bother sending it because it's definitely wrong. + if (msg.time_unix_usec > 978307200000000) { + mavlink_msg_system_time_send_struct(_mavlink->get_channel(), &msg); + return true; + } - return true; + return false; } };