allow limiting number of scan retries (fixes 1013)
This commit is contained in:
+12
-1
@@ -92,6 +92,7 @@ static struct options s_opt = {
|
|||||||
|
|
||||||
false, // scanConfig
|
false, // scanConfig
|
||||||
0, // initialScan
|
0, // initialScan
|
||||||
|
5, // scanRetries
|
||||||
getenv("LANG"), // preferLanguage
|
getenv("LANG"), // preferLanguage
|
||||||
false, // checkConfig
|
false, // checkConfig
|
||||||
OF_NONE, // dumpConfig
|
OF_NONE, // dumpConfig
|
||||||
@@ -165,7 +166,8 @@ static const char argpdoc[] =
|
|||||||
|
|
||||||
#define O_INISND -2
|
#define O_INISND -2
|
||||||
#define O_DEVLAT (O_INISND-1)
|
#define O_DEVLAT (O_INISND-1)
|
||||||
#define O_CFGLNG (O_DEVLAT-1)
|
#define O_SCNRET (O_DEVLAT-1)
|
||||||
|
#define O_CFGLNG (O_SCNRET-1)
|
||||||
#define O_CHKCFG (O_CFGLNG-1)
|
#define O_CHKCFG (O_CFGLNG-1)
|
||||||
#define O_DMPCFG (O_CHKCFG-1)
|
#define O_DMPCFG (O_CHKCFG-1)
|
||||||
#define O_DMPCTO (O_DMPCFG-1)
|
#define O_DMPCTO (O_DMPCFG-1)
|
||||||
@@ -223,6 +225,7 @@ static const struct argp_option argpoptions[] = {
|
|||||||
"\"off\" for not picking CSV files by scan result (default when configpath is given).\n"
|
"\"off\" for not picking CSV files by scan result (default when configpath is given).\n"
|
||||||
"If combined with --checkconfig, you can add scan message data as "
|
"If combined with --checkconfig, you can add scan message data as "
|
||||||
"arguments for checking a particular scan configuration, e.g. \"FF08070400/0AB5454850303003277201\".", 0 },
|
"arguments for checking a particular scan configuration, e.g. \"FF08070400/0AB5454850303003277201\".", 0 },
|
||||||
|
{"scanretries", O_SCNRET, "COUNT", 0, "Retry scanning devices COUNT times [5]", 0 },
|
||||||
{"configlang", O_CFGLNG, "LANG", 0,
|
{"configlang", O_CFGLNG, "LANG", 0,
|
||||||
"Prefer LANG in multilingual configuration files [system default language]", 0 },
|
"Prefer LANG in multilingual configuration files [system default language]", 0 },
|
||||||
{"checkconfig", O_CHKCFG, nullptr, 0, "Check config files, then stop", 0 },
|
{"checkconfig", O_CHKCFG, nullptr, 0, "Check config files, then stop", 0 },
|
||||||
@@ -361,6 +364,14 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||||||
s_scanConfigOrPathSet = true;
|
s_scanConfigOrPathSet = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case O_SCNRET: // --scanretries=10
|
||||||
|
value = parseInt(arg, 10, 0, 100, &result);
|
||||||
|
if (result != RESULT_OK) {
|
||||||
|
argp_error(state, "invalid scanretries");
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
opt->scanRetries = value;
|
||||||
|
break;
|
||||||
case O_CFGLNG: // --configlang=LANG
|
case O_CFGLNG: // --configlang=LANG
|
||||||
opt->preferLanguage = arg;
|
opt->preferLanguage = arg;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ typedef struct options {
|
|||||||
* else: single slave address.
|
* else: single slave address.
|
||||||
*/
|
*/
|
||||||
symbol_t initialScan;
|
symbol_t initialScan;
|
||||||
|
int scanRetries; //!< number of retries for scanning devices [10]
|
||||||
const char* preferLanguage; //!< preferred language in configuration files
|
const char* preferLanguage; //!< preferred language in configuration files
|
||||||
bool checkConfig; //!< check config files, then stop
|
bool checkConfig; //!< check config files, then stop
|
||||||
OutputFormat dumpConfig; //!< dump config files, then stop
|
OutputFormat dumpConfig; //!< dump config files, then stop
|
||||||
|
|||||||
+10
-3
@@ -109,8 +109,8 @@ MainLoop::MainLoop(const struct options& opt, Device *device, MessageMap* messag
|
|||||||
Queue<Request*>* requestQueue)
|
Queue<Request*>* requestQueue)
|
||||||
: Thread(), m_device(device), m_reconnectCount(0), m_userList(opt.accessLevel), m_messages(messages),
|
: Thread(), m_device(device), m_reconnectCount(0), m_userList(opt.accessLevel), m_messages(messages),
|
||||||
m_scanHelper(scanHelper), m_address(opt.address), m_scanConfig(opt.scanConfig),
|
m_scanHelper(scanHelper), m_address(opt.address), m_scanConfig(opt.scanConfig),
|
||||||
m_initialScan(opt.readOnly ? ESC : opt.initialScan), m_scanStatus(SCAN_STATUS_NONE),
|
m_initialScan(opt.readOnly ? ESC : opt.initialScan), m_scanRetries(opt.scanRetries),
|
||||||
m_polling(opt.pollInterval > 0), m_enableHex(opt.enableHex),
|
m_scanStatus(SCAN_STATUS_NONE), m_polling(opt.pollInterval > 0), m_enableHex(opt.enableHex),
|
||||||
m_shutdown(false), m_runUpdateCheck(opt.updateCheck), m_httpClient(), m_requestQueue(requestQueue) {
|
m_shutdown(false), m_runUpdateCheck(opt.updateCheck), m_httpClient(), m_requestQueue(requestQueue) {
|
||||||
m_device->setListener(this);
|
m_device->setListener(this);
|
||||||
// open Device
|
// open Device
|
||||||
@@ -228,6 +228,7 @@ void MainLoop::run() {
|
|||||||
symbol_t lastScanAddress = 0; // 0 is known to be a master
|
symbol_t lastScanAddress = 0; // 0 is known to be a master
|
||||||
scanStatus_t lastScanStatus = m_scanStatus;
|
scanStatus_t lastScanStatus = m_scanStatus;
|
||||||
int scanCompleted = 0;
|
int scanCompleted = 0;
|
||||||
|
int scanRetry = 0;
|
||||||
time(&now);
|
time(&now);
|
||||||
start = now;
|
start = now;
|
||||||
lastTaskRun = now;
|
lastTaskRun = now;
|
||||||
@@ -261,7 +262,7 @@ void MainLoop::run() {
|
|||||||
m_busHandler->reconnect();
|
m_busHandler->reconnect();
|
||||||
m_reconnectCount++;
|
m_reconnectCount++;
|
||||||
}
|
}
|
||||||
if (m_scanConfig) {
|
if (m_scanConfig && scanRetry <= m_scanRetries) {
|
||||||
bool loadDelay = false;
|
bool loadDelay = false;
|
||||||
if (m_initialScan != ESC && reload && m_busHandler->hasSignal()) {
|
if (m_initialScan != ESC && reload && m_busHandler->hasSignal()) {
|
||||||
loadDelay = true;
|
loadDelay = true;
|
||||||
@@ -312,6 +313,8 @@ void MainLoop::run() {
|
|||||||
scanCompleted++;
|
scanCompleted++;
|
||||||
if (scanCompleted > SCAN_REPEAT_COUNT) { // repeat failed scan only every Nth time
|
if (scanCompleted > SCAN_REPEAT_COUNT) { // repeat failed scan only every Nth time
|
||||||
scanCompleted = 0;
|
scanCompleted = 0;
|
||||||
|
scanRetry++;
|
||||||
|
logNotice(lf_main, "scan completed %d time(s), %s", scanRetry, scanRetry <= m_scanRetries ? "check again" : "end");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m_scanStatus = SCAN_STATUS_RUNNING;
|
m_scanStatus = SCAN_STATUS_RUNNING;
|
||||||
@@ -424,7 +427,11 @@ void MainLoop::run() {
|
|||||||
bool connected = true;
|
bool connected = true;
|
||||||
if (!req->empty()) {
|
if (!req->empty()) {
|
||||||
req->log();
|
req->log();
|
||||||
|
bool currentReload = reload;
|
||||||
result_t result = decodeRequest(req, &connected, &reqMode, &user, &reload, &ostream);
|
result_t result = decodeRequest(req, &connected, &reqMode, &user, &reload, &ostream);
|
||||||
|
if (reload && !currentReload) {
|
||||||
|
scanRetry = 0; // restart scan counting
|
||||||
|
}
|
||||||
if (!req->isHttp() && (ostream.tellp() == 0 || result != RESULT_OK)) {
|
if (!req->isHttp() && (ostream.tellp() == 0 || result != RESULT_OK)) {
|
||||||
if (reqMode.listenMode != lm_direct) {
|
if (reqMode.listenMode != lm_direct) {
|
||||||
ostream.str("");
|
ostream.str("");
|
||||||
|
|||||||
@@ -416,6 +416,9 @@ class MainLoop : public Thread, DeviceListener {
|
|||||||
* (@a ESC=none, 0xfe=broadcast ident, @a SYN=full scan, else: single slave address). */
|
* (@a ESC=none, 0xfe=broadcast ident, @a SYN=full scan, else: single slave address). */
|
||||||
const symbol_t m_initialScan;
|
const symbol_t m_initialScan;
|
||||||
|
|
||||||
|
/** number of retries for scanning a device. */
|
||||||
|
const int m_scanRetries;
|
||||||
|
|
||||||
/** the current scan status. */
|
/** the current scan status. */
|
||||||
scanStatus_t m_scanStatus;
|
scanStatus_t m_scanStatus;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user