Merge branch 'master' of git.osmocom.org:gr-osmosdr

This commit is contained in:
Dimitri Stolnikov 2017-06-12 00:04:36 +02:00
commit c653754dde
2 changed files with 54 additions and 4 deletions

View File

@ -29,6 +29,7 @@
#endif #endif
#include <iostream> #include <iostream>
#include <algorithm> //find
#include <boost/assign.hpp> #include <boost/assign.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
@ -122,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 soapy_sink_c::get_sample_rates( void )
{ {
osmosdr::meta_range_t result; 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)) BOOST_FOREACH(const double rate, _device->listSampleRates(SOAPY_SDR_TX, 0))
{ {
result.push_back(osmosdr::range_t(rate)); result.push_back(osmosdr::range_t(rate));
} }
#endif
return result; return result;
} }
@ -163,13 +171,30 @@ double soapy_sink_c::get_center_freq( size_t chan)
double soapy_sink_c::set_freq_corr( double ppm, size_t chan) double soapy_sink_c::set_freq_corr( double ppm, size_t chan)
{ {
_device->setFrequency(SOAPY_SDR_TX, chan, "CORR", ppm); #ifdef SOAPY_SDR_API_HAS_FREQUENCY_CORRECTION_API
_device->setFrequencyCorrection(SOAPY_SDR_TX, chan, ppm);
#else
std::vector<std::string> components = _device->listFrequencies(SOAPY_SDR_TX, chan);
if (std::find(components.begin(), components.end(), "CORR") != components.end())
{
_device->setFrequency(SOAPY_SDR_TX, chan, "CORR", ppm);
}
#endif
return this->get_freq_corr(chan); return this->get_freq_corr(chan);
} }
double soapy_sink_c::get_freq_corr( size_t chan) double soapy_sink_c::get_freq_corr( size_t chan)
{ {
return _device->getFrequency(SOAPY_SDR_TX, chan, "CORR"); #ifdef SOAPY_SDR_API_HAS_FREQUENCY_CORRECTION_API
return _device->getFrequencyCorrection(SOAPY_SDR_TX, chan);
#else
std::vector<std::string> components = _device->listFrequencies(SOAPY_SDR_TX, chan);
if (std::find(components.begin(), components.end(), "CORR") != components.end())
{
return _device->getFrequency(SOAPY_SDR_TX, chan, "CORR");
}
return 0.0;
#endif
} }
std::vector<std::string> soapy_sink_c::get_gain_names( size_t chan) std::vector<std::string> soapy_sink_c::get_gain_names( size_t chan)

View File

@ -29,6 +29,7 @@
#endif #endif
#include <iostream> #include <iostream>
#include <algorithm> //find
#include <boost/assign.hpp> #include <boost/assign.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
@ -123,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 soapy_source_c::get_sample_rates( void )
{ {
osmosdr::meta_range_t result; 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)) BOOST_FOREACH(const double rate, _device->listSampleRates(SOAPY_SDR_RX, 0))
{ {
result.push_back(osmosdr::range_t(rate)); result.push_back(osmosdr::range_t(rate));
} }
#endif
return result; return result;
} }
@ -164,13 +172,30 @@ double soapy_source_c::get_center_freq( size_t chan )
double soapy_source_c::set_freq_corr( double ppm, size_t chan ) double soapy_source_c::set_freq_corr( double ppm, size_t chan )
{ {
_device->setFrequency(SOAPY_SDR_RX, chan, "CORR", ppm); #ifdef SOAPY_SDR_API_HAS_FREQUENCY_CORRECTION_API
_device->setFrequencyCorrection(SOAPY_SDR_RX, chan, ppm);
#else
std::vector<std::string> components = _device->listFrequencies(SOAPY_SDR_RX, chan);
if (std::find(components.begin(), components.end(), "CORR") != components.end())
{
_device->setFrequency(SOAPY_SDR_RX, chan, "CORR", ppm);
}
#endif
return this->get_freq_corr(chan); return this->get_freq_corr(chan);
} }
double soapy_source_c::get_freq_corr( size_t chan ) double soapy_source_c::get_freq_corr( size_t chan )
{ {
return _device->getFrequency(SOAPY_SDR_RX, chan, "CORR"); #ifdef SOAPY_SDR_API_HAS_FREQUENCY_CORRECTION_API
return _device->getFrequencyCorrection(SOAPY_SDR_RX, chan);
#else
std::vector<std::string> components = _device->listFrequencies(SOAPY_SDR_RX, chan);
if (std::find(components.begin(), components.end(), "CORR") != components.end())
{
return _device->getFrequency(SOAPY_SDR_RX, chan, "CORR");
}
return 0.0;
#endif
} }
std::vector<std::string> soapy_source_c::get_gain_names( size_t chan ) std::vector<std::string> soapy_source_c::get_gain_names( size_t chan )