From c2666f7cb2a1998f27a876b80bf159c897da2ec2 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 18 Sep 2022 13:39:39 +0200 Subject: [PATCH] repeat failed scans --- ChangeLog.md | 10 ++++++---- src/ebusd/bushandler.cpp | 8 +++++--- src/ebusd/bushandler.h | 3 ++- src/ebusd/mainloop.cpp | 10 +++++++++- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 9f5cfe90..adc64d90 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,12 +1,14 @@ # 22.4 (tbd) ## Bug Fixes -* fix some smaller glitches +* fix some smaller glitches (short argument names, compilation on small devices, argument help) * fix revision in gh build for update check +* fix for include instruction without subdirectory +* add timeout to network device connection ## Features -* add continuation of initial scan until it succeeded -* add restart of device state when connection was reset -* add KNX integration directly via KNXnet/IP multicast routing as well as via knxd client +* add continuation to initial scan until succeeded as well as repetition to incomplete regular scan +* add restart of enhanced device state when connection was reset +* add KNX integration via KNXnet/IP multicast routing and optionally via knxd client # 22.3 (2022-05-08) diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index 0e41d377..2a49366c 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -1677,7 +1677,7 @@ void BusHandler::formatGrabResult(bool unknown, OutputFormat outputFormat, ostri } } -symbol_t BusHandler::getNextScanAddress(symbol_t lastAddress) const { +symbol_t BusHandler::getNextScanAddress(symbol_t lastAddress, bool withUnfinished) const { if (lastAddress == SYN) { return SYN; } @@ -1685,14 +1685,16 @@ symbol_t BusHandler::getNextScanAddress(symbol_t lastAddress) const { if (!isValidAddress(lastAddress, false) || isMaster(lastAddress)) { continue; } - if ((m_seenAddresses[lastAddress]&(SEEN|LOAD_INIT)) == SEEN) { + if ((m_seenAddresses[lastAddress]&(SEEN|LOAD_INIT)) == SEEN + || (withUnfinished && (m_seenAddresses[lastAddress]&(SEEN|SCAN_INIT|LOAD_INIT)) == (SEEN|LOAD_INIT))) { return lastAddress; } symbol_t master = getMasterAddress(lastAddress); if (master == SYN || (m_seenAddresses[master]&SEEN) == 0) { continue; } - if ((m_seenAddresses[lastAddress]&LOAD_INIT) == 0) { + if ((m_seenAddresses[lastAddress]&LOAD_INIT) == 0 + || (withUnfinished && (m_seenAddresses[lastAddress]&(SCAN_INIT|LOAD_INIT)) == LOAD_INIT)) { return lastAddress; } } diff --git a/src/ebusd/bushandler.h b/src/ebusd/bushandler.h index 1fe5d20a..58441d9c 100755 --- a/src/ebusd/bushandler.h +++ b/src/ebusd/bushandler.h @@ -603,9 +603,10 @@ class BusHandler : public WaitThread { /** * Get the next slave address that still needs to be scanned or loaded. * @param lastAddress the last returned slave address, or 0 for returning the first one. + * @param withUnfinished whether to include slave addresses that were not scanned yet. * @return the next slave address that still needs to be scanned or loaded, or @a SYN. */ - symbol_t getNextScanAddress(symbol_t lastAddress) const; + symbol_t getNextScanAddress(symbol_t lastAddress, bool withUnfinished) const; /** * Set the state of the participant to configuration @a LOADED. diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index ea43e289..970f21b9 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -213,12 +213,16 @@ MainLoop::~MainLoop() { /** the initial delay for running the update check. */ #define CHECK_INITIAL_DELAY (2*60) +/** the number of completed scan runs after which to try again failed ones. */ +#define SCAN_REPEAT_COUNT 6 + void MainLoop::run() { bool reload = true; time_t lastTaskRun, now, start, lastSignal = 0, since, sinkSince = 1, nextCheckRun; int taskDelay = 5; symbol_t lastScanAddress = 0; // 0 is known to be a master scanStatus_t lastScanStatus = SCAN_STATUS_NONE; + int scanCompleted = 0; time(&now); start = now; lastTaskRun = now; @@ -296,11 +300,15 @@ void MainLoop::run() { } } if (!loadDelay) { - lastScanAddress = m_busHandler->getNextScanAddress(lastScanAddress); + lastScanAddress = m_busHandler->getNextScanAddress(lastScanAddress, scanCompleted >= SCAN_REPEAT_COUNT); if (lastScanAddress == SYN) { taskDelay = 5; lastScanAddress = 0; scanStatus = SCAN_STATUS_FINISHED; + scanCompleted++; + if (scanCompleted > SCAN_REPEAT_COUNT) { // repeat failed scan only every Nth time + scanCompleted = 0; + } } else { scanStatus = SCAN_STATUS_RUNNING; nextCheckRun = now + CHECK_INITIAL_DELAY;