diff --git a/blocks/soapy/include/gnuradio-4.0/soapy/Soapy.hpp b/blocks/soapy/include/gnuradio-4.0/soapy/Soapy.hpp index f87d856f..310b7c26 100644 --- a/blocks/soapy/include/gnuradio-4.0/soapy/Soapy.hpp +++ b/blocks/soapy/include/gnuradio-4.0/soapy/Soapy.hpp @@ -8,7 +8,7 @@ #include // needed for existing C++ return types that are ABI stable (i.e. header-only defined) -#include +#include #include #include #include @@ -17,6 +17,12 @@ namespace gr::blocks::soapy { +namespace detail { +bool equalWithinOnePercent(const std::vector& a, const std::vector& b) { + return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin(), [](double x, double y) { return std::abs(x - y) <= 0.01 * std::max(std::abs(x), std::abs(y)); }); +} +} // namespace detail + template struct SoapyBlock : public Block /*, BlockingIO*/> { using Description = Docat(i), static_cast(sample_rate)); } + + std::vector actualSampleRates; + for (std::size_t i = 0UZ; i < nChannels; i++) { + actualSampleRates.push_back(_device.getSampleRate(SOAPY_SDR_RX, rx_channels->at(i))); + } + + if (!detail::equalWithinOnePercent(actualSampleRates, std::vector(nChannels, static_cast(sample_rate)))) { + throw gr::exception(fmt::format("sample rate mismatch:\nSet: {} vs. Actual: {}\n", sample_rate, fmt::join(actualSampleRates, ", "))); + } } void setAntennae() { @@ -201,6 +213,14 @@ This block supports multiple output ports and was tested against the 'rtlsdr' an for (std::size_t i = 0UZ; i < nChannels; i++) { _device.setCenterFrequency(SOAPY_SDR_RX, rx_channels->at(i), rx_center_frequency->at(std::min(i, nFrequency - 1UZ))); } + std::vector rx_center_frequency_actual; + for (std::size_t i = 0UZ; i < nChannels; i++) { + rx_center_frequency_actual.push_back(_device.getCenterFrequency(SOAPY_SDR_RX, rx_channels->at(i))); + } + + if (!detail::equalWithinOnePercent(rx_center_frequency_actual, rx_center_frequency.value)) { + throw gr::exception(fmt::format("center frequency mismatch:\nSet: {} vs. Actual: {}\n", fmt::join(rx_center_frequency.value, ", "), fmt::join(rx_center_frequency_actual, ", "))); + } } void setBandwidth() {