diff --git a/devices/plutosdr/deviceplutosdrbox.cpp b/devices/plutosdr/deviceplutosdrbox.cpp index 1c1903c3f..57dbcf640 100644 --- a/devices/plutosdr/deviceplutosdrbox.cpp +++ b/devices/plutosdr/deviceplutosdrbox.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "deviceplutosdrbox.h" @@ -77,7 +78,7 @@ void DevicePlutoSDRBox::set_params(DeviceType devType, if (pos == std::string::npos) { - std::cerr << "PlutoSDRDevice::set_params: Misformed line: " << *it << std::endl; + std::cerr << "DevicePlutoSDRBox::set_params: Misformed line: " << *it << std::endl; continue; } @@ -88,7 +89,7 @@ void DevicePlutoSDRBox::set_params(DeviceType devType, if (ret) { - std::cerr << "PlutoSDRDevice::set_params: Parameter not recognized: " << key << std::endl; + std::cerr << "DevicePlutoSDRBox::set_params: Parameter not recognized: " << key << std::endl; continue; } @@ -102,7 +103,7 @@ void DevicePlutoSDRBox::set_params(DeviceType devType, if (ret < 0) { - std::cerr << "PlutoSDRDevice::set_params: Unable to write attribute " << key << ": " << ret << std::endl; + std::cerr << "DevicePlutoSDRBox::set_params: Unable to write attribute " << key << ": " << ret << std::endl; } } } @@ -136,7 +137,7 @@ bool DevicePlutoSDRBox::get_param(DeviceType devType, const std::string ¶m, if (ret) { - std::cerr << "PlutoSDRDevice::get_param: Parameter not recognized: " << param << std::endl; + std::cerr << "DevicePlutoSDRBox::get_param: Parameter not recognized: " << param << std::endl; return false; } @@ -150,7 +151,7 @@ bool DevicePlutoSDRBox::get_param(DeviceType devType, const std::string ¶m, if (nchars < 0) { - std::cerr << "PlutoSDRDevice::get_param: Unable to read attribute " << param << ": " << nchars << std::endl; + std::cerr << "DevicePlutoSDRBox::get_param: Unable to read attribute " << param << ": " << nchars << std::endl; return false; } else @@ -160,6 +161,18 @@ bool DevicePlutoSDRBox::get_param(DeviceType devType, const std::string ¶m, } } +void DevicePlutoSDRBox::set_filter(const std::string &filterConfigStr) +{ + int ret; + + ret = iio_device_attr_write_raw(m_devPhy, "filter_fir_config", filterConfigStr.c_str(), filterConfigStr.size()); + + if (ret < 0) + { + std::cerr << "DevicePlutoSDRBox::set_filter: Unable to set: " << filterConfigStr << ": " << ret << std::endl; + } +} + bool DevicePlutoSDRBox::openRx() { if (!m_chnRx0) { @@ -170,7 +183,7 @@ bool DevicePlutoSDRBox::openRx() iio_channel_enable(m_chnRx0); return true; } else { - std::cerr << "PlutoSDRDevice::openRx: failed" << std::endl; + std::cerr << "DevicePlutoSDRBox::openRx: failed" << std::endl; return false; } } @@ -185,7 +198,7 @@ bool DevicePlutoSDRBox::openTx() iio_channel_enable(m_chnTx0); return true; } else { - std::cerr << "PlutoSDRDevice::openTx: failed" << std::endl; + std::cerr << "DevicePlutoSDRBox::openTx: failed" << std::endl; return false; } } @@ -328,6 +341,28 @@ char* DevicePlutoSDRBox::txBufferFirst() } } +bool DevicePlutoSDRBox::getRxSampleRates(SampleRates& sampleRates) +{ + std::string srStr; + + if (get_param(DEVICE_PHY, "rx_path_rates", srStr)) { + return parseSampleRates(srStr, sampleRates); + } else { + return false; + } +} + +bool DevicePlutoSDRBox::getTxSampleRates(SampleRates& sampleRates) +{ + std::string srStr; + + if (get_param(DEVICE_PHY, "tx_path_rates", srStr)) { + return parseSampleRates(srStr, sampleRates); + } else { + return false; + } +} + bool DevicePlutoSDRBox::parseSampleRates(const std::string& rateStr, SampleRates& sampleRates) { // Rx: "BBPLL:983040000 ADC:245760000 R2:122880000 R1:61440000 RF:30720000 RXSAMP:30720000" @@ -341,12 +376,12 @@ bool DevicePlutoSDRBox::parseSampleRates(const std::string& rateStr, SampleRates { try { - sampleRates.m_bbRate = boost::lexical_cast(desc_match[1]); - sampleRates.m_addaConnvRate = boost::lexical_cast(desc_match[2]); - sampleRates.m_hb3Rate = boost::lexical_cast(desc_match[3]); - sampleRates.m_hb2Rate = boost::lexical_cast(desc_match[4]); - sampleRates.m_hb1Rate = boost::lexical_cast(desc_match[5]); - sampleRates.m_firRate = boost::lexical_cast(desc_match[6]); + sampleRates.m_bbRate = boost::lexical_cast(desc_match[1]) + 1; + sampleRates.m_addaConnvRate = boost::lexical_cast(desc_match[2]) + 1; + sampleRates.m_hb3Rate = boost::lexical_cast(desc_match[3]) + 1; + sampleRates.m_hb2Rate = boost::lexical_cast(desc_match[4]) + 1; + sampleRates.m_hb1Rate = boost::lexical_cast(desc_match[5]) + 1; + sampleRates.m_firRate = boost::lexical_cast(desc_match[6]) + 1; return true; } catch (const boost::bad_lexical_cast &e) diff --git a/devices/plutosdr/deviceplutosdrbox.h b/devices/plutosdr/deviceplutosdrbox.h index 72e7d147d..e9f0d65eb 100644 --- a/devices/plutosdr/deviceplutosdrbox.h +++ b/devices/plutosdr/deviceplutosdrbox.h @@ -51,6 +51,7 @@ public: void set_params(DeviceType devType, const std::vector ¶ms); bool get_param(DeviceType devType, const std::string ¶m, std::string &value); + void set_filter(const std::string &filterConfigStr); bool openRx(); bool openTx(); void closeRx(); diff --git a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp index 5b90658cd..e1f19a7a1 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp @@ -254,9 +254,11 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, bool fo // - device to host sample rate is changed // - rate governor is changed // - FIR filter decimation is changed + // - FIR filter is enabled or disabled if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || (m_settings.m_rateGovernor != settings.m_rateGovernor) || - (m_settings.m_lpfFIRlog2Decim != settings.m_lpfFIRlog2Decim) || force) + (m_settings.m_lpfFIRlog2Decim != settings.m_lpfFIRlog2Decim) || + (m_settings.m_lpfFIREnable != settings.m_lpfFIREnable) || force) { suspendAllOtherThreads = true; suspendOwnThread = true; @@ -300,8 +302,15 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, bool fo // Change affecting device baseband sample rate potentially affecting all buddies device/host sample rate if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || (m_settings.m_rateGovernor != settings.m_rateGovernor) || - (m_settings.m_lpfFIRlog2Decim != settings.m_lpfFIRlog2Decim) || force) + (m_settings.m_lpfFIRlog2Decim != settings.m_lpfFIRlog2Decim) || + (m_settings.m_lpfFIREnable != settings.m_lpfFIREnable) || force) { + std::vector params; + params.push_back(QString(tr("in_voltage_sampling_frequency=%1").arg(settings.m_devSampleRate)).toStdString()); + QString rateGovStr; + PlutoSDRInputSettings::translateGovernor(settings.m_rateGovernor, rateGovStr); + params.push_back(QString(tr("trx_rate_governor=%1").arg(rateGovStr)).toStdString()); + params.push_back(QString(tr("in_voltage_filter_fir_en=%1").arg(settings.m_lpfFIREnable ? 1 : 0)).toStdString()); forwardChangeAllDSP = true; } diff --git a/plugins/samplesource/plutosdrinput/plutosdrinput.h b/plugins/samplesource/plutosdrinput/plutosdrinput.h index 6d010df14..388bc0095 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinput.h +++ b/plugins/samplesource/plutosdrinput/plutosdrinput.h @@ -44,7 +44,7 @@ public: } private: - MsgConfigurePlutoSDR m_settings; + PlutoSDRInputSettings m_settings; bool m_force; MsgConfigurePlutoSDR(const PlutoSDRInputSettings& settings, bool force) : diff --git a/plugins/samplesource/plutosdrinput/plutosdrinputsettings.cpp b/plugins/samplesource/plutosdrinput/plutosdrinputsettings.cpp index adb181f92..8ad076065 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinputsettings.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinputsettings.cpp @@ -129,3 +129,19 @@ bool PlutoSDRInputSettings::deserialize(const QByteArray& data) return false; } } + +void PlutoSDRInputSettings::translateGovernor(RateGovernor gov, QString& s) +{ + switch(gov) + { + case RATEGOV_NORMAL: + s = "normal"; + break; + case RATEGOV_HIGHOSR: + s = "highest_osr"; + break; + default: + s = "highest_osr"; + break; + } +} diff --git a/plugins/samplesource/plutosdrinput/plutosdrinputsettings.h b/plugins/samplesource/plutosdrinput/plutosdrinputsettings.h index 7c13f3a69..8a560d8f2 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinputsettings.h +++ b/plugins/samplesource/plutosdrinput/plutosdrinputsettings.h @@ -81,6 +81,7 @@ struct PlutoSDRInputSettings { void resetToDefaults(); QByteArray serialize() const; bool deserialize(const QByteArray& data); + static void translateGovernor(RateGovernor gov, QString& s); }; #endif /* _PLUTOSDR_PLUTOSDRINPUTSETTINGS_H_ */