aboutsummaryrefslogtreecommitdiffstats
path: root/src/output
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2024-05-28 12:31:19 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2024-05-28 12:31:19 +0200
commit2784f199bce0455cc56b1eda9cbf3fbbba1b136e (patch)
tree60ad2b7c78b54946190ccc7c9be435a378fdec8c /src/output
parentc03474ea5ad656e0f2f89a8866a8ac651bd6bc76 (diff)
downloaddabmod-2784f199bce0455cc56b1eda9cbf3fbbba1b136e.tar.gz
dabmod-2784f199bce0455cc56b1eda9cbf3fbbba1b136e.tar.bz2
dabmod-2784f199bce0455cc56b1eda9cbf3fbbba1b136e.zip
Fix DEXTER freq readback, make SDRDevices responsible for updating conf freq
Diffstat (limited to 'src/output')
-rw-r--r--src/output/Dexter.cpp36
-rw-r--r--src/output/SDR.cpp2
-rw-r--r--src/output/Soapy.cpp3
-rw-r--r--src/output/UHD.cpp3
4 files changed, 28 insertions, 16 deletions
diff --git a/src/output/Dexter.cpp b/src/output/Dexter.cpp
index 26472e8..0cd21ca 100644
--- a/src/output/Dexter.cpp
+++ b/src/output/Dexter.cpp
@@ -2,7 +2,7 @@
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Her Majesty the
Queen in Right of Canada (Communications Research Center Canada)
- Copyright (C) 2023
+ Copyright (C) 2024
Matthias P. Braendli, matthias.braendli@mpb.li
http://opendigitalradio.org
@@ -111,13 +111,22 @@ Dexter::Dexter(SDRDeviceConfig& config) :
}
tune(m_conf.lo_offset, m_conf.frequency);
- // TODO m_conf.frequency = m_dexter_dsp_tx->getFrequency(SOAPY_SDR_TX, 0);
+ const double actual_freq = get_tx_freq();
etiLog.level(info) << "Dexter:Actual frequency: " <<
- std::fixed << std::setprecision(3) <<
- m_conf.frequency / 1000.0 << " kHz.";
+ std::fixed << std::setprecision(3) << actual_freq / 1000.0 << " kHz.";
- // skip: Set bandwidth
+ const auto actual_freq_long = llrint(round(actual_freq));
+ const auto configured_freq_long = llrint(round(m_conf.frequency - m_conf.lo_offset));
+
+ if (actual_freq_long != configured_freq_long) {
+ etiLog.level(error) << "Frequency tune: should " <<
+ std::fixed << std::setprecision(3) <<
+ (m_conf.frequency - m_conf.lo_offset) << " (" << configured_freq_long << ") " <<
+ " read back " << actual_freq << " (" << actual_freq_long << ")";
+ throw std::runtime_error("Could not set frequency!");
+ }
+ // skip: Set bandwidth
// skip: antenna
// The FIFO should not contain data, but setting gain=0 before setting start_clks to zero is an additional security
@@ -348,33 +357,36 @@ void Dexter::handle_hw_time()
void Dexter::tune(double lo_offset, double frequency)
{
- // lo_offset is applied to the DSP, and frequency is given to the ad9957
+ // lo_offset is applied to the DSP, and frequency is given to the ad9957, this gives lower spurs
- long long freq = frequency;
int r = 0;
- if ((r = iio_device_attr_write_longlong(m_ad9957, "center_frequency", freq)) != 0) {
+
+ const double freq = frequency - lo_offset;
+ if ((r = iio_device_attr_write_double(m_ad9957, "center_frequency", freq)) != 0) {
etiLog.level(warn) << "Failed to set ad9957.center_frequency = " << freq << " : " << get_iio_error(r);
}
- long long lo_offs = lo_offset;
+ long long lo_offs = std::round(lo_offset);
if ((r = iio_device_attr_write_longlong(m_dexter_dsp_tx, "frequency0", lo_offs)) != 0) {
etiLog.level(warn) << "Failed to set dexter_dsp_tx.frequency0 = " << lo_offs << " : " << get_iio_error(r);
}
+
+ m_conf.frequency = get_tx_freq();
}
double Dexter::get_tx_freq(void) const
{
- long long lo_offset = 0;
int r = 0;
+ long long lo_offset = 0;
if ((r = iio_device_attr_read_longlong(m_dexter_dsp_tx, "frequency0", &lo_offset)) != 0) {
etiLog.level(warn) << "Failed to read dexter_dsp_tx.frequency0: " << get_iio_error(r);
return 0;
}
- long long frequency = 0;
- if ((r = iio_device_attr_read_longlong(m_ad9957, "center_frequency", &frequency)) != 0) {
+ double frequency = 0;
+ if ((r = iio_device_attr_read_double(m_ad9957, "center_frequency", &frequency)) != 0) {
etiLog.level(warn) << "Failed to read ad9957.center_frequency: " << get_iio_error(r);
return 0;
}
diff --git a/src/output/SDR.cpp b/src/output/SDR.cpp
index 17668e3..594171f 100644
--- a/src/output/SDR.cpp
+++ b/src/output/SDR.cpp
@@ -382,7 +382,6 @@ void SDR::set_parameter(const string& parameter, const string& value)
else if (parameter == "freq") {
ss >> m_config.frequency;
m_device->tune(m_config.lo_offset, m_config.frequency);
- m_config.frequency = m_device->get_tx_freq();
}
else if (parameter == "channel") {
try {
@@ -390,7 +389,6 @@ void SDR::set_parameter(const string& parameter, const string& value)
m_config.frequency = frequency;
m_device->tune(m_config.lo_offset, m_config.frequency);
- m_config.frequency = m_device->get_tx_freq();
}
catch (const std::out_of_range& e) {
throw ParameterError("Cannot parse channel");
diff --git a/src/output/Soapy.cpp b/src/output/Soapy.cpp
index 7931860..6a198b5 100644
--- a/src/output/Soapy.cpp
+++ b/src/output/Soapy.cpp
@@ -86,7 +86,6 @@ Soapy::Soapy(SDRDeviceConfig& config) :
" ksps.";
tune(m_conf.lo_offset, m_conf.frequency);
- m_conf.frequency = m_device->getFrequency(SOAPY_SDR_TX, 0);
etiLog.level(info) << "SoapySDR:Actual frequency: " <<
std::fixed << std::setprecision(3) <<
m_conf.frequency / 1000.0 << " kHz.";
@@ -143,6 +142,8 @@ void Soapy::tune(double lo_offset, double frequency)
SoapySDR::Kwargs offset_arg;
offset_arg["OFFSET"] = to_string(lo_offset);
m_device->setFrequency(SOAPY_SDR_TX, 0, m_conf.frequency, offset_arg);
+
+ m_conf.frequency = m_device->getFrequency(SOAPY_SDR_TX, 0);
}
double Soapy::get_tx_freq(void) const
diff --git a/src/output/UHD.cpp b/src/output/UHD.cpp
index 094e021..e097692 100644
--- a/src/output/UHD.cpp
+++ b/src/output/UHD.cpp
@@ -204,7 +204,6 @@ UHD::UHD(SDRDeviceConfig& config) :
tune(m_conf.lo_offset, m_conf.frequency);
- m_conf.frequency = m_usrp->get_tx_freq();
etiLog.level(debug) << std::fixed << std::setprecision(3) <<
"OutputUHD:Actual TX frequency: " << m_conf.frequency;
@@ -285,6 +284,8 @@ void UHD::tune(double lo_offset, double frequency)
m_usrp->set_rx_freq(frequency);
}
+
+ m_conf.frequency = m_usrp->get_tx_freq();
}
double UHD::get_tx_freq(void) const