SoapySDR support: get and print device parameters applied to input

pull/263/head
f4exb 2018-10-31 12:22:46 +01:00
rodzic ee6a7e4653
commit 9c459ca336
7 zmienionych plików z 637 dodań i 3 usunięć

Wyświetl plik

@ -14,12 +14,18 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <sstream>
#include <iostream>
#include <QDebug>
#include "devicesoapysdrparams.h"
DeviceSoapySDRParams::DeviceSoapySDRParams(SoapySDR::Device *device) :
m_device(device)
{
fillParams();
printParams();
}
DeviceSoapySDRParams::~DeviceSoapySDRParams()
@ -85,3 +91,172 @@ void DeviceSoapySDRParams::fillChannelParams(std::vector<ChannelSetting>& channe
channelSettings.back().m_bandwidthsRanges = m_device->getBandwidthRange(direction, ichan);
}
void DeviceSoapySDRParams::printParams()
{
qDebug() << "DeviceSoapySDRParams::printParams: m_deviceSettingsArgs:\n" << argInfoListToString(m_deviceSettingsArgs).c_str();
int ichan = 0;
for (const auto &it : m_RxChannelsSettings)
{
qDebug() << "DeviceSoapySDRParams::printParams: Rx channel " << ichan;
printChannelParams(it);
ichan++;
}
ichan = 0;
for (const auto &it : m_TxChannelsSettings)
{
qDebug() << "DeviceSoapySDRParams::printParams: Tx channel " << ichan;
printChannelParams(it);
ichan++;
}
}
void DeviceSoapySDRParams::printChannelParams(const ChannelSetting& channelSetting)
{
qDebug() << "DeviceSoapySDRParams::printParams: m_streamSettingsArgs:\n" << argInfoListToString(channelSetting.m_streamSettingsArgs).c_str();
qDebug() << "DeviceSoapySDRParams::printParams:"
<< " m_hasDCAutoCorrection: " << channelSetting.m_hasDCAutoCorrection
<< " m_hasDCOffsetValue: " << channelSetting.m_hasDCOffsetValue
<< " m_hasIQBalanceValue: " << channelSetting.m_hasIQBalanceValue
<< " m_hasFrequencyCorrectionValue: " << channelSetting.m_hasFrequencyCorrectionValue
<< " m_hasAGC: " << channelSetting.m_hasAGC;
qDebug() << "DeviceSoapySDRParams::printParams: m_antennas: " << vectorToString(channelSetting.m_antennas).c_str();
qDebug() << "DeviceSoapySDRParams::printParams: m_gainRange: " << rangeToString(channelSetting.m_gainRange).c_str();
qDebug() << "DeviceSoapySDRParams::printParams: individual gains...";
for (const auto &gainIt : channelSetting.m_gainSettings)
{
qDebug() << "DeviceSoapySDRParams::printParams: m_name: " << gainIt.m_name.c_str();
qDebug() << "DeviceSoapySDRParams::printParams: m_range: " << rangeToString(gainIt.m_range).c_str();
}
qDebug() << "DeviceSoapySDRParams::printParams: tunable elements...";
for (const auto &freqIt : channelSetting.m_frequencySettings)
{
qDebug() << "DeviceSoapySDRParams::printParams: m_name: " << freqIt.m_name.c_str();
qDebug() << "DeviceSoapySDRParams::printParams: m_range (kHz): " << rangeListToString(freqIt.m_ranges, 1e3).c_str();
}
qDebug() << "DeviceSoapySDRParams::printParams: m_frequencySettingsArgs:\n" << argInfoListToString(channelSetting.m_frequencySettingsArgs).c_str();
qDebug() << "DeviceSoapySDRParams::printParams: m_ratesRanges (kHz): " << rangeListToString(channelSetting.m_ratesRanges, 1e3).c_str();
qDebug() << "DeviceSoapySDRParams::printParams: m_bandwidthsRanges (kHz): " << rangeListToString(channelSetting.m_bandwidthsRanges, 1e3).c_str();
}
std::string DeviceSoapySDRParams::argInfoToString(const SoapySDR::ArgInfo &argInfo, const std::string indent)
{
std::stringstream ss;
//name, or use key if missing
std::string name = argInfo.name;
if (argInfo.name.empty()) name = argInfo.key;
ss << indent << " * " << name;
//optional description
std::string desc = argInfo.description;
const std::string replace("\n"+indent+" ");
for (std::size_t pos = 0; (pos=desc.find("\n", pos)) != std::string::npos; pos+=replace.size()) {
desc.replace(pos, 1, replace);
}
if (not desc.empty()) {
ss << " - " << desc << std::endl << indent << " ";
}
//other fields
ss << " [key=" << argInfo.key;
if (not argInfo.units.empty()) {
ss << ", units=" << argInfo.units;
}
if (not argInfo.value.empty()) {
ss << ", default=" << argInfo.value;
}
//type
switch (argInfo.type)
{
case SoapySDR::ArgInfo::BOOL:
ss << ", type=bool";
break;
case SoapySDR::ArgInfo::INT:
ss << ", type=int";
break;
case SoapySDR::ArgInfo::FLOAT:
ss << ", type=float";
break;
case SoapySDR::ArgInfo::STRING:
ss << ", type=string";
break;
}
//optional range/enumeration
if (argInfo.range.minimum() < argInfo.range.maximum()) {
ss << ", range=" << rangeToString(argInfo.range);
}
if (not argInfo.options.empty()) {
ss << ", options=(" << vectorToString(argInfo.options) << ")";
}
ss << "]";
return ss.str();
}
std::string DeviceSoapySDRParams::argInfoListToString(const SoapySDR::ArgInfoList &argInfos)
{
std::stringstream ss;
for (std::size_t i = 0; i < argInfos.size(); i++) {
ss << argInfoToString(argInfos[i]) << std::endl;
}
return ss.str();
}
std::string DeviceSoapySDRParams::rangeToString(const SoapySDR::Range &range)
{
std::stringstream ss;
ss << "[" << range.minimum() << ", " << range.maximum();
if (range.step() != 0.0) {
ss << ", " << range.step();
}
ss << "]";
return ss.str();
}
std::string DeviceSoapySDRParams::rangeListToString(const SoapySDR::RangeList &range, const double scale)
{
const std::size_t MAXRLEN = 10; //for abbreviating long lists
std::stringstream ss;
for (std::size_t i = 0; i < range.size(); i++)
{
if (range.size() >= MAXRLEN and i >= MAXRLEN/2 and i < (range.size()-MAXRLEN/2))
{
if (i == MAXRLEN) ss << ", ...";
continue;
}
if (not ss.str().empty()) {
ss << ", ";
}
if (range[i].minimum() == range[i].maximum()) {
ss << (range[i].minimum()/scale);
} else {
ss << "[" << (range[i].minimum()/scale) << ", " << (range[i].maximum()/scale) << "]";
}
}
return ss.str();
}

Wyświetl plik

@ -18,6 +18,9 @@
#define DEVICES_SOAPYSDR_DEVICESOAPYSDRPARAMS_H_
#include <stdint.h>
#include <string>
#include <vector>
#include <SoapySDR/Device.hpp>
#include "export.h"
@ -68,6 +71,36 @@ public:
private:
void fillParams();
void fillChannelParams(std::vector<ChannelSetting>& channelSettings, int direction, unsigned int ichan);
void printParams();
void printChannelParams(const ChannelSetting& channelSetting);
// Printing functions copied from SoapySDR's SoapySDRProbe.cpp
std::string argInfoToString(const SoapySDR::ArgInfo &argInfo, const std::string indent = " ");
std::string argInfoListToString(const SoapySDR::ArgInfoList &argInfos);
std::string rangeToString(const SoapySDR::Range &range);
std::string rangeListToString(const SoapySDR::RangeList &range, const double scale);
template <typename Type>
std::string vectorToString(const std::vector<Type> &options)
{
std::stringstream ss;
if (options.empty()) {
return "";
}
for (std::size_t i = 0; i < options.size(); i++)
{
if (not ss.str().empty()) {
ss << ", ";
}
ss << options[i];
}
return ss.str();
}
SoapySDR::Device *m_device;
SoapySDR::ArgInfoList m_deviceSettingsArgs; //!< list (vector) of device settings arguments
uint32_t m_nbRx; //!< number of Rx channels

Wyświetl plik

@ -20,6 +20,7 @@
#include <SoapySDR/Device.hpp>
#include "export.h"
#include "devicesoapysdrparams.h"
class SoapySDRInput;
class SoapySDROutput;
@ -34,6 +35,7 @@ public:
~DeviceSoapySDRShared();
SoapySDR::Device *m_device;
DeviceSoapySDRParams *m_deviceParams;
int m_channel; //!< allocated channel (-1 if none)
SoapySDRInput *m_source;
SoapySDROutput *m_sink;

Wyświetl plik

@ -19,7 +19,7 @@ set(soapysdrinput_HEADERS
)
set(soapysdrinput_FORMS
# soapysdrinputgui.ui
soapysdrinputgui.ui
)
if (BUILD_DEBIAN)

Wyświetl plik

@ -32,6 +32,7 @@ SoapySDRInput::SoapySDRInput(DeviceSourceAPI *deviceAPI) :
m_deviceDescription("SoapySDRInput"),
m_running(false)
{
openDevice();
}
SoapySDRInput::~SoapySDRInput()
@ -78,6 +79,7 @@ bool SoapySDRInput::openDevice()
}
m_deviceShared.m_device = device;
m_deviceShared.m_deviceParams = deviceSoapySDRShared->m_deviceParams;
}
// look for Tx buddies and get reference to the device object
else if (m_deviceAPI->getSinkBuddies().size() > 0) // then sink
@ -102,6 +104,7 @@ bool SoapySDRInput::openDevice()
}
m_deviceShared.m_device = device;
m_deviceShared.m_deviceParams = deviceSoapySDRShared->m_deviceParams;
}
// There are no buddies then create the first SoapySDR device
else
@ -115,6 +118,8 @@ bool SoapySDRInput::openDevice()
qCritical("BladeRF2Input::openDevice: cannot open BladeRF2 device");
return false;
}
m_deviceShared.m_deviceParams = new DeviceSoapySDRParams(m_deviceShared.m_device);
}
m_deviceShared.m_channel = m_deviceAPI->getItemIndex(); // publicly allocate channel
@ -140,10 +145,12 @@ void SoapySDRInput::closeDevice()
m_deviceShared.m_channel = -1; // publicly release channel
m_deviceShared.m_source = 0;
// No buddies so effectively close the device
// No buddies so effectively close the device and delete parameters
if ((m_deviceAPI->getSinkBuddies().size() == 0) && (m_deviceAPI->getSourceBuddies().size() == 0))
{
delete m_deviceShared.m_deviceParams;
m_deviceShared.m_deviceParams = 0;
DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance();
deviceSoapySDR.closeSoapySdr(m_deviceShared.m_device);
m_deviceShared.m_device = 0;

Wyświetl plik

@ -20,22 +20,28 @@
#include "device/deviceuiset.h"
#include "util/simpleserializer.h"
#include "ui_soapysdrinputgui.h"
#include "soapysdrinputgui.h"
SoapySDRInputGui::SoapySDRInputGui(DeviceUISet *deviceUISet, QWidget* parent) :
QWidget(parent),
ui(0),
ui(new Ui::SoapySDRInputGui),
m_deviceUISet(deviceUISet),
m_forceSettings(true),
m_doApplySettings(true),
m_sampleSource(0),
m_sampleRate(0),
m_deviceCenterFrequency(0),
m_lastEngineState(DSPDeviceSourceEngine::StNotStarted)
{
m_sampleSource = (SoapySDRInput*) m_deviceUISet->m_deviceSourceAPI->getSampleSource();
ui->setupUi(this);
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
}
SoapySDRInputGui::~SoapySDRInputGui()
{
delete ui;
}
void SoapySDRInputGui::destroy()

Wyświetl plik

@ -0,0 +1,411 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SoapySDRInputGui</class>
<widget class="QWidget" name="SoapySDRInputGui">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>324</width>
<height>276</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>320</width>
<height>132</height>
</size>
</property>
<property name="font">
<font>
<family>Liberation Sans</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="windowTitle">
<string>SoapySDR</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_freq">
<property name="topMargin">
<number>4</number>
</property>
<item>
<layout class="QVBoxLayout" name="deviceUILayout">
<item>
<layout class="QHBoxLayout" name="deviceButtonsLayout">
<item>
<widget class="ButtonSwitch" name="startStop">
<property name="toolTip">
<string>start/stop acquisition</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../sdrgui/resources/res.qrc">
<normaloff>:/play.png</normaloff>
<normalon>:/stop.png</normalon>:/play.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="ButtonSwitch" name="record">
<property name="toolTip">
<string>Toggle record I/Q samples from device</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../sdrgui/resources/res.qrc">
<normaloff>:/record_off.png</normaloff>:/record_off.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="deviceRateLayout">
<item>
<widget class="QLabel" name="deviceRateText">
<property name="toolTip">
<string>I/Q sample rate kS/s</string>
</property>
<property name="text">
<string>00000k</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="freqLeftSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="ValueDial" name="centerFrequency" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>16</height>
</size>
</property>
<property name="font">
<font>
<family>Liberation Mono</family>
<pointsize>20</pointsize>
</font>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="toolTip">
<string>Tuner center frequency in kHz</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="freqUnits">
<property name="text">
<string> kHz</string>
</property>
</widget>
</item>
<item>
<spacer name="freqRightlSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_freq">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>304</width>
<height>128</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Data1</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<item>
<property name="text">
<string>0</string>
</property>
</item>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Kiki</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>0.0</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Zozo</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_2"/>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Didi</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_3"/>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="paddingLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ValueDial</class>
<extends>QWidget</extends>
<header>gui/valuedial.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ButtonSwitch</class>
<extends>QToolButton</extends>
<header>gui/buttonswitch.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../../sdrgui/resources/res.qrc"/>
</resources>
<connections/>
</ui>