From eeee73206c2b9644bbd9abb30baa5bb8bfccccc2 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Sun, 29 Apr 2018 20:22:08 +1200 Subject: [PATCH] Sleep time computation algorithm adjustements --- GpsTracker/Config.h | 37 ++++++++++++++++------------- GpsTracker/Core.cpp | 18 +++++++------- GpsTracker/NetworkPositionsConfig.h | 2 +- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/GpsTracker/Config.h b/GpsTracker/Config.h index 4a41270..bb0db05 100644 --- a/GpsTracker/Config.h +++ b/GpsTracker/Config.h @@ -16,6 +16,8 @@ #define CONFIG_SEED 13 #define VERSION "1.00" +#define SLEEP_TIMING_TIME(hours, minutes) hours * 60 + minutes + #pragma region Default configuration values #define MENU_TIMEOUT 10000 @@ -25,7 +27,12 @@ Exprimed in seconds */ #define SLEEP_DEFAULT_TIME_SECONDS 1800 -#define SLEEP_DEFAULT_INCREASE_THRESHOLD 3 +#define SLEEP_DEFAULT_STOPPED_THRESHOLD 5 +#define SLEEP_DEFAULT_PAUSING_TIME_SECONDS 270 + +#define SLEEP_TIMING_MIN SLEEP_TIMING_TIME(0, 0) +#define SLEEP_TIMING_MAX SLEEP_TIMING_TIME(23, 59) +#define SLEEP_TIMING_MIN_MOVING_VELOCITY 5 #define GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS 10000L #define GPS_DEFAULT_TOTAL_TIMEOUT_MS 80000L @@ -37,10 +44,6 @@ #pragma endregion -#define SLEEP_TIMING_TIME(hours, minutes) hours * 60 + minutes -#define SLEEP_TIMING_MIN SLEEP_TIMING_TIME(0, 0) -#define SLEEP_TIMING_MAX SLEEP_TIMING_TIME(23, 59) - struct sleepTimings_t { uint8_t speed; uint16_t timeMin; @@ -61,18 +64,18 @@ struct config_t { namespace config { static const sleepTimings_t defaultSleepTimings[] PROGMEM = { - { 3, SLEEP_TIMING_TIME(16, 00), SLEEP_TIMING_TIME(19, 59), 3600 }, - { 3, SLEEP_TIMING_TIME(20, 00), SLEEP_TIMING_MAX, SLEEP_DEFAULT_TIME_SECONDS }, - { 3, SLEEP_TIMING_MIN, SLEEP_TIMING_TIME(8, 29), SLEEP_DEFAULT_TIME_SECONDS }, - { 3, SLEEP_TIMING_TIME(8, 30), SLEEP_TIMING_TIME(15, 59), 10800 }, - - { 5, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 900 }, - { 20, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 600 }, - { 30, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 540 }, - { 50, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 480 }, - { 80, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 240 }, - { 100, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 210 }, - { 180, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 180 }, + { 0, SLEEP_TIMING_TIME(16, 00), SLEEP_TIMING_TIME(19, 59), 3600 }, + { 0, SLEEP_TIMING_TIME(20, 00), SLEEP_TIMING_MAX, SLEEP_DEFAULT_TIME_SECONDS }, + { 0, SLEEP_TIMING_MIN, SLEEP_TIMING_TIME(8, 29), SLEEP_DEFAULT_TIME_SECONDS }, + { 0, SLEEP_TIMING_TIME(8, 30), SLEEP_TIMING_TIME(15, 59), 10800 }, + + { SLEEP_TIMING_MIN_MOVING_VELOCITY, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 540 }, + { 10, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 270 }, + { 20, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 225 }, + { 30, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 240 }, + { 45, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 280 }, + { 65, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 276 }, + { 85, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 225 } }; namespace main { diff --git a/GpsTracker/Core.cpp b/GpsTracker/Core.cpp index 5d98ebf..14dde34 100644 --- a/GpsTracker/Core.cpp +++ b/GpsTracker/Core.cpp @@ -8,7 +8,7 @@ using namespace utils; namespace core { uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS;; - uint8_t increaseInARow = 0; + uint8_t stoppedInARow = 0; void main() { @@ -26,12 +26,13 @@ namespace core { void updateSleepTime(uint8_t velocity) { uint16_t result = computeSleepTime(velocity); - if (result > sleepTime) { - increaseInARow++; - if (increaseInARow < SLEEP_DEFAULT_INCREASE_THRESHOLD) return; - + if (velocity < SLEEP_TIMING_MIN_MOVING_VELOCITY) { + stoppedInARow++; + if (stoppedInARow < SLEEP_DEFAULT_STOPPED_THRESHOLD) { + result = SLEEP_DEFAULT_PAUSING_TIME_SECONDS; + } } - else increaseInARow = 0; + else stoppedInARow = 0; sleepTime = result; NOTICE_FORMAT("updateSleepTime", "%dkmh => %d seconds", velocity, sleepTime); @@ -48,15 +49,16 @@ namespace core { currentTime = SLEEP_TIMING_TIME(time.Hour, time.Minute); } - for (uint8_t i = 0; i < flash::getArraySize(config::defaultSleepTimings); i++) { + for (uint8_t i = flash::getArraySize(config::defaultSleepTimings); i--;) { sleepTimings_t timing; flash::read(&config::defaultSleepTimings[i], timing); - if (velocity > timing.speed) continue; + if (velocity < timing.speed) continue; if (currentTime != 0xFFFF && (currentTime < timing.timeMin || currentTime > timing.timeMax)) continue; result = timing.seconds; break; + } VERBOSE_FORMAT("computeSleepTime", "%d,%d", velocity, result); diff --git a/GpsTracker/NetworkPositionsConfig.h b/GpsTracker/NetworkPositionsConfig.h index 7e5f40d..6388fe0 100644 --- a/GpsTracker/NetworkPositionsConfig.h +++ b/GpsTracker/NetworkPositionsConfig.h @@ -1,7 +1,7 @@ #pragma once -#define POSITIONS_CONFIG_NET_DEFAULT_SAVE_THRESHOLD 10 +#define POSITIONS_CONFIG_NET_DEFAULT_SAVE_THRESHOLD 30 #define POSITIONS_CONFIG_NET_DEFAULT_APN "Vodafone" #define POSITIONS_CONFIG_NET_DEFAULT_URL "http://yourserver.com/endpoint" #define POSITIONS_CONFIG_NET_DEFAULT_EXPECTED_RESPONSE 201