Commit ada0f073 authored by Bryant Mairs's avatar Bryant Mairs

Refactored QGC::groundTime*() functions to be simpler.

parent 8714e12a
...@@ -30,29 +30,17 @@ namespace QGC ...@@ -30,29 +30,17 @@ namespace QGC
quint64 groundTimeUsecs() quint64 groundTimeUsecs()
{ {
QDateTime time = QDateTime::currentDateTime(); return groundTimeMilliseconds() * 1000;
time = time.toUTC();
/* Return seconds and milliseconds, in milliseconds unit */
quint64 microseconds = time.toTime_t() * static_cast<quint64>(1000000);
return static_cast<quint64>(microseconds + (time.time().msec()*1000));
} }
quint64 groundTimeMilliseconds() quint64 groundTimeMilliseconds()
{ {
QDateTime time = QDateTime::currentDateTime(); return static_cast<quint64>(QDateTime::currentMSecsSinceEpoch());
time = time.toUTC();
/* Return seconds and milliseconds, in milliseconds unit */
quint64 seconds = time.toTime_t() * static_cast<quint64>(1000);
return static_cast<quint64>(seconds + (time.time().msec()));
} }
qreal groundTimeSeconds() qreal groundTimeSeconds()
{ {
QDateTime time = QDateTime::currentDateTime(); return static_cast<qreal>(groundTimeMilliseconds()) / 1000.0f;
time = time.toUTC();
/* Return time in seconds unit */
quint64 seconds = time.toTime_t();
return static_cast<qreal>(seconds + (time.time().msec() / 1000.0));
} }
float limitAngleToPMPIf(float angle) float limitAngleToPMPIf(float angle)
......
...@@ -75,11 +75,17 @@ const QColor colorDarkYellow(180, 180, 0); ...@@ -75,11 +75,17 @@ const QColor colorDarkYellow(180, 180, 0);
const QColor colorBackground("#050508"); const QColor colorBackground("#050508");
const QColor colorBlack(0, 0, 0); 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(); quint64 groundTimeUsecs();
/** @brief Get the current ground time in milliseconds */ /** @brief Get the current ground time in milliseconds */
quint64 groundTimeMilliseconds(); 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(); qreal groundTimeSeconds();
/** @brief Returns the angle limited to -pi - pi */ /** @brief Returns the angle limited to -pi - pi */
float limitAngleToPMPIf(float angle); float limitAngleToPMPIf(float angle);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment