Compare commits

..

2 Commits

Author SHA1 Message Date
Jorge Alejandro 318e527793
Merge 1d0cdb9f00 into b56fc99c2c 2023-09-17 18:13:55 -04:00
Jorge Alejandro 1d0cdb9f00 Add scan-interval-ms parameter
Allow user to specify the scan interval for searching for devices.
Scanning places every interface on the machine in promiscuous mode
and currently runs once a second.  This behaviour may have undesirable
side-effects and also pollutes the kernel log.

The new parameter --scan-interval-ms <interval> will allow the user
to specify the rate at which scanning occurs.  If equal to 0, then
only a single scan is performed.
2023-09-17 18:13:21 -04:00
1 changed files with 24 additions and 12 deletions

View File

@ -222,11 +222,11 @@ void usage(std::string executableName) {
std::cerr << "Copyright 2019-2023 Intrepid Control Systems, Inc.\n\n";
std::cerr << "Usage: " << executableName << " [option]\n\n";
std::cerr << "Options:\n";
std::cerr << "\t-d, --daemon\t\t\tRun as a daemon in the background\n";
std::cerr << "\t-h, -?, --help, --usage\t\t\tShow this help page\n";
std::cerr << "\t --devices\t\t\tList supported devices\n";
std::cerr << "\t --filter <serial>\t\tOnly connect to devices with serial\n\t\t\t\t\t\tnumbers starting with this filter\n";
std::cerr << "\t --scan-interval-ms <interval>\tDevice scan interval in ms\n\t\t\t\t\t\tIf 0, only a single scan is performed\n";
std::cerr << "\t-d, --daemon\t\t\tRun as a daemon in the background\n";
std::cerr << "\t-h, -?, --help, --usage\t\t\tShow this help page\n";
std::cerr << "\t --devices\t\t\tList supported devices\n";
std::cerr << "\t --filter <serial>\t\tOnly connect to devices with serial\n\t\t\t\t\t\tnumbers starting with this filter\n";
std::cerr << "\t --scan-interval-ms <interval>\tDevice scan interval in ms\n\t\t\t\t\t\tIf 0, only a single scan is performed\n";
}
void terminateSignal(int signal) {
@ -382,10 +382,10 @@ void searchForDevices() {
void deviceSearchThread() {
while(!stopRunning) {
searchForDevices();
if (scanIntervalMs == 0) {
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(scanIntervalMs));
if(scanIntervalMs == 0) {
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(scanIntervalMs));
}
}
@ -406,9 +406,21 @@ int main(int argc, char** argv) {
} else if(arg == "--filter" && i + 1 <= argc) {
serialFilter = argv[++i];
transform(serialFilter.begin(), serialFilter.end(), serialFilter.begin(), ::toupper);
} else if(arg == "--scan-interval-ms" && i + 1 <= argc) {
scanIntervalMs = std::atoi(argv[i + 1]);
i++;
} else if(arg == "--scan-interval-ms" && i + 1 <= argc) {
try {
scanIntervalMs = std::stoi(argv[++i]);
} catch (const std::invalid_argument& e) {
std::cerr << "Invalid input for scan-interval-ms\n";
return EX_USAGE;
} catch (const std::out_of_range& e) {
std::cerr << "Out of range input for scan-interval-ms\n";
return EX_USAGE;
}
if(scanIntervalMs < 0) {
std::cerr << "Invalid input for scan-interval-ms\n";
return EX_USAGE;
}
} else {
usage(argv[0]);
return EX_USAGE;