2017-09-01 22:21:41 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
2019-04-11 00:39:30 -04:00
|
|
|
// (at your option) any later version. //
|
2017-09-01 22:21:41 -04:00
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#include <regex>
|
|
|
|
#include <iio.h>
|
2017-09-06 12:48:58 -04:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2017-09-07 00:15:39 -04:00
|
|
|
#include <QtGlobal>
|
2017-09-01 22:21:41 -04:00
|
|
|
|
2018-01-21 04:57:04 -05:00
|
|
|
#include "dsp/dsptypes.h"
|
2017-09-07 12:41:55 -04:00
|
|
|
#include "dsp/wfir.h"
|
2017-09-10 13:37:23 -04:00
|
|
|
#include "deviceplutosdr.h"
|
2017-09-01 22:21:41 -04:00
|
|
|
#include "deviceplutosdrbox.h"
|
|
|
|
|
|
|
|
DevicePlutoSDRBox::DevicePlutoSDRBox(const std::string& uri) :
|
2018-02-21 21:04:42 -05:00
|
|
|
m_devSampleRate(0),
|
|
|
|
m_LOppmTenths(0),
|
|
|
|
m_lpfFIREnable(false),
|
|
|
|
m_lpfFIRBW(100.0f),
|
|
|
|
m_lpfFIRlog2Decim(0),
|
2017-09-11 17:51:58 -04:00
|
|
|
m_lpfFIRRxGain(0),
|
|
|
|
m_lpfFIRTxGain(0),
|
2021-04-25 16:28:40 -04:00
|
|
|
m_ctx(nullptr),
|
|
|
|
m_devPhy(nullptr),
|
|
|
|
m_devRx(nullptr),
|
|
|
|
m_devTx(nullptr),
|
|
|
|
m_rxBuf(nullptr),
|
|
|
|
m_txBuf(nullptr),
|
2018-02-21 21:04:42 -05:00
|
|
|
m_xoInitial(0),
|
2021-05-04 10:32:58 -04:00
|
|
|
m_temp(0.0f),
|
|
|
|
m_rxSampleBytes(0),
|
|
|
|
m_txSampleBytes(0)
|
2017-09-01 22:21:41 -04:00
|
|
|
{
|
|
|
|
m_ctx = iio_create_context_from_uri(uri.c_str());
|
2017-09-22 21:42:58 -04:00
|
|
|
|
|
|
|
if (m_ctx)
|
|
|
|
{
|
|
|
|
m_devPhy = iio_context_find_device(m_ctx, "ad9361-phy");
|
|
|
|
m_devRx = iio_context_find_device(m_ctx, "cf-ad9361-lpc");
|
|
|
|
m_devTx = iio_context_find_device(m_ctx, "cf-ad9361-dds-core-lpc");
|
|
|
|
}
|
2020-08-17 07:46:46 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qCritical("DevicePlutoSDRBox::DevicePlutoSDRBox: cannot create context for uri: %s", uri.c_str());
|
|
|
|
}
|
2017-09-22 21:42:58 -04:00
|
|
|
|
2017-09-01 22:21:41 -04:00
|
|
|
m_valid = m_ctx && m_devPhy && m_devRx && m_devTx;
|
2017-09-07 17:27:24 -04:00
|
|
|
|
2021-04-25 16:28:40 -04:00
|
|
|
if (m_valid)
|
|
|
|
{
|
|
|
|
std::regex channelIdReg("voltage([0-9]+)");
|
|
|
|
|
2017-09-07 17:27:24 -04:00
|
|
|
getXO();
|
2021-04-25 16:28:40 -04:00
|
|
|
int nbRxChannels = iio_device_get_channels_count(m_devRx);
|
|
|
|
|
|
|
|
for (int i = 0; i < nbRxChannels; i++)
|
|
|
|
{
|
|
|
|
iio_channel *chn = iio_device_get_channel(m_devRx, i);
|
|
|
|
std::string channelId(iio_channel_get_id(chn));
|
|
|
|
|
|
|
|
if (std::regex_match(channelId, channelIdReg))
|
|
|
|
{
|
2021-05-01 03:50:51 -04:00
|
|
|
int nbAttributes = iio_channel_get_attrs_count(chn);
|
2021-04-25 16:28:40 -04:00
|
|
|
m_rxChannelIds.append(QString(channelId.c_str()));
|
|
|
|
m_rxChannels.append(chn);
|
2021-05-01 03:50:51 -04:00
|
|
|
qDebug("DevicePlutoSDRBox::DevicePlutoSDRBox: Rx: %s #Attrs: %d", channelId.c_str(), nbAttributes);
|
2021-04-25 16:28:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int nbTxChannels = iio_device_get_channels_count(m_devTx);
|
|
|
|
|
|
|
|
for (int i = 0; i < nbTxChannels; i++)
|
|
|
|
{
|
|
|
|
iio_channel *chn = iio_device_get_channel(m_devTx, i);
|
|
|
|
std::string channelId(iio_channel_get_id(chn));
|
|
|
|
|
|
|
|
if (std::regex_match(channelId, channelIdReg))
|
|
|
|
{
|
2021-05-01 03:50:51 -04:00
|
|
|
int nbAttributes = iio_channel_get_attrs_count(chn);
|
2021-04-25 16:28:40 -04:00
|
|
|
m_txChannelIds.append(QString(channelId.c_str()));
|
|
|
|
m_txChannels.append(chn);
|
2021-05-01 03:50:51 -04:00
|
|
|
qDebug("DevicePlutoSDRBox::DevicePlutoSDRBox: Tx: %s #Attrs: %d", channelId.c_str(), nbAttributes);
|
2021-04-25 16:28:40 -04:00
|
|
|
}
|
|
|
|
}
|
2017-09-07 17:27:24 -04:00
|
|
|
}
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
DevicePlutoSDRBox::~DevicePlutoSDRBox()
|
|
|
|
{
|
|
|
|
deleteRxBuffer();
|
|
|
|
deleteTxBuffer();
|
|
|
|
closeRx();
|
|
|
|
closeTx();
|
|
|
|
if (m_ctx) { iio_context_destroy(m_ctx); }
|
|
|
|
}
|
|
|
|
|
2017-09-22 21:42:58 -04:00
|
|
|
bool DevicePlutoSDRBox::probeURI(const std::string& uri)
|
|
|
|
{
|
|
|
|
bool retVal;
|
|
|
|
struct iio_context *ctx;
|
|
|
|
|
|
|
|
ctx = iio_create_context_from_uri(uri.c_str());
|
|
|
|
retVal = (ctx != 0);
|
|
|
|
|
|
|
|
if (ctx) {
|
|
|
|
iio_context_destroy(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2017-09-01 22:21:41 -04:00
|
|
|
void DevicePlutoSDRBox::set_params(DeviceType devType,
|
|
|
|
const std::vector<std::string>& params)
|
|
|
|
{
|
|
|
|
iio_device *dev;
|
|
|
|
|
|
|
|
switch (devType)
|
|
|
|
{
|
|
|
|
case DEVICE_PHY:
|
|
|
|
dev = m_devPhy;
|
|
|
|
break;
|
|
|
|
case DEVICE_RX:
|
|
|
|
dev = m_devRx;
|
|
|
|
break;
|
|
|
|
case DEVICE_TX:
|
|
|
|
dev = m_devTx;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev = m_devPhy;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (std::vector<std::string>::const_iterator it = params.begin(); it != params.end(); ++it)
|
|
|
|
{
|
|
|
|
struct iio_channel *chn = 0;
|
|
|
|
const char *attr = 0;
|
|
|
|
std::size_t pos;
|
|
|
|
int ret;
|
2017-09-08 21:09:17 -04:00
|
|
|
int type;
|
2017-09-01 22:21:41 -04:00
|
|
|
|
|
|
|
pos = it->find('=');
|
|
|
|
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
{
|
2021-01-19 06:36:56 -05:00
|
|
|
std::cerr << "DevicePlutoSDRBox::set_params: Malformed line: " << *it << std::endl;
|
2017-09-01 22:21:41 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string key = it->substr(0, pos);
|
|
|
|
std::string val = it->substr(pos + 1, std::string::npos);
|
|
|
|
|
|
|
|
ret = iio_device_identify_filename(dev, key.c_str(), &chn, &attr);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
2017-09-07 00:15:39 -04:00
|
|
|
std::cerr << "DevicePlutoSDRBox::set_params: Parameter not recognized: " << key << std::endl;
|
2017-09-01 22:21:41 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chn) {
|
|
|
|
ret = iio_channel_attr_write(chn, attr, val.c_str());
|
2017-09-08 21:09:17 -04:00
|
|
|
type = 0;
|
2017-09-01 22:21:41 -04:00
|
|
|
} else if (iio_device_find_attr(dev, attr)) {
|
|
|
|
ret = iio_device_attr_write(dev, attr, val.c_str());
|
2017-09-08 21:09:17 -04:00
|
|
|
type = 1;
|
2017-09-01 22:21:41 -04:00
|
|
|
} else {
|
|
|
|
ret = iio_device_debug_attr_write(dev, attr, val.c_str());
|
2017-09-08 21:09:17 -04:00
|
|
|
type = 2;
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2017-09-08 21:09:17 -04:00
|
|
|
std::string item;
|
2017-10-08 18:12:15 -04:00
|
|
|
char errstr[256];
|
2017-09-08 21:09:17 -04:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
item = "channel";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
item = "device";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
item = "debug";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
item = "unknown";
|
|
|
|
break;
|
|
|
|
}
|
2017-10-08 18:12:15 -04:00
|
|
|
iio_strerror(-ret, errstr, 255);
|
|
|
|
std::cerr << "DevicePlutoSDRBox::set_params: Unable to write " << item << " attribute " << key << "=" << val << ": " << errstr << " (" << ret << ") " << std::endl;
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
2017-09-09 04:44:42 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "DevicePlutoSDRBox::set_params: set attribute " << key << "=" << val << ": " << ret << std::endl;
|
|
|
|
}
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 09:06:40 -04:00
|
|
|
bool DevicePlutoSDRBox::get_param(DeviceType devType, const std::string ¶m, std::string &value)
|
|
|
|
{
|
|
|
|
struct iio_channel *chn = 0;
|
|
|
|
const char *attr = 0;
|
|
|
|
char valuestr[256];
|
|
|
|
int ret;
|
|
|
|
ssize_t nchars;
|
2017-09-05 17:51:03 -04:00
|
|
|
iio_device *dev;
|
|
|
|
|
|
|
|
switch (devType)
|
|
|
|
{
|
|
|
|
case DEVICE_PHY:
|
|
|
|
dev = m_devPhy;
|
|
|
|
break;
|
|
|
|
case DEVICE_RX:
|
|
|
|
dev = m_devRx;
|
|
|
|
break;
|
|
|
|
case DEVICE_TX:
|
|
|
|
dev = m_devTx;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev = m_devPhy;
|
|
|
|
break;
|
|
|
|
}
|
2017-09-05 09:06:40 -04:00
|
|
|
|
|
|
|
ret = iio_device_identify_filename(dev, param.c_str(), &chn, &attr);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
2017-09-07 00:15:39 -04:00
|
|
|
std::cerr << "DevicePlutoSDRBox::get_param: Parameter not recognized: " << param << std::endl;
|
2017-09-05 09:06:40 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chn) {
|
|
|
|
nchars = iio_channel_attr_read(chn, attr, valuestr, 256);
|
|
|
|
} else if (iio_device_find_attr(dev, attr)) {
|
|
|
|
nchars = iio_device_attr_read(dev, attr, valuestr, 256);
|
|
|
|
} else {
|
|
|
|
nchars = iio_device_debug_attr_read(dev, attr, valuestr, 256);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nchars < 0)
|
|
|
|
{
|
2017-09-07 00:15:39 -04:00
|
|
|
std::cerr << "DevicePlutoSDRBox::get_param: Unable to read attribute " << param << ": " << nchars << std::endl;
|
2017-09-05 09:06:40 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value.assign(valuestr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 16:24:09 -04:00
|
|
|
void DevicePlutoSDRBox::setFilter(const std::string &filterConfigStr)
|
2017-09-07 00:15:39 -04:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-01 22:21:41 -04:00
|
|
|
bool DevicePlutoSDRBox::openRx()
|
|
|
|
{
|
2017-09-22 21:42:58 -04:00
|
|
|
if (!m_valid) { return false; }
|
|
|
|
|
2021-04-25 16:28:40 -04:00
|
|
|
if (m_rxChannels.size() > 0)
|
|
|
|
{
|
|
|
|
iio_channel_enable(m_rxChannels.at(0));
|
2017-09-01 22:21:41 -04:00
|
|
|
|
2021-04-25 16:28:40 -04:00
|
|
|
const struct iio_data_format *df = iio_channel_get_data_format(m_rxChannels.at(0));
|
2020-08-19 04:02:50 -04:00
|
|
|
qDebug("DevicePlutoSDRBox::openRx channel I: length: %u bits: %u shift: %u signed: %s be: %s with_scale: %s scale: %lf repeat: %u",
|
2017-09-10 10:58:48 -04:00
|
|
|
df->length,
|
|
|
|
df->bits,
|
|
|
|
df->shift,
|
|
|
|
df->is_signed ? "true" : "false",
|
|
|
|
df->is_be ? "true" : "false",
|
|
|
|
df->with_scale? "true" : "false",
|
|
|
|
df->scale,
|
|
|
|
df->repeat);
|
2021-05-04 10:32:58 -04:00
|
|
|
m_rxSampleBytes = df->length / 8;
|
2021-04-25 16:28:40 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-01 03:50:51 -04:00
|
|
|
qWarning("DevicePlutoSDRBox::openRx: open channel I failed");
|
2017-09-01 22:21:41 -04:00
|
|
|
return false;
|
|
|
|
}
|
2020-08-19 04:02:50 -04:00
|
|
|
|
2021-04-25 16:28:40 -04:00
|
|
|
if (m_rxChannels.size() > 1)
|
|
|
|
{
|
|
|
|
iio_channel_enable(m_rxChannels.at(1));
|
2020-08-19 04:02:50 -04:00
|
|
|
|
2021-04-25 16:28:40 -04:00
|
|
|
const struct iio_data_format* df = iio_channel_get_data_format(m_rxChannels.at(1));
|
2020-08-19 04:02:50 -04:00
|
|
|
qDebug("DevicePlutoSDRBox::openRx channel Q: length: %u bits: %u shift: %u signed: %s be: %s with_scale: %s scale: %lf repeat: %u",
|
|
|
|
df->length,
|
|
|
|
df->bits,
|
|
|
|
df->shift,
|
|
|
|
df->is_signed ? "true" : "false",
|
|
|
|
df->is_be ? "true" : "false",
|
|
|
|
df->with_scale ? "true" : "false",
|
|
|
|
df->scale,
|
|
|
|
df->repeat);
|
|
|
|
return true;
|
|
|
|
}
|
2021-04-25 16:28:40 -04:00
|
|
|
else
|
|
|
|
{
|
2021-05-01 03:50:51 -04:00
|
|
|
qWarning("DevicePlutoSDRBox::openRx: open channel Q failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DevicePlutoSDRBox::openSecondRx()
|
|
|
|
{
|
|
|
|
if (!m_valid) { return false; }
|
|
|
|
|
|
|
|
if (m_rxChannels.size() > 2)
|
|
|
|
{
|
|
|
|
iio_channel_enable(m_rxChannels.at(2));
|
|
|
|
|
|
|
|
const struct iio_data_format *df = iio_channel_get_data_format(m_rxChannels.at(2));
|
|
|
|
qDebug("DevicePlutoSDRBox::openSecondRx channel I: length: %u bits: %u shift: %u signed: %s be: %s with_scale: %s scale: %lf repeat: %u",
|
|
|
|
df->length,
|
|
|
|
df->bits,
|
|
|
|
df->shift,
|
|
|
|
df->is_signed ? "true" : "false",
|
|
|
|
df->is_be ? "true" : "false",
|
|
|
|
df->with_scale? "true" : "false",
|
|
|
|
df->scale,
|
|
|
|
df->repeat);
|
2021-05-04 10:32:58 -04:00
|
|
|
m_rxSampleBytes = df->length / 8;
|
2021-05-01 03:50:51 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning("DevicePlutoSDRBox::openSecondRx: open channel I failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_rxChannels.size() > 3)
|
|
|
|
{
|
|
|
|
iio_channel_enable(m_rxChannels.at(3));
|
|
|
|
|
|
|
|
const struct iio_data_format* df = iio_channel_get_data_format(m_rxChannels.at(3));
|
|
|
|
qDebug("DevicePlutoSDRBox::openSecondRx channel Q: length: %u bits: %u shift: %u signed: %s be: %s with_scale: %s scale: %lf repeat: %u",
|
|
|
|
df->length,
|
|
|
|
df->bits,
|
|
|
|
df->shift,
|
|
|
|
df->is_signed ? "true" : "false",
|
|
|
|
df->is_be ? "true" : "false",
|
|
|
|
df->with_scale ? "true" : "false",
|
|
|
|
df->scale,
|
|
|
|
df->repeat);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning("DevicePlutoSDRBox::openSecondRx: open channel Q failed");
|
2020-08-19 04:02:50 -04:00
|
|
|
return false;
|
|
|
|
}
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DevicePlutoSDRBox::openTx()
|
|
|
|
{
|
2017-09-22 21:42:58 -04:00
|
|
|
if (!m_valid) { return false; }
|
|
|
|
|
2021-04-25 16:28:40 -04:00
|
|
|
if (m_txChannels.size() > 0)
|
|
|
|
{
|
|
|
|
iio_channel_enable(m_txChannels.at(0));
|
|
|
|
const struct iio_data_format *df = iio_channel_get_data_format(m_txChannels.at(0));
|
2017-10-28 22:01:44 -04:00
|
|
|
qDebug("DevicePlutoSDRBox::openTx: channel I: length: %u bits: %u shift: %u signed: %s be: %s with_scale: %s scale: %lf repeat: %u",
|
|
|
|
df->length,
|
|
|
|
df->bits,
|
|
|
|
df->shift,
|
|
|
|
df->is_signed ? "true" : "false",
|
|
|
|
df->is_be ? "true" : "false",
|
|
|
|
df->with_scale? "true" : "false",
|
|
|
|
df->scale,
|
|
|
|
df->repeat);
|
2021-05-04 10:32:58 -04:00
|
|
|
m_txSampleBytes = df->length / 8;
|
2021-04-25 16:28:40 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-28 22:01:44 -04:00
|
|
|
std::cerr << "DevicePlutoSDRBox::openTx: failed to open I channel" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-25 16:28:40 -04:00
|
|
|
if (m_txChannels.size() > 1)
|
|
|
|
{
|
|
|
|
iio_channel_enable(m_txChannels.at(1));
|
|
|
|
const struct iio_data_format *df = iio_channel_get_data_format(m_txChannels.at(1));
|
2017-10-28 22:01:44 -04:00
|
|
|
qDebug("DevicePlutoSDRBox::openTx: channel Q: length: %u bits: %u shift: %u signed: %s be: %s with_scale: %s scale: %lf repeat: %u",
|
2017-09-10 10:58:48 -04:00
|
|
|
df->length,
|
|
|
|
df->bits,
|
|
|
|
df->shift,
|
|
|
|
df->is_signed ? "true" : "false",
|
|
|
|
df->is_be ? "true" : "false",
|
|
|
|
df->with_scale? "true" : "false",
|
|
|
|
df->scale,
|
|
|
|
df->repeat);
|
2017-09-01 22:21:41 -04:00
|
|
|
return true;
|
2021-04-25 16:28:40 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-28 22:01:44 -04:00
|
|
|
std::cerr << "DevicePlutoSDRBox::openTx: failed to open Q channel" << std::endl;
|
2017-09-01 22:21:41 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 03:50:51 -04:00
|
|
|
bool DevicePlutoSDRBox::openSecondTx()
|
|
|
|
{
|
|
|
|
if (!m_valid) { return false; }
|
|
|
|
|
|
|
|
if (m_txChannels.size() > 2)
|
|
|
|
{
|
|
|
|
iio_channel_enable(m_txChannels.at(2));
|
|
|
|
const struct iio_data_format *df = iio_channel_get_data_format(m_txChannels.at(2));
|
|
|
|
qDebug("DevicePlutoSDRBox::openSecondTx: channel I: length: %u bits: %u shift: %u signed: %s be: %s with_scale: %s scale: %lf repeat: %u",
|
|
|
|
df->length,
|
|
|
|
df->bits,
|
|
|
|
df->shift,
|
|
|
|
df->is_signed ? "true" : "false",
|
|
|
|
df->is_be ? "true" : "false",
|
|
|
|
df->with_scale? "true" : "false",
|
|
|
|
df->scale,
|
|
|
|
df->repeat);
|
2021-05-04 10:32:58 -04:00
|
|
|
m_txSampleBytes = df->length / 8;
|
2021-05-01 03:50:51 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning("DevicePlutoSDRBox::openSecondTx: failed to open I channel");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_txChannels.size() > 3)
|
|
|
|
{
|
|
|
|
iio_channel_enable(m_txChannels.at(3));
|
|
|
|
const struct iio_data_format *df = iio_channel_get_data_format(m_txChannels.at(3));
|
|
|
|
qDebug("DevicePlutoSDRBox::openSecondTx: channel Q: length: %u bits: %u shift: %u signed: %s be: %s with_scale: %s scale: %lf repeat: %u",
|
|
|
|
df->length,
|
|
|
|
df->bits,
|
|
|
|
df->shift,
|
|
|
|
df->is_signed ? "true" : "false",
|
|
|
|
df->is_be ? "true" : "false",
|
|
|
|
df->with_scale? "true" : "false",
|
|
|
|
df->scale,
|
|
|
|
df->repeat);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning("DevicePlutoSDRBox::openSecondTx: failed to open Q channel");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-01 22:21:41 -04:00
|
|
|
void DevicePlutoSDRBox::closeRx()
|
|
|
|
{
|
2021-04-25 16:28:40 -04:00
|
|
|
if (m_rxChannels.size() > 0) { iio_channel_disable(m_rxChannels.at(0)); }
|
|
|
|
if (m_rxChannels.size() > 1) { iio_channel_disable(m_rxChannels.at(1)); }
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
|
2021-05-01 03:50:51 -04:00
|
|
|
void DevicePlutoSDRBox::closeSecondRx()
|
|
|
|
{
|
|
|
|
if (m_rxChannels.size() > 2) { iio_channel_disable(m_rxChannels.at(2)); }
|
|
|
|
if (m_rxChannels.size() > 3) { iio_channel_disable(m_rxChannels.at(3)); }
|
|
|
|
}
|
|
|
|
|
2017-09-01 22:21:41 -04:00
|
|
|
void DevicePlutoSDRBox::closeTx()
|
|
|
|
{
|
2021-04-25 16:28:40 -04:00
|
|
|
if (m_txChannels.size() > 0) { iio_channel_disable(m_txChannels.at(0)); }
|
|
|
|
if (m_txChannels.size() > 1) { iio_channel_disable(m_txChannels.at(1)); }
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
|
2021-05-01 03:50:51 -04:00
|
|
|
void DevicePlutoSDRBox::closeSecondTx()
|
|
|
|
{
|
|
|
|
if (m_txChannels.size() > 2) { iio_channel_disable(m_txChannels.at(2)); }
|
|
|
|
if (m_txChannels.size() > 3) { iio_channel_disable(m_txChannels.at(3)); }
|
|
|
|
}
|
|
|
|
|
2017-09-01 22:21:41 -04:00
|
|
|
struct iio_buffer *DevicePlutoSDRBox::createRxBuffer(unsigned int size, bool cyclic)
|
|
|
|
{
|
|
|
|
if (m_devRx) {
|
|
|
|
m_rxBuf = iio_device_create_buffer(m_devRx, size, cyclic ? '\1' : '\0');
|
|
|
|
} else {
|
2021-05-02 07:06:10 -04:00
|
|
|
m_rxBuf = nullptr;
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_rxBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iio_buffer *DevicePlutoSDRBox::createTxBuffer(unsigned int size, bool cyclic)
|
|
|
|
{
|
|
|
|
if (m_devTx) {
|
|
|
|
m_txBuf = iio_device_create_buffer(m_devTx, size, cyclic ? '\1' : '\0');
|
|
|
|
} else {
|
2021-05-02 07:06:10 -04:00
|
|
|
m_txBuf = nullptr;
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_txBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DevicePlutoSDRBox::deleteRxBuffer()
|
|
|
|
{
|
2021-05-02 07:06:10 -04:00
|
|
|
if (m_rxBuf)
|
|
|
|
{
|
2017-09-01 22:21:41 -04:00
|
|
|
iio_buffer_destroy(m_rxBuf);
|
2021-05-02 07:06:10 -04:00
|
|
|
m_rxBuf = nullptr;
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DevicePlutoSDRBox::deleteTxBuffer()
|
|
|
|
{
|
2021-05-02 07:06:10 -04:00
|
|
|
if (m_txBuf)
|
|
|
|
{
|
2017-09-01 22:21:41 -04:00
|
|
|
iio_buffer_destroy(m_txBuf);
|
2021-05-02 07:06:10 -04:00
|
|
|
m_txBuf = nullptr;
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t DevicePlutoSDRBox::getRxSampleSize()
|
|
|
|
{
|
|
|
|
if (m_devRx) {
|
|
|
|
return iio_device_get_sample_size(m_devRx);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t DevicePlutoSDRBox::getTxSampleSize()
|
|
|
|
{
|
|
|
|
if (m_devTx) {
|
|
|
|
return iio_device_get_sample_size(m_devTx);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t DevicePlutoSDRBox::rxBufferRefill()
|
|
|
|
{
|
|
|
|
if (m_rxBuf) {
|
|
|
|
return iio_buffer_refill(m_rxBuf);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t DevicePlutoSDRBox::txBufferPush()
|
|
|
|
{
|
|
|
|
if (m_txBuf) {
|
|
|
|
return iio_buffer_push(m_txBuf);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ptrdiff_t DevicePlutoSDRBox::rxBufferStep()
|
|
|
|
{
|
|
|
|
if (m_rxBuf) {
|
|
|
|
return iio_buffer_step(m_rxBuf);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char* DevicePlutoSDRBox::rxBufferEnd()
|
|
|
|
{
|
|
|
|
if (m_rxBuf) {
|
|
|
|
return (char *) iio_buffer_end(m_rxBuf);
|
|
|
|
} else {
|
2021-04-25 16:28:40 -04:00
|
|
|
return nullptr;
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char* DevicePlutoSDRBox::rxBufferFirst()
|
|
|
|
{
|
|
|
|
if (m_rxBuf) {
|
2021-04-25 16:28:40 -04:00
|
|
|
return (char *) iio_buffer_first(m_rxBuf, m_rxChannels.at(0));
|
2017-09-01 22:21:41 -04:00
|
|
|
} else {
|
2021-04-25 16:28:40 -04:00
|
|
|
return nullptr;
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ptrdiff_t DevicePlutoSDRBox::txBufferStep()
|
|
|
|
{
|
|
|
|
if (m_txBuf) {
|
|
|
|
return iio_buffer_step(m_txBuf);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char* DevicePlutoSDRBox::txBufferEnd()
|
|
|
|
{
|
|
|
|
if (m_txBuf) {
|
|
|
|
return (char *) iio_buffer_end(m_txBuf);
|
|
|
|
} else {
|
2021-04-25 16:28:40 -04:00
|
|
|
return nullptr;
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char* DevicePlutoSDRBox::txBufferFirst()
|
|
|
|
{
|
|
|
|
if (m_txBuf) {
|
2021-04-25 16:28:40 -04:00
|
|
|
return (char *) iio_buffer_first(m_txBuf, m_txChannels.at(0));
|
2017-09-01 22:21:41 -04:00
|
|
|
} else {
|
2021-04-25 16:28:40 -04:00
|
|
|
return nullptr;
|
2017-09-01 22:21:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-28 22:01:44 -04:00
|
|
|
void DevicePlutoSDRBox::txChannelConvert(int16_t *dst, int16_t *src)
|
|
|
|
{
|
2021-04-25 16:28:40 -04:00
|
|
|
if (m_txChannels.size() > 0) {
|
|
|
|
iio_channel_convert_inverse(m_txChannels.at(0), &dst[0], &src[0]);
|
2017-10-28 22:01:44 -04:00
|
|
|
}
|
2021-04-25 16:28:40 -04:00
|
|
|
if (m_txChannels.size() > 1) {
|
|
|
|
iio_channel_convert_inverse(m_txChannels.at(1), &dst[1], &src[1]);
|
2017-10-28 22:01:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 03:50:51 -04:00
|
|
|
void DevicePlutoSDRBox::txChannelConvert(int chanIndex, int16_t *dst, int16_t *src)
|
|
|
|
{
|
|
|
|
if (m_txChannels.size() > 2*chanIndex) {
|
|
|
|
iio_channel_convert_inverse(m_txChannels.at(2*chanIndex), &dst[0], &src[0]);
|
|
|
|
}
|
|
|
|
if (m_txChannels.size() > 2*chanIndex+1) {
|
|
|
|
iio_channel_convert_inverse(m_txChannels.at(2*chanIndex+1), &dst[1], &src[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 00:15:39 -04:00
|
|
|
bool DevicePlutoSDRBox::getRxSampleRates(SampleRates& sampleRates)
|
|
|
|
{
|
|
|
|
std::string srStr;
|
|
|
|
|
|
|
|
if (get_param(DEVICE_PHY, "rx_path_rates", srStr)) {
|
2017-09-08 21:09:17 -04:00
|
|
|
qDebug("DevicePlutoSDRBox::getRxSampleRates: %s", srStr.c_str());
|
2017-09-07 00:15:39 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-06 12:48:58 -04:00
|
|
|
bool DevicePlutoSDRBox::parseSampleRates(const std::string& rateStr, SampleRates& sampleRates)
|
|
|
|
{
|
|
|
|
// Rx: "BBPLL:983040000 ADC:245760000 R2:122880000 R1:61440000 RF:30720000 RXSAMP:30720000"
|
|
|
|
// Tx: "BBPLL:983040000 DAC:122880000 T2:122880000 T1:61440000 TF:30720000 TXSAMP:30720000"
|
|
|
|
std::regex desc_regex("BBPLL:(.+) ..C:(.+) .2:(.+) .1:(.+) .F:(.+) .XSAMP:(.+)");
|
|
|
|
std::smatch desc_match;
|
|
|
|
std::regex_search(rateStr, desc_match, desc_regex);
|
|
|
|
std::string valueStr;
|
|
|
|
|
|
|
|
if (desc_match.size() == 7)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-09-09 09:34:04 -04:00
|
|
|
sampleRates.m_bbRateHz = boost::lexical_cast<uint32_t>(desc_match[1]);
|
2017-09-10 04:16:23 -04:00
|
|
|
sampleRates.m_addaConnvRate = boost::lexical_cast<uint32_t>(desc_match[2]);
|
|
|
|
sampleRates.m_hb3Rate = boost::lexical_cast<uint32_t>(desc_match[3]);
|
|
|
|
sampleRates.m_hb2Rate = boost::lexical_cast<uint32_t>(desc_match[4]);
|
|
|
|
sampleRates.m_hb1Rate = boost::lexical_cast<uint32_t>(desc_match[5]);
|
|
|
|
sampleRates.m_firRate = boost::lexical_cast<uint32_t>(desc_match[6]);
|
2017-09-06 12:48:58 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast &e)
|
|
|
|
{
|
|
|
|
qWarning("DevicePlutoSDRBox::parseSampleRates: bad conversion to numeric");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-09-01 22:21:41 -04:00
|
|
|
|
2017-09-08 21:09:17 -04:00
|
|
|
void DevicePlutoSDRBox::setSampleRate(uint32_t sampleRate)
|
|
|
|
{
|
2017-09-10 06:07:54 -04:00
|
|
|
char buff[100];
|
|
|
|
std::vector<std::string> params;
|
|
|
|
snprintf(buff, sizeof(buff), "in_voltage_sampling_frequency=%d", sampleRate);
|
|
|
|
params.push_back(std::string(buff));
|
|
|
|
snprintf(buff, sizeof(buff), "out_voltage_sampling_frequency=%d", sampleRate);
|
|
|
|
params.push_back(std::string(buff));
|
|
|
|
set_params(DEVICE_PHY, params);
|
2017-09-08 21:09:17 -04:00
|
|
|
m_devSampleRate = sampleRate;
|
|
|
|
}
|
|
|
|
|
2017-09-11 17:51:58 -04:00
|
|
|
/**
|
|
|
|
* @param sampleRate baseband sample rate (S/s)
|
|
|
|
* @param log2IntDec FIR interpolation or decimation factor
|
|
|
|
* @param use Rx or Tx. Applies to the rest of the parameters
|
|
|
|
* @param bw FIR filter bandwidth at approximately -6 dB cutoff (Hz)
|
|
|
|
* @param gain FIR filter gain (dB)
|
|
|
|
*/
|
|
|
|
void DevicePlutoSDRBox::setFIR(uint32_t sampleRate, uint32_t log2IntDec, DeviceUse use, uint32_t bw, int gain)
|
2017-09-07 02:49:22 -04:00
|
|
|
{
|
|
|
|
SampleRates sampleRates;
|
|
|
|
std::ostringstream ostr;
|
|
|
|
|
|
|
|
uint32_t nbTaps;
|
2017-09-07 12:41:55 -04:00
|
|
|
double normalizedBW;
|
2017-09-08 21:09:17 -04:00
|
|
|
uint32_t intdec = 1<<(log2IntDec > 2 ? 2 : log2IntDec);
|
2017-09-07 12:41:55 -04:00
|
|
|
|
2017-09-11 17:51:58 -04:00
|
|
|
// update gain parameter
|
|
|
|
|
|
|
|
if (use == USE_RX) {
|
|
|
|
m_lpfFIRRxGain = gain;
|
|
|
|
} else {
|
|
|
|
m_lpfFIRTxGain = gain;
|
|
|
|
}
|
|
|
|
|
2017-09-07 12:41:55 -04:00
|
|
|
// set a dummy minimal filter first to get the sample rates right
|
|
|
|
|
2017-09-08 21:09:17 -04:00
|
|
|
setFIREnable(false); // disable first
|
|
|
|
|
2017-09-11 17:51:58 -04:00
|
|
|
formatFIRHeader(ostr, intdec);
|
2017-09-07 12:41:55 -04:00
|
|
|
formatFIRCoefficients(ostr, 16, 0.5);
|
|
|
|
setFilter(ostr.str());
|
|
|
|
ostr.str(""); // reset string stream
|
2017-09-07 02:49:22 -04:00
|
|
|
|
2017-09-10 12:35:38 -04:00
|
|
|
setFIREnable(true); // re-enable
|
|
|
|
setSampleRate(sampleRate); // set to new sample rate
|
2017-09-07 02:49:22 -04:00
|
|
|
|
2017-09-08 21:09:17 -04:00
|
|
|
if (!getRxSampleRates(sampleRates)) {
|
|
|
|
return;
|
2017-09-07 02:49:22 -04:00
|
|
|
}
|
|
|
|
|
2017-09-08 21:09:17 -04:00
|
|
|
setFIREnable(false); // disable again
|
|
|
|
|
2017-09-10 04:16:23 -04:00
|
|
|
uint32_t nbGroups = sampleRates.m_addaConnvRate / 16;
|
2017-09-08 21:09:17 -04:00
|
|
|
nbTaps = nbGroups*8 > 128 ? 128 : nbGroups*8;
|
|
|
|
nbTaps = intdec == 1 ? (nbTaps > 64 ? 64 : nbTaps) : nbTaps;
|
2017-09-10 04:16:23 -04:00
|
|
|
normalizedBW = ((float) bw) / sampleRates.m_hb1Rate;
|
2017-09-10 13:37:23 -04:00
|
|
|
normalizedBW = normalizedBW < DevicePlutoSDR::firBWLowLimitFactor ?
|
|
|
|
DevicePlutoSDR::firBWLowLimitFactor :
|
|
|
|
normalizedBW > DevicePlutoSDR::firBWHighLimitFactor ? DevicePlutoSDR::firBWHighLimitFactor : normalizedBW;
|
2017-09-08 21:09:17 -04:00
|
|
|
|
|
|
|
qDebug("DevicePlutoSDRBox::setFIR: intdec: %u gain: %d nbTaps: %u BWin: %u BW: %f (%f)",
|
|
|
|
intdec,
|
|
|
|
gain,
|
|
|
|
nbTaps,
|
|
|
|
bw,
|
2017-09-10 04:16:23 -04:00
|
|
|
normalizedBW*sampleRates.m_hb1Rate,
|
2017-09-08 21:09:17 -04:00
|
|
|
normalizedBW);
|
2017-09-07 12:41:55 -04:00
|
|
|
|
|
|
|
// set the right filter
|
|
|
|
|
2017-09-11 17:51:58 -04:00
|
|
|
formatFIRHeader(ostr, intdec);
|
2017-09-07 12:41:55 -04:00
|
|
|
formatFIRCoefficients(ostr, nbTaps, normalizedBW);
|
|
|
|
setFilter(ostr.str());
|
2017-09-08 21:09:17 -04:00
|
|
|
|
|
|
|
m_lpfFIRlog2Decim = log2IntDec;
|
|
|
|
m_lpfFIRBW = bw;
|
2017-09-10 12:35:38 -04:00
|
|
|
|
|
|
|
// enable and set sample rate will be done by the caller
|
2017-09-08 21:09:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DevicePlutoSDRBox::setFIREnable(bool enable)
|
|
|
|
{
|
|
|
|
char buff[100];
|
|
|
|
std::vector<std::string> params;
|
|
|
|
snprintf(buff, sizeof(buff), "in_out_voltage_filter_fir_en=%d", enable ? 1 : 0);
|
|
|
|
params.push_back(std::string(buff));
|
|
|
|
set_params(DEVICE_PHY, params);
|
|
|
|
m_lpfFIREnable = enable;
|
2017-09-07 02:49:22 -04:00
|
|
|
}
|
|
|
|
|
2017-09-08 21:09:17 -04:00
|
|
|
void DevicePlutoSDRBox::setLOPPMTenths(int ppmTenths)
|
2017-09-07 12:41:55 -04:00
|
|
|
{
|
2017-09-08 21:09:17 -04:00
|
|
|
char buff[100];
|
|
|
|
std::vector<std::string> params;
|
|
|
|
int64_t newXO = m_xoInitial + ((m_xoInitial*ppmTenths) / 10000000L);
|
2018-02-21 12:54:59 -05:00
|
|
|
snprintf(buff, sizeof(buff), "xo_correction=%ld", (long int) newXO);
|
2017-09-08 21:09:17 -04:00
|
|
|
params.push_back(std::string(buff));
|
|
|
|
set_params(DEVICE_PHY, params);
|
|
|
|
m_LOppmTenths = ppmTenths;
|
|
|
|
}
|
|
|
|
|
2017-09-11 17:51:58 -04:00
|
|
|
void DevicePlutoSDRBox::formatFIRHeader(std::ostringstream& ostr,uint32_t intdec)
|
2017-09-08 21:09:17 -04:00
|
|
|
{
|
2017-09-11 17:51:58 -04:00
|
|
|
ostr << "RX 3 GAIN " << m_lpfFIRRxGain << " DEC " << intdec << std::endl;
|
|
|
|
ostr << "TX 3 GAIN " << m_lpfFIRTxGain << " INT " << intdec << std::endl;
|
2017-09-07 12:41:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DevicePlutoSDRBox::formatFIRCoefficients(std::ostringstream& ostr, uint32_t nbTaps, double normalizedBW)
|
|
|
|
{
|
2017-09-07 16:24:09 -04:00
|
|
|
double *fcoeffs = new double[nbTaps];
|
2017-09-12 12:49:12 -04:00
|
|
|
WFIR::BasicFIR(fcoeffs, nbTaps, WFIR::LPF, normalizedBW, 0.0, normalizedBW < 0.2 ? WFIR::wtHAMMING : WFIR::wtBLACKMAN_HARRIS, 0.0);
|
2017-09-07 12:41:55 -04:00
|
|
|
|
2017-09-07 16:24:09 -04:00
|
|
|
for (unsigned int i = 0; i < nbTaps; i++) {
|
2018-01-22 02:46:05 -05:00
|
|
|
ostr << (int16_t) (fcoeffs[i] * 32768.0f) << ", " << (int16_t) (fcoeffs[i] * 32768.0f) << std::endl;
|
2017-09-07 12:41:55 -04:00
|
|
|
}
|
2017-09-08 21:09:17 -04:00
|
|
|
|
|
|
|
delete[] fcoeffs;
|
2017-09-07 12:41:55 -04:00
|
|
|
}
|
2017-09-01 22:21:41 -04:00
|
|
|
|
2017-09-07 17:27:24 -04:00
|
|
|
void DevicePlutoSDRBox::getXO()
|
|
|
|
{
|
|
|
|
std::string valueStr;
|
|
|
|
get_param(DEVICE_PHY, "xo_correction", valueStr);
|
|
|
|
try
|
|
|
|
{
|
2019-04-15 10:17:36 -04:00
|
|
|
m_xoInitial = boost::lexical_cast<quint64>(valueStr);
|
2019-04-20 18:13:14 -04:00
|
|
|
qDebug("DevicePlutoSDRBox::getXO: %ld", m_xoInitial);
|
2017-09-07 17:27:24 -04:00
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast &e)
|
|
|
|
{
|
|
|
|
qWarning("DevicePlutoSDRBox::getXO: cannot get initial XO correction");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-08 20:18:04 -04:00
|
|
|
bool DevicePlutoSDRBox::getRxGain(int& gaindB, unsigned int chan)
|
|
|
|
{
|
|
|
|
chan = chan % 2;
|
|
|
|
char buff[30];
|
|
|
|
snprintf(buff, sizeof(buff), "in_voltage%d_hardwaregain", chan);
|
|
|
|
std::string gainStr;
|
|
|
|
get_param(DEVICE_PHY, buff, gainStr);
|
|
|
|
|
|
|
|
std::regex gain_regex("(.+)\\.(.+) dB");
|
|
|
|
std::smatch gain_match;
|
|
|
|
std::regex_search(gainStr, gain_match, gain_regex);
|
|
|
|
|
|
|
|
if (gain_match.size() == 3)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
gaindB = boost::lexical_cast<int>(gain_match[1]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast &e)
|
|
|
|
{
|
|
|
|
qWarning("DevicePlutoSDRBox::getRxGain: bad conversion to numeric");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-19 02:33:26 -04:00
|
|
|
bool DevicePlutoSDRBox::getRxRSSI(std::string& rssiStr, unsigned int chan)
|
2017-09-08 21:09:17 -04:00
|
|
|
{
|
|
|
|
chan = chan % 2;
|
|
|
|
char buff[20];
|
|
|
|
snprintf(buff, sizeof(buff), "in_voltage%d_rssi", chan);
|
|
|
|
return get_param(DEVICE_PHY, buff, rssiStr);
|
|
|
|
}
|
|
|
|
|
2017-09-19 02:33:26 -04:00
|
|
|
bool DevicePlutoSDRBox::getTxRSSI(std::string& rssiStr, unsigned int chan)
|
|
|
|
{
|
|
|
|
chan = chan % 2;
|
|
|
|
char buff[20];
|
|
|
|
snprintf(buff, sizeof(buff), "out_voltage%d_rssi", chan);
|
|
|
|
return get_param(DEVICE_PHY, buff, rssiStr);
|
|
|
|
}
|
|
|
|
|
2019-01-04 05:23:54 -05:00
|
|
|
void DevicePlutoSDRBox::getRxLORange(uint64_t& minLimit, uint64_t& maxLimit)
|
2019-01-02 08:50:33 -05:00
|
|
|
{
|
|
|
|
// values are returned in Hz
|
|
|
|
qint64 stepLimit;
|
|
|
|
std::string rangeStr;
|
|
|
|
|
|
|
|
char buff[50];
|
2019-01-04 05:23:54 -05:00
|
|
|
snprintf(buff, sizeof(buff), "out_altvoltage0_RX_LO_frequency_available");
|
2019-01-02 08:50:33 -05:00
|
|
|
|
2019-01-04 05:23:54 -05:00
|
|
|
if (get_param(DEVICE_PHY, buff, rangeStr))
|
|
|
|
{
|
2019-01-02 08:50:33 -05:00
|
|
|
std::istringstream instream(rangeStr.substr(1, rangeStr.size() - 2));
|
2019-01-04 05:23:54 -05:00
|
|
|
instream >> minLimit >> stepLimit >> maxLimit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
minLimit = DevicePlutoSDR::rxLOLowLimitFreq;
|
|
|
|
maxLimit = DevicePlutoSDR::rxLOHighLimitFreq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DevicePlutoSDRBox::getTxLORange(uint64_t& minLimit, uint64_t& maxLimit)
|
|
|
|
{
|
|
|
|
// values are returned in Hz
|
|
|
|
qint64 stepLimit;
|
|
|
|
std::string rangeStr;
|
|
|
|
|
|
|
|
char buff[50];
|
|
|
|
snprintf(buff, sizeof(buff), "out_altvoltage1_TX_LO_frequency_available");
|
|
|
|
|
|
|
|
if (get_param(DEVICE_PHY, buff, rangeStr))
|
|
|
|
{
|
|
|
|
std::istringstream instream(rangeStr.substr(1, rangeStr.size() - 2));
|
|
|
|
instream >> minLimit >> stepLimit >> maxLimit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
minLimit = DevicePlutoSDR::txLOLowLimitFreq;
|
|
|
|
maxLimit = DevicePlutoSDR::txLOHighLimitFreq;
|
2019-01-02 08:50:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-01 16:42:08 -05:00
|
|
|
void DevicePlutoSDRBox::getbbLPRxRange(uint32_t& minLimit, uint32_t& maxLimit)
|
|
|
|
{
|
|
|
|
// values are returned in Hz of RF (complex channel) bandwidth
|
|
|
|
qint32 stepLimit;
|
|
|
|
std::string rangeStr;
|
|
|
|
|
|
|
|
char buff[50];
|
|
|
|
snprintf(buff, sizeof(buff), "in_voltage_rf_bandwidth_available");
|
|
|
|
|
|
|
|
if (get_param(DEVICE_PHY, buff, rangeStr))
|
|
|
|
{
|
|
|
|
std::istringstream instream(rangeStr.substr(1, rangeStr.size() - 2));
|
|
|
|
instream >> minLimit >> stepLimit >> maxLimit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
minLimit = DevicePlutoSDR::bbLPRxLowLimitFreq;
|
|
|
|
maxLimit = DevicePlutoSDR::bbLPRxHighLimitFreq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DevicePlutoSDRBox::getbbLPTxRange(uint32_t& minLimit, uint32_t& maxLimit)
|
|
|
|
{
|
|
|
|
// values are returned in Hz
|
|
|
|
qint32 stepLimit;
|
|
|
|
std::string rangeStr;
|
|
|
|
|
|
|
|
char buff[50];
|
|
|
|
snprintf(buff, sizeof(buff), "out_voltage_rf_bandwidth_available");
|
|
|
|
|
|
|
|
if (get_param(DEVICE_PHY, buff, rangeStr))
|
|
|
|
{
|
|
|
|
std::istringstream instream(rangeStr.substr(1, rangeStr.size() - 2));
|
|
|
|
instream >> minLimit >> stepLimit >> maxLimit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
minLimit = DevicePlutoSDR::bbLPTxLowLimitFreq;
|
|
|
|
maxLimit = DevicePlutoSDR::bbLPTxHighLimitFreq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-08 21:09:17 -04:00
|
|
|
bool DevicePlutoSDRBox::fetchTemp()
|
|
|
|
{
|
|
|
|
std::string temp_mC_str;
|
|
|
|
|
|
|
|
if (get_param(DEVICE_PHY, "in_temp0_input", temp_mC_str))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
uint32_t temp_mC = boost::lexical_cast<uint32_t>(temp_mC_str);
|
|
|
|
m_temp = temp_mC / 1000.0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast &e)
|
|
|
|
{
|
|
|
|
std::cerr << "PlutoSDRDevice::getTemp: bad conversion to numeric" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DevicePlutoSDRBox::getRateGovernors(std::string& rateGovernors)
|
|
|
|
{
|
|
|
|
return get_param(DEVICE_PHY, "trx_rate_governor", rateGovernors);
|
|
|
|
}
|