From a9e536f45bae3c283a1ad7ed13ff17bbda6173ba Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 1 Apr 2017 19:45:51 -0700 Subject: [PATCH 1/4] soapy - check for freq corr before invoking set_freq_corr() is often a NOP for devices. checking avoids crashes for some applications (ex GQRX) --- lib/soapy/soapy_sink_c.cc | 14 ++++++++++++-- lib/soapy/soapy_source_c.cc | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/soapy/soapy_sink_c.cc b/lib/soapy/soapy_sink_c.cc index 1af5a65..dbdfa7e 100644 --- a/lib/soapy/soapy_sink_c.cc +++ b/lib/soapy/soapy_sink_c.cc @@ -29,6 +29,7 @@ #endif #include +#include //find #include #include @@ -163,13 +164,22 @@ double soapy_sink_c::get_center_freq( size_t chan) double soapy_sink_c::set_freq_corr( double ppm, size_t chan) { - _device->setFrequency(SOAPY_SDR_TX, chan, "CORR", ppm); + std::vector components = _device->listFrequencies(SOAPY_SDR_TX, chan); + if (std::find(components.begin(), components.end(), "COOR") != components.end()) + { + _device->setFrequency(SOAPY_SDR_TX, chan, "CORR", ppm); + } return this->get_freq_corr(chan); } double soapy_sink_c::get_freq_corr( size_t chan) { - return _device->getFrequency(SOAPY_SDR_TX, chan, "CORR"); + std::vector components = _device->listFrequencies(SOAPY_SDR_TX, chan); + if (std::find(components.begin(), components.end(), "COOR") != components.end()) + { + return _device->getFrequency(SOAPY_SDR_TX, chan, "CORR"); + } + return 0.0; } std::vector soapy_sink_c::get_gain_names( size_t chan) diff --git a/lib/soapy/soapy_source_c.cc b/lib/soapy/soapy_source_c.cc index d066ed8..fe1e8d9 100644 --- a/lib/soapy/soapy_source_c.cc +++ b/lib/soapy/soapy_source_c.cc @@ -29,6 +29,7 @@ #endif #include +#include //find #include #include @@ -164,13 +165,22 @@ double soapy_source_c::get_center_freq( size_t chan ) double soapy_source_c::set_freq_corr( double ppm, size_t chan ) { - _device->setFrequency(SOAPY_SDR_RX, chan, "CORR", ppm); + std::vector components = _device->listFrequencies(SOAPY_SDR_RX, chan); + if (std::find(components.begin(), components.end(), "COOR") != components.end()) + { + _device->setFrequency(SOAPY_SDR_RX, chan, "CORR", ppm); + } return this->get_freq_corr(chan); } double soapy_source_c::get_freq_corr( size_t chan ) { - return _device->getFrequency(SOAPY_SDR_RX, chan, "CORR"); + std::vector components = _device->listFrequencies(SOAPY_SDR_RX, chan); + if (std::find(components.begin(), components.end(), "COOR") != components.end()) + { + return _device->getFrequency(SOAPY_SDR_RX, chan, "CORR"); + } + return 0.0; } std::vector soapy_source_c::get_gain_names( size_t chan ) From b361fa5a7768864901821567bba0f89a18646b9e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 14 Apr 2017 10:57:16 -0500 Subject: [PATCH 2/4] soapy: support newer getSampleRateRange() API call Switch to the newer API call which can provide a list of ranges. There are feature detection ifdefs provided by the library so that code will always correctly compile. --- lib/soapy/soapy_sink_c.cc | 7 +++++++ lib/soapy/soapy_source_c.cc | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/soapy/soapy_sink_c.cc b/lib/soapy/soapy_sink_c.cc index dbdfa7e..29defea 100644 --- a/lib/soapy/soapy_sink_c.cc +++ b/lib/soapy/soapy_sink_c.cc @@ -123,10 +123,17 @@ size_t soapy_sink_c::get_num_channels( void ) osmosdr::meta_range_t soapy_sink_c::get_sample_rates( void ) { osmosdr::meta_range_t result; + #ifdef SOAPY_SDR_API_HAS_GET_SAMPLE_RATE_RANGE + BOOST_FOREACH(const SoapySDR::Range &r, _device->getSampleRateRange(SOAPY_SDR_TX, 0)) + { + result.push_back(osmosdr::range_t(r.minimum(), r.maximum())); + } + #else BOOST_FOREACH(const double rate, _device->listSampleRates(SOAPY_SDR_TX, 0)) { result.push_back(osmosdr::range_t(rate)); } + #endif return result; } diff --git a/lib/soapy/soapy_source_c.cc b/lib/soapy/soapy_source_c.cc index fe1e8d9..a1a1885 100644 --- a/lib/soapy/soapy_source_c.cc +++ b/lib/soapy/soapy_source_c.cc @@ -124,10 +124,17 @@ size_t soapy_source_c::get_num_channels( void ) osmosdr::meta_range_t soapy_source_c::get_sample_rates( void ) { osmosdr::meta_range_t result; + #ifdef SOAPY_SDR_API_HAS_GET_SAMPLE_RATE_RANGE + BOOST_FOREACH(const SoapySDR::Range &r, _device->getSampleRateRange(SOAPY_SDR_RX, 0)) + { + result.push_back(osmosdr::range_t(r.minimum(), r.maximum())); + } + #else BOOST_FOREACH(const double rate, _device->listSampleRates(SOAPY_SDR_RX, 0)) { result.push_back(osmosdr::range_t(rate)); } + #endif return result; } From 117f64885904f743d1f04c5ddbbd39aab5a56e6d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 14 Apr 2017 11:02:00 -0500 Subject: [PATCH 3/4] soapy: support set/getFrequencyCorrection() API backwards compatible changes with #ifdef set/get_freq_corr() call directly into the SoapySDR equivalent when supported by the API version. --- lib/soapy/soapy_sink_c.cc | 8 ++++++++ lib/soapy/soapy_source_c.cc | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/soapy/soapy_sink_c.cc b/lib/soapy/soapy_sink_c.cc index 29defea..07cf069 100644 --- a/lib/soapy/soapy_sink_c.cc +++ b/lib/soapy/soapy_sink_c.cc @@ -171,22 +171,30 @@ double soapy_sink_c::get_center_freq( size_t chan) double soapy_sink_c::set_freq_corr( double ppm, size_t chan) { + #ifdef SOAPY_SDR_API_HAS_FREQUENCY_CORRECTION_API + _device->setFrequencyCorrection(SOAPY_SDR_TX, chan, ppm); + #else std::vector components = _device->listFrequencies(SOAPY_SDR_TX, chan); if (std::find(components.begin(), components.end(), "COOR") != components.end()) { _device->setFrequency(SOAPY_SDR_TX, chan, "CORR", ppm); } + #endif return this->get_freq_corr(chan); } double soapy_sink_c::get_freq_corr( size_t chan) { + #ifdef SOAPY_SDR_API_HAS_FREQUENCY_CORRECTION_API + return _device->getFrequencyCorrection(SOAPY_SDR_TX, chan); + #else std::vector components = _device->listFrequencies(SOAPY_SDR_TX, chan); if (std::find(components.begin(), components.end(), "COOR") != components.end()) { return _device->getFrequency(SOAPY_SDR_TX, chan, "CORR"); } return 0.0; + #endif } std::vector soapy_sink_c::get_gain_names( size_t chan) diff --git a/lib/soapy/soapy_source_c.cc b/lib/soapy/soapy_source_c.cc index a1a1885..c780966 100644 --- a/lib/soapy/soapy_source_c.cc +++ b/lib/soapy/soapy_source_c.cc @@ -172,22 +172,30 @@ double soapy_source_c::get_center_freq( size_t chan ) double soapy_source_c::set_freq_corr( double ppm, size_t chan ) { + #ifdef SOAPY_SDR_API_HAS_FREQUENCY_CORRECTION_API + _device->setFrequencyCorrection(SOAPY_SDR_RX, chan, ppm); + #else std::vector components = _device->listFrequencies(SOAPY_SDR_RX, chan); if (std::find(components.begin(), components.end(), "COOR") != components.end()) { _device->setFrequency(SOAPY_SDR_RX, chan, "CORR", ppm); } + #endif return this->get_freq_corr(chan); } double soapy_source_c::get_freq_corr( size_t chan ) { + #ifdef SOAPY_SDR_API_HAS_FREQUENCY_CORRECTION_API + return _device->getFrequencyCorrection(SOAPY_SDR_RX, chan); + #else std::vector components = _device->listFrequencies(SOAPY_SDR_RX, chan); if (std::find(components.begin(), components.end(), "COOR") != components.end()) { return _device->getFrequency(SOAPY_SDR_RX, chan, "CORR"); } return 0.0; + #endif } std::vector soapy_source_c::get_gain_names( size_t chan ) From cf9549485af61658eab3e14e0a89db80742eb547 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 21 Apr 2017 11:29:30 -0700 Subject: [PATCH 4/4] soapy - correct constant for frequency correction This is a typo, some modules use the "CORR" string in the setFrequency(dir, chan, name, value) API to perform fine frequency adjustments. Updated modules will use setFrequencyCorrection(), this is support for backwards compatible implementations. --- lib/soapy/soapy_sink_c.cc | 4 ++-- lib/soapy/soapy_source_c.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/soapy/soapy_sink_c.cc b/lib/soapy/soapy_sink_c.cc index 07cf069..b12b8da 100644 --- a/lib/soapy/soapy_sink_c.cc +++ b/lib/soapy/soapy_sink_c.cc @@ -175,7 +175,7 @@ double soapy_sink_c::set_freq_corr( double ppm, size_t chan) _device->setFrequencyCorrection(SOAPY_SDR_TX, chan, ppm); #else std::vector components = _device->listFrequencies(SOAPY_SDR_TX, chan); - if (std::find(components.begin(), components.end(), "COOR") != components.end()) + if (std::find(components.begin(), components.end(), "CORR") != components.end()) { _device->setFrequency(SOAPY_SDR_TX, chan, "CORR", ppm); } @@ -189,7 +189,7 @@ double soapy_sink_c::get_freq_corr( size_t chan) return _device->getFrequencyCorrection(SOAPY_SDR_TX, chan); #else std::vector components = _device->listFrequencies(SOAPY_SDR_TX, chan); - if (std::find(components.begin(), components.end(), "COOR") != components.end()) + if (std::find(components.begin(), components.end(), "CORR") != components.end()) { return _device->getFrequency(SOAPY_SDR_TX, chan, "CORR"); } diff --git a/lib/soapy/soapy_source_c.cc b/lib/soapy/soapy_source_c.cc index c780966..a645361 100644 --- a/lib/soapy/soapy_source_c.cc +++ b/lib/soapy/soapy_source_c.cc @@ -176,7 +176,7 @@ double soapy_source_c::set_freq_corr( double ppm, size_t chan ) _device->setFrequencyCorrection(SOAPY_SDR_RX, chan, ppm); #else std::vector components = _device->listFrequencies(SOAPY_SDR_RX, chan); - if (std::find(components.begin(), components.end(), "COOR") != components.end()) + if (std::find(components.begin(), components.end(), "CORR") != components.end()) { _device->setFrequency(SOAPY_SDR_RX, chan, "CORR", ppm); } @@ -190,7 +190,7 @@ double soapy_source_c::get_freq_corr( size_t chan ) return _device->getFrequencyCorrection(SOAPY_SDR_RX, chan); #else std::vector components = _device->listFrequencies(SOAPY_SDR_RX, chan); - if (std::find(components.begin(), components.end(), "COOR") != components.end()) + if (std::find(components.begin(), components.end(), "CORR") != components.end()) { return _device->getFrequency(SOAPY_SDR_RX, chan, "CORR"); }