From be13de79a4f30fd0722c7c1eefb05f0ad9ad46d8 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 13 Oct 2016 20:39:06 +1100 Subject: [PATCH] AP_Stats: a periodic update function, flttime and runtime --- libraries/AP_Stats/AP_Stats.cpp | 13 +++++++++++++ libraries/AP_Stats/AP_Stats.h | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/libraries/AP_Stats/AP_Stats.cpp b/libraries/AP_Stats/AP_Stats.cpp index a1630cf3e1..ed22f693e7 100644 --- a/libraries/AP_Stats/AP_Stats.cpp +++ b/libraries/AP_Stats/AP_Stats.cpp @@ -16,3 +16,16 @@ void AP_Stats::init() { params.bootcount.set_and_save(params.bootcount+1); } + +void AP_Stats::flush() +{ +} + +void AP_Stats::update() +{ + const uint32_t now_ms = AP_HAL::millis(); + if (now_ms - last_flush_ms > flush_interval_ms) { + flush(); + last_flush_ms = now_ms; + } +} diff --git a/libraries/AP_Stats/AP_Stats.h b/libraries/AP_Stats/AP_Stats.h index e4ec5f8ada..d9459e6ddb 100644 --- a/libraries/AP_Stats/AP_Stats.h +++ b/libraries/AP_Stats/AP_Stats.h @@ -12,6 +12,13 @@ public: void init(); + // copy state into underlying parameters: + void flush(); + + // periodic update function (e.g. put our values to permanent storage): + // call at least 1Hz + void update(); + static const struct AP_Param::GroupInfo var_info[]; private: @@ -20,4 +27,6 @@ private: AP_Int16 bootcount; } params; + uint64_t last_flush_ms; // in terms of system uptime + const uint16_t flush_interval_ms = 30000; };