From ada0f073173c31970642373d41c84ea1a07538b0 Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Tue, 10 Jun 2014 12:44:34 -0700 Subject: [PATCH] Refactored QGC::groundTime*() functions to be simpler. --- src/QGC.cc | 18 +++--------------- src/QGC.h | 10 ++++++++-- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/QGC.cc b/src/QGC.cc index 12dbcb6..3f1b6c2 100644 --- a/src/QGC.cc +++ b/src/QGC.cc @@ -30,29 +30,17 @@ namespace QGC quint64 groundTimeUsecs() { - QDateTime time = QDateTime::currentDateTime(); - time = time.toUTC(); - /* Return seconds and milliseconds, in milliseconds unit */ - quint64 microseconds = time.toTime_t() * static_cast(1000000); - return static_cast(microseconds + (time.time().msec()*1000)); + return groundTimeMilliseconds() * 1000; } quint64 groundTimeMilliseconds() { - QDateTime time = QDateTime::currentDateTime(); - time = time.toUTC(); - /* Return seconds and milliseconds, in milliseconds unit */ - quint64 seconds = time.toTime_t() * static_cast(1000); - return static_cast(seconds + (time.time().msec())); + return static_cast(QDateTime::currentMSecsSinceEpoch()); } qreal groundTimeSeconds() { - QDateTime time = QDateTime::currentDateTime(); - time = time.toUTC(); - /* Return time in seconds unit */ - quint64 seconds = time.toTime_t(); - return static_cast(seconds + (time.time().msec() / 1000.0)); + return static_cast(groundTimeMilliseconds()) / 1000.0f; } float limitAngleToPMPIf(float angle) diff --git a/src/QGC.h b/src/QGC.h index e49b2a4..c0a548a 100644 --- a/src/QGC.h +++ b/src/QGC.h @@ -75,11 +75,17 @@ const QColor colorDarkYellow(180, 180, 0); const QColor colorBackground("#050508"); const QColor colorBlack(0, 0, 0); -/** @brief Get the current ground time in microseconds */ +/** + * @brief Get the current ground time in microseconds. + * @note This does not have microsecond precision, it is limited to millisecond precision. + */ quint64 groundTimeUsecs(); /** @brief Get the current ground time in milliseconds */ quint64 groundTimeMilliseconds(); -/** @brief Get the current ground time in seconds */ +/** + * @brief Get the current ground time in fractional seconds + * @note Precision is limited to milliseconds. + */ qreal groundTimeSeconds(); /** @brief Returns the angle limited to -pi - pi */ float limitAngleToPMPIf(float angle);