From 1faba76a8f0c531e948d1cd784901348d551e9fb Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Wed, 5 Sep 2012 16:31:36 +0200 Subject: [PATCH] Minor state machine fixes to reboot / timestamp detection --- src/uas/UAS.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 1ebc9127a..3c3861b0f 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -1535,6 +1535,7 @@ quint64 UAS::getUnixTimeFromMs(quint64 time) */ quint64 UAS::getUnixTime(quint64 time) { + bool isNull = (time == 0); // Check if the offset estimation likely went wrong // and we're talking to a new instance / the system // has rebooted. Only reset if this is consistent. @@ -1542,7 +1543,7 @@ quint64 UAS::getUnixTime(quint64 time) { onboardTimeOffsetInvalidCount++; } - else if (lastNonNullTime < time) + else if (time != 0 && lastNonNullTime < time) { onboardTimeOffsetInvalidCount = 0; } @@ -1554,7 +1555,6 @@ quint64 UAS::getUnixTime(quint64 time) onboardTimeOffsetInvalidCount = 0; } - quint64 ret = 0; if (attitudeStamped) { @@ -1599,6 +1599,11 @@ quint64 UAS::getUnixTime(quint64 time) // a Unix epoch timestamp. Do nothing. ret = time/1000; } + + if (!isNull) { + lastNonNullTime = time; + } + return ret; } -- 2.22.0