From aa12879356acd5e8db597dfc0609a8cce7dc5397 Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 27 Nov 2020 14:43:45 +0100 Subject: [PATCH] Fix wraparound bug in backlog --- tasmota/support_command.ino | 10 +++++----- tasmota/support_wifi.ino | 2 +- tasmota/tasmota.ino | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index cbeab8d0f259..a69cd6e1ec1e 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -244,8 +244,8 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) DEBUG_CORE_LOG(PSTR("CMD: Payload %d"), payload); -// TasmotaGlobal.backlog_delay = millis() + (100 * MIN_BACKLOG_DELAY); - TasmotaGlobal.backlog_delay = millis() + Settings.param[P_BACKLOG_DELAY]; +// TasmotaGlobal.backlog_timer = millis() + (100 * MIN_BACKLOG_DELAY); + TasmotaGlobal.backlog_timer = millis() + Settings.param[P_BACKLOG_DELAY]; char command[CMDSZ] = { 0 }; XdrvMailbox.command = command; @@ -344,7 +344,7 @@ void CmndBacklog(void) } // ResponseCmndChar(D_JSON_APPENDED); ResponseClear(); - TasmotaGlobal.backlog_delay = 0; + TasmotaGlobal.backlog_timer = millis(); } else { bool blflag = BACKLOG_EMPTY; #ifdef SUPPORT_IF_STATEMENT @@ -359,10 +359,10 @@ void CmndBacklog(void) void CmndDelay(void) { if ((XdrvMailbox.payload >= (MIN_BACKLOG_DELAY / 100)) && (XdrvMailbox.payload <= 3600)) { - TasmotaGlobal.backlog_delay = millis() + (100 * XdrvMailbox.payload); + TasmotaGlobal.backlog_timer = millis() + (100 * XdrvMailbox.payload); } uint32_t bl_delay = 0; - long bl_delta = TimePassedSince(TasmotaGlobal.backlog_delay); + long bl_delta = TimePassedSince(TasmotaGlobal.backlog_timer); if (bl_delta < 0) { bl_delay = (bl_delta *-1) / 100; } ResponseCmndNumber(bl_delay); } diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index f25e710e7801..ecc256d5cbbb 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -687,7 +687,7 @@ void stationKeepAliveNow(void) { } void wifiKeepAlive(void) { - static uint32_t wifi_timer = 0; // Wifi keepalive timer + static uint32_t wifi_timer = millis(); // Wifi keepalive timer uint32_t wifiTimerSec = Settings.param[P_ARP_GRATUITOUS]; // 8-bits number of seconds, or minutes if > 100 diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 3034013a383e..38dafb87e97e 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -84,7 +84,7 @@ struct { uint32_t baudrate; // Current Serial baudrate uint32_t pulse_timer[MAX_PULSETIMERS]; // Power off timer uint32_t blink_timer; // Power cycle timer - uint32_t backlog_delay; // Command backlog delay + uint32_t backlog_timer; // Timer for next command in backlog uint32_t loop_load_avg; // Indicative loop load average uint32_t web_log_index; // Index in Web log buffer uint32_t uptime; // Counting every second until 4294967295 = 130 year @@ -319,7 +319,7 @@ void setup(void) { } void BacklogLoop(void) { - if (TimeReached(TasmotaGlobal.backlog_delay)) { + if (TimeReached(TasmotaGlobal.backlog_timer)) { if (!BACKLOG_EMPTY && !TasmotaGlobal.backlog_mutex) { TasmotaGlobal.backlog_mutex = true; bool nodelay = false; @@ -341,7 +341,7 @@ void BacklogLoop(void) { ExecuteCommand((char*)cmd.c_str(), SRC_BACKLOG); } if (nodelay) { - TasmotaGlobal.backlog_delay = 0; // Reset backlog_delay which has been set by ExecuteCommand (CommandHandler) + TasmotaGlobal.backlog_timer = millis(); // Reset backlog_timer which has been set by ExecuteCommand (CommandHandler) } TasmotaGlobal.backlog_mutex = false; }