Skip to content

Commit

Permalink
mavlink: don't send wrong time
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
julianoes committed Feb 23, 2018
1 parent df7364d commit 3917eb2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/modules/mavlink/mavlink_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,9 +1225,14 @@ class MavlinkStreamSystemTime : public MavlinkStream
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;
}
};

Expand Down

0 comments on commit 3917eb2

Please sign in to comment.