1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-06-24 21:15:24 -04:00

PlutoSDR input: implemented input class interim state (2)

This commit is contained in:
f4exb 2017-09-07 06:15:39 +02:00
parent 7b437e41ba
commit 5a05cf14bb
6 changed files with 78 additions and 16 deletions

View File

@ -20,6 +20,7 @@
#include <regex> #include <regex>
#include <iio.h> #include <iio.h>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <QtGlobal>
#include "deviceplutosdrbox.h" #include "deviceplutosdrbox.h"
@ -77,7 +78,7 @@ void DevicePlutoSDRBox::set_params(DeviceType devType,
if (pos == std::string::npos) 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; continue;
} }
@ -88,7 +89,7 @@ void DevicePlutoSDRBox::set_params(DeviceType devType,
if (ret) 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; continue;
} }
@ -102,7 +103,7 @@ void DevicePlutoSDRBox::set_params(DeviceType devType,
if (ret < 0) 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 &param,
if (ret) 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; return false;
} }
@ -150,7 +151,7 @@ bool DevicePlutoSDRBox::get_param(DeviceType devType, const std::string &param,
if (nchars < 0) 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; return false;
} }
else else
@ -160,6 +161,18 @@ bool DevicePlutoSDRBox::get_param(DeviceType devType, const std::string &param,
} }
} }
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() bool DevicePlutoSDRBox::openRx()
{ {
if (!m_chnRx0) { if (!m_chnRx0) {
@ -170,7 +183,7 @@ bool DevicePlutoSDRBox::openRx()
iio_channel_enable(m_chnRx0); iio_channel_enable(m_chnRx0);
return true; return true;
} else { } else {
std::cerr << "PlutoSDRDevice::openRx: failed" << std::endl; std::cerr << "DevicePlutoSDRBox::openRx: failed" << std::endl;
return false; return false;
} }
} }
@ -185,7 +198,7 @@ bool DevicePlutoSDRBox::openTx()
iio_channel_enable(m_chnTx0); iio_channel_enable(m_chnTx0);
return true; return true;
} else { } else {
std::cerr << "PlutoSDRDevice::openTx: failed" << std::endl; std::cerr << "DevicePlutoSDRBox::openTx: failed" << std::endl;
return false; 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) bool DevicePlutoSDRBox::parseSampleRates(const std::string& rateStr, SampleRates& sampleRates)
{ {
// Rx: "BBPLL:983040000 ADC:245760000 R2:122880000 R1:61440000 RF:30720000 RXSAMP:30720000" // 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 try
{ {
sampleRates.m_bbRate = boost::lexical_cast<uint32_t>(desc_match[1]); sampleRates.m_bbRate = boost::lexical_cast<uint32_t>(desc_match[1]) + 1;
sampleRates.m_addaConnvRate = boost::lexical_cast<uint32_t>(desc_match[2]); sampleRates.m_addaConnvRate = boost::lexical_cast<uint32_t>(desc_match[2]) + 1;
sampleRates.m_hb3Rate = boost::lexical_cast<uint32_t>(desc_match[3]); sampleRates.m_hb3Rate = boost::lexical_cast<uint32_t>(desc_match[3]) + 1;
sampleRates.m_hb2Rate = boost::lexical_cast<uint32_t>(desc_match[4]); sampleRates.m_hb2Rate = boost::lexical_cast<uint32_t>(desc_match[4]) + 1;
sampleRates.m_hb1Rate = boost::lexical_cast<uint32_t>(desc_match[5]); sampleRates.m_hb1Rate = boost::lexical_cast<uint32_t>(desc_match[5]) + 1;
sampleRates.m_firRate = boost::lexical_cast<uint32_t>(desc_match[6]); sampleRates.m_firRate = boost::lexical_cast<uint32_t>(desc_match[6]) + 1;
return true; return true;
} }
catch (const boost::bad_lexical_cast &e) catch (const boost::bad_lexical_cast &e)

View File

@ -51,6 +51,7 @@ public:
void set_params(DeviceType devType, const std::vector<std::string> &params); void set_params(DeviceType devType, const std::vector<std::string> &params);
bool get_param(DeviceType devType, const std::string &param, std::string &value); bool get_param(DeviceType devType, const std::string &param, std::string &value);
void set_filter(const std::string &filterConfigStr);
bool openRx(); bool openRx();
bool openTx(); bool openTx();
void closeRx(); void closeRx();

View File

@ -254,9 +254,11 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, bool fo
// - device to host sample rate is changed // - device to host sample rate is changed
// - rate governor is changed // - rate governor is changed
// - FIR filter decimation is changed // - FIR filter decimation is changed
// - FIR filter is enabled or disabled
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || if ((m_settings.m_devSampleRate != settings.m_devSampleRate) ||
(m_settings.m_rateGovernor != settings.m_rateGovernor) || (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; suspendAllOtherThreads = true;
suspendOwnThread = 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 // Change affecting device baseband sample rate potentially affecting all buddies device/host sample rate
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || if ((m_settings.m_devSampleRate != settings.m_devSampleRate) ||
(m_settings.m_rateGovernor != settings.m_rateGovernor) || (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<std::string> 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; forwardChangeAllDSP = true;
} }

View File

@ -44,7 +44,7 @@ public:
} }
private: private:
MsgConfigurePlutoSDR m_settings; PlutoSDRInputSettings m_settings;
bool m_force; bool m_force;
MsgConfigurePlutoSDR(const PlutoSDRInputSettings& settings, bool force) : MsgConfigurePlutoSDR(const PlutoSDRInputSettings& settings, bool force) :

View File

@ -129,3 +129,19 @@ bool PlutoSDRInputSettings::deserialize(const QByteArray& data)
return false; 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;
}
}

View File

@ -81,6 +81,7 @@ struct PlutoSDRInputSettings {
void resetToDefaults(); void resetToDefaults();
QByteArray serialize() const; QByteArray serialize() const;
bool deserialize(const QByteArray& data); bool deserialize(const QByteArray& data);
static void translateGovernor(RateGovernor gov, QString& s);
}; };
#endif /* _PLUTOSDR_PLUTOSDRINPUTSETTINGS_H_ */ #endif /* _PLUTOSDR_PLUTOSDRINPUTSETTINGS_H_ */