diff --git a/include/bci/abs/Discovery.h b/include/bci/abs/Discovery.h index 73d5bea..dafa514 100644 --- a/include/bci/abs/Discovery.h +++ b/include/bci/abs/Discovery.h @@ -27,7 +27,8 @@ using SerialDeviceList = std::vector; Result MulticastDiscovery(std::string_view interface_ip); Result SerialDiscovery(std::string_view port, - unsigned int max_devices); + std::uint8_t first_id, + std::uint8_t last_id); } // namespace bci::abs diff --git a/src/Discovery.cpp b/src/Discovery.cpp index 22c15fa..f332e50 100644 --- a/src/Discovery.cpp +++ b/src/Discovery.cpp @@ -50,11 +50,12 @@ Result MulticastDiscovery(std::string_view interface_ip) { } Result SerialDiscovery(std::string_view port, - unsigned int max_devices) { + std::uint8_t first_id, + std::uint8_t last_id) { SerialDeviceList devices; - if (max_devices == 0 || max_devices > 256) { - max_devices = 256; + if (last_id < first_id) { + return Err(ec::kInvalidArgument); } drivers::SerialDriver driver; @@ -64,15 +65,17 @@ Result SerialDiscovery(std::string_view port, return Err(ret); } - for (std::uint8_t id = 0; max_devices > 0; ++id, --max_devices) { - driver.SetDeviceID(id); + int total = last_id - first_id + 1; + + for (int i = 0; i < total; ++i) { + driver.SetDeviceID(first_id + i); ret = driver.Write("*IDN?\r\n", 100); if (auto resp = driver.ReadLine(50)) { std::array idn; if (scpi::SplitRespMnemonics(*resp, idn) != ErrorCode::kSuccess) { return Err(ErrorCode::kInvalidResponse); } - devices.emplace_back(id, std::string(idn[2])); + devices.emplace_back(first_id + i, std::string(idn[2])); } else { if (resp.error() != ec::kReadTimedOut) { return Err(resp.error());