diff --git a/src/QGC.cc b/src/QGC.cc index 2ea7fdc4fbf4d1e2ea477f982b56c9630a643280..df7f3e6950df976617e9728d2f1f689046faa40a 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 0b8b07541b89b7ec3d6698e63e11172a13be2923..bcfb5ffedfd7bb8b5fd886e15281a0f07f114950 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 324da7fdce90ca4cab0e7939cad3366d00168ad9..8291eaf4331750765dae41824b316e6145c286f7 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"))