From 0f66f2f2dc997062897b383cf48c9046285b7327 Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Thu, 2 Jan 2020 13:14:31 -0500 Subject: [PATCH] Add time since boot --- src/QGC.cc | 12 ++++++++++++ src/QGC.h | 5 +++++ src/main.cc | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/src/QGC.cc b/src/QGC.cc index 2ea7fdc..df7f3e6 100644 --- a/src/QGC.cc +++ b/src/QGC.cc @@ -15,6 +15,18 @@ namespace QGC { +static quint64 gBootTime = 0; + +void initTimer() +{ + gBootTime = groundTimeMilliseconds(); +} + +quint64 bootTimeMilliseconds() +{ + return groundTimeMilliseconds() - gBootTime; +} + quint64 groundTimeUsecs() { return groundTimeMilliseconds() * 1000; diff --git a/src/QGC.h b/src/QGC.h index 0b8b075..bcfb5ff 100644 --- a/src/QGC.h +++ b/src/QGC.h @@ -37,6 +37,11 @@ float limitAngleToPMPIf(double angle); /** @brief Returns the angle limited to -pi - pi */ double limitAngleToPMPId(double angle); +/** @brief Records boot time (called from main) */ +void initTimer(); +/** @brief Get the ground time since boot in milliseconds */ +quint64 bootTimeMilliseconds(); + const static int MAX_FLIGHT_TIME = 60 * 60 * 24 * 21; class SLEEP : public QThread diff --git a/src/main.cc b/src/main.cc index 324da7f..8291eaf 100644 --- a/src/main.cc +++ b/src/main.cc @@ -15,6 +15,7 @@ * */ +#include "QGC.h" #include #include #include @@ -238,6 +239,9 @@ int main(int argc, char *argv[]) } #endif + //-- Record boot time + QGC::initTimer(); + #ifdef Q_OS_UNIX //Force writing to the console on UNIX/BSD devices if (!qEnvironmentVariableIsSet("QT_LOGGING_TO_CONSOLE"))