Browse Source

Sleep time computation algorithm adjustements

tags/v1.2.0
Bertrand Lemasle 7 years ago
parent
commit
eeee73206c
3 changed files with 31 additions and 26 deletions
  1. +20
    -17
      GpsTracker/Config.h
  2. +10
    -8
      GpsTracker/Core.cpp
  3. +1
    -1
      GpsTracker/NetworkPositionsConfig.h

+ 20
- 17
GpsTracker/Config.h View File

@@ -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 {


+ 10
- 8
GpsTracker/Core.cpp View File

@@ -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);


+ 1
- 1
GpsTracker/NetworkPositionsConfig.h View File

@@ -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


Loading…
Cancel
Save