1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-01 21:54:55 -04:00

BladeRF Tx support: rename more Rx files and cmake items

This commit is contained in:
f4exb
2016-12-27 03:11:57 +01:00
parent da53b153ab
commit 7ef54cc2e0
14 changed files with 29 additions and 22 deletions
@@ -0,0 +1,68 @@
project(bladerfinput)
set(bladerfinput_SOURCES
bladerfinputgui.cpp
bladerfinput.cpp
bladerfinputplugin.cpp
bladerfinputsettings.cpp
bladerfinputthread.cpp
)
set(bladerfinput_HEADERS
bladerfinputgui.h
bladerfinput.h
bladerfinputplugin.h
bladerfinputsettings.h
bladerfinputthread.h
)
set(bladerfinput_FORMS
bladerfinputgui.ui
)
if (BUILD_DEBIAN)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${LIBBLADERFLIBSRC}/include
${LIBBLADERFLIBSRC}/src
)
else (BUILD_DEBIAN)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${LIBBLADERF_INCLUDE_DIR}
)
endif (BUILD_DEBIAN)
#include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_PLUGIN)
add_definitions(-DQT_SHARED)
#qt4_wrap_cpp(bladerfinput_HEADERS_MOC ${bladerfinput_HEADERS})
qt5_wrap_ui(bladerfinput_FORMS_HEADERS ${bladerfinput_FORMS})
add_library(inputbladerf SHARED
${bladerfinput_SOURCES}
${bladerfinput_HEADERS_MOC}
${bladerfinput_FORMS_HEADERS}
)
if (BUILD_DEBIAN)
target_link_libraries(inputbladerf
${QT_LIBRARIES}
bladerf
sdrbase
)
else (BUILD_DEBIAN)
target_link_libraries(inputbladerf
${QT_LIBRARIES}
${LIBBLADERF_LIBRARIES}
sdrbase
)
endif (BUILD_DEBIAN)
qt5_use_modules(inputbladerf Core Widgets)
install(TARGETS inputbladerf DESTINATION lib/plugins/samplesource)
@@ -0,0 +1,487 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 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 //
// //
// 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 "../bladerfinput/bladerfinput.h"
#include <string.h>
#include <errno.h>
#include <QDebug>
#include "util/simpleserializer.h"
#include "dsp/dspcommands.h"
#include "dsp/dspengine.h"
#include <device/devicesourceapi.h>
#include "../bladerfinput/bladerfinputgui.h"
#include "../bladerfinput/bladerfinputthread.h"
MESSAGE_CLASS_DEFINITION(BladerfInput::MsgConfigureBladerf, Message)
MESSAGE_CLASS_DEFINITION(BladerfInput::MsgReportBladerf, Message)
BladerfInput::BladerfInput(DeviceSourceAPI *deviceAPI) :
m_deviceAPI(deviceAPI),
m_settings(),
m_dev(0),
m_bladerfThread(0),
m_deviceDescription("BladeRF")
{
}
BladerfInput::~BladerfInput()
{
stop();
}
bool BladerfInput::init(const Message& cmd)
{
return false;
}
bool BladerfInput::start(int device)
{
QMutexLocker mutexLocker(&m_mutex);
if (m_dev != 0)
{
stop();
}
int res;
int fpga_loaded;
if (!m_sampleFifo.setSize(96000 * 4))
{
qCritical("Could not allocate SampleFifo");
return false;
}
if ((m_dev = open_bladerf_from_serial(0)) == 0) // TODO: fix; Open first available device as there is no proper handling for multiple devices
{
qCritical("could not open BladeRF");
return false;
}
fpga_loaded = bladerf_is_fpga_configured(m_dev);
if (fpga_loaded < 0)
{
qCritical("Failed to check FPGA state: %s",
bladerf_strerror(fpga_loaded));
return false;
}
else if (fpga_loaded == 0)
{
qCritical("The device's FPGA is not loaded.");
return false;
}
// TODO: adjust USB transfer data according to sample rate
if ((res = bladerf_sync_config(m_dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0)
{
qCritical("bladerf_sync_config with return code %d", res);
goto failed;
}
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_RX, true)) < 0)
{
qCritical("bladerf_enable_module with return code %d", res);
goto failed;
}
if((m_bladerfThread = new BladerfInputThread(m_dev, &m_sampleFifo)) == NULL) {
qFatal("out of memory");
goto failed;
}
m_bladerfThread->startWork();
mutexLocker.unlock();
applySettings(m_settings, true);
qDebug("BladerfInput::startInput: started");
return true;
failed:
stop();
return false;
}
void BladerfInput::stop()
{
QMutexLocker mutexLocker(&m_mutex);
if(m_bladerfThread != 0)
{
m_bladerfThread->stopWork();
delete m_bladerfThread;
m_bladerfThread = 0;
}
if(m_dev != 0)
{
bladerf_close(m_dev);
m_dev = 0;
}
}
const QString& BladerfInput::getDeviceDescription() const
{
return m_deviceDescription;
}
int BladerfInput::getSampleRate() const
{
int rate = m_settings.m_devSampleRate;
return (rate / (1<<m_settings.m_log2Decim));
}
quint64 BladerfInput::getCenterFrequency() const
{
return m_settings.m_centerFrequency;
}
bool BladerfInput::handleMessage(const Message& message)
{
if (MsgConfigureBladerf::match(message))
{
MsgConfigureBladerf& conf = (MsgConfigureBladerf&) message;
qDebug() << "BladerfInput::handleMessage: MsgConfigureBladerf";
if (!applySettings(conf.getSettings(), false))
{
qDebug("BladeRF config error");
}
return true;
}
else
{
return false;
}
}
bool BladerfInput::applySettings(const BladeRFInputSettings& settings, bool force)
{
bool forwardChange = false;
QMutexLocker mutexLocker(&m_mutex);
qDebug() << "BladerfInput::applySettings: m_dev: " << m_dev;
if (m_settings.m_dcBlock != settings.m_dcBlock)
{
m_settings.m_dcBlock = settings.m_dcBlock;
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqCorrection);
}
if (m_settings.m_iqCorrection != settings.m_iqCorrection)
{
m_settings.m_iqCorrection = settings.m_iqCorrection;
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqCorrection);
}
if ((m_settings.m_lnaGain != settings.m_lnaGain) || force)
{
m_settings.m_lnaGain = settings.m_lnaGain;
if (m_dev != 0)
{
if(bladerf_set_lna_gain(m_dev, getLnaGain(m_settings.m_lnaGain)) != 0)
{
qDebug("bladerf_set_lna_gain() failed");
}
else
{
qDebug() << "BladerfInput: LNA gain set to " << getLnaGain(m_settings.m_lnaGain);
}
}
}
if ((m_settings.m_vga1 != settings.m_vga1) || force)
{
m_settings.m_vga1 = settings.m_vga1;
if (m_dev != 0)
{
if(bladerf_set_rxvga1(m_dev, m_settings.m_vga1) != 0)
{
qDebug("bladerf_set_rxvga1() failed");
}
else
{
qDebug() << "BladerfInput: VGA1 gain set to " << m_settings.m_vga1;
}
}
}
if ((m_settings.m_vga2 != settings.m_vga2) || force)
{
m_settings.m_vga2 = settings.m_vga2;
if(m_dev != 0)
{
if(bladerf_set_rxvga2(m_dev, m_settings.m_vga2) != 0)
{
qDebug("bladerf_set_rxvga2() failed");
}
else
{
qDebug() << "BladerfInput: VGA2 gain set to " << m_settings.m_vga2;
}
}
}
if ((m_settings.m_xb200 != settings.m_xb200) || force)
{
m_settings.m_xb200 = settings.m_xb200;
if (m_dev != 0)
{
if (m_settings.m_xb200)
{
if (bladerf_expansion_attach(m_dev, BLADERF_XB_200) != 0)
{
qDebug("bladerf_expansion_attach(xb200) failed");
}
else
{
qDebug() << "BladerfInput: Attach XB200";
}
}
else
{
if (bladerf_expansion_attach(m_dev, BLADERF_XB_NONE) != 0)
{
qDebug("bladerf_expansion_attach(none) failed");
}
else
{
qDebug() << "BladerfInput: Detach XB200";
}
}
}
}
if ((m_settings.m_xb200Path != settings.m_xb200Path) || force)
{
m_settings.m_xb200Path = settings.m_xb200Path;
if (m_dev != 0)
{
if(bladerf_xb200_set_path(m_dev, BLADERF_MODULE_RX, m_settings.m_xb200Path) != 0)
{
qDebug("bladerf_xb200_set_path(BLADERF_MODULE_RX) failed");
}
else
{
qDebug() << "BladerfInput: set xb200 path to " << m_settings.m_xb200Path;
}
}
}
if ((m_settings.m_xb200Filter != settings.m_xb200Filter) || force)
{
m_settings.m_xb200Filter = settings.m_xb200Filter;
if (m_dev != 0)
{
if(bladerf_xb200_set_filterbank(m_dev, BLADERF_MODULE_RX, m_settings.m_xb200Filter) != 0)
{
qDebug("bladerf_xb200_set_filterbank(BLADERF_MODULE_RX) failed");
}
else
{
qDebug() << "BladerfInput: set xb200 filter to " << m_settings.m_xb200Filter;
}
}
}
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force)
{
m_settings.m_devSampleRate = settings.m_devSampleRate;
forwardChange = true;
if (m_dev != 0)
{
unsigned int actualSamplerate;
if (bladerf_set_sample_rate(m_dev, BLADERF_MODULE_RX, m_settings.m_devSampleRate, &actualSamplerate) < 0)
{
qCritical("could not set sample rate: %d", m_settings.m_devSampleRate);
}
else
{
qDebug() << "bladerf_set_sample_rate(BLADERF_MODULE_RX) actual sample rate is " << actualSamplerate;
}
}
}
if ((m_settings.m_bandwidth != settings.m_bandwidth) || force)
{
m_settings.m_bandwidth = settings.m_bandwidth;
if(m_dev != 0)
{
unsigned int actualBandwidth;
if( bladerf_set_bandwidth(m_dev, BLADERF_MODULE_RX, m_settings.m_bandwidth, &actualBandwidth) < 0)
{
qCritical("could not set bandwidth: %d", m_settings.m_bandwidth);
}
else
{
qDebug() << "bladerf_set_bandwidth(BLADERF_MODULE_RX) actual bandwidth is " << actualBandwidth;
}
}
}
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
{
m_settings.m_log2Decim = settings.m_log2Decim;
forwardChange = true;
if(m_dev != 0)
{
m_bladerfThread->setLog2Decimation(m_settings.m_log2Decim);
qDebug() << "BladerfInput: set decimation to " << (1<<m_settings.m_log2Decim);
}
}
if ((m_settings.m_fcPos != settings.m_fcPos) || force)
{
m_settings.m_fcPos = settings.m_fcPos;
if(m_dev != 0)
{
m_bladerfThread->setFcPos((int) m_settings.m_fcPos);
qDebug() << "BladerfInput: set fc pos (enum) to " << (int) m_settings.m_fcPos;
}
}
if (m_settings.m_centerFrequency != settings.m_centerFrequency)
{
forwardChange = true;
}
m_settings.m_centerFrequency = settings.m_centerFrequency;
qint64 deviceCenterFrequency = m_settings.m_centerFrequency;
qint64 f_img = deviceCenterFrequency;
qint64 f_cut = deviceCenterFrequency + m_settings.m_bandwidth/2;
if ((m_settings.m_log2Decim == 0) || (m_settings.m_fcPos == BladeRFInputSettings::FC_POS_CENTER))
{
deviceCenterFrequency = m_settings.m_centerFrequency;
f_img = deviceCenterFrequency;
f_cut = deviceCenterFrequency + m_settings.m_bandwidth/2;
}
else
{
if (m_settings.m_fcPos == BladeRFInputSettings::FC_POS_INFRA)
{
deviceCenterFrequency = m_settings.m_centerFrequency + (m_settings.m_devSampleRate / 4);
f_img = deviceCenterFrequency + m_settings.m_devSampleRate/2;
f_cut = deviceCenterFrequency + m_settings.m_bandwidth/2;
}
else if (m_settings.m_fcPos == BladeRFInputSettings::FC_POS_SUPRA)
{
deviceCenterFrequency = m_settings.m_centerFrequency - (m_settings.m_devSampleRate / 4);
f_img = deviceCenterFrequency - m_settings.m_devSampleRate/2;
f_cut = deviceCenterFrequency - m_settings.m_bandwidth/2;
}
}
if (m_dev != NULL)
{
if (bladerf_set_frequency( m_dev, BLADERF_MODULE_RX, deviceCenterFrequency ) != 0)
{
qDebug("bladerf_set_frequency(%lld) failed", m_settings.m_centerFrequency);
}
}
if (forwardChange)
{
int sampleRate = m_settings.m_devSampleRate/(1<<m_settings.m_log2Decim);
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency);
m_deviceAPI->getDeviceInputMessageQueue()->push(notif);
}
qDebug() << "BladerfInput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz"
<< " device center freq: " << deviceCenterFrequency << " Hz"
<< " device sample rate: " << m_settings.m_devSampleRate << "Hz"
<< " Actual sample rate: " << m_settings.m_devSampleRate/(1<<m_settings.m_log2Decim) << "Hz"
<< " BW: " << m_settings.m_bandwidth << "Hz"
<< " img: " << f_img << "Hz"
<< " cut: " << f_cut << "Hz"
<< " img - cut: " << f_img - f_cut;
return true;
}
bladerf_lna_gain BladerfInput::getLnaGain(int lnaGain)
{
if (lnaGain == 2)
{
return BLADERF_LNA_GAIN_MAX;
}
else if (lnaGain == 1)
{
return BLADERF_LNA_GAIN_MID;
}
else
{
return BLADERF_LNA_GAIN_BYPASS;
}
}
struct bladerf *BladerfInput::open_bladerf_from_serial(const char *serial)
{
int status;
struct bladerf *dev;
struct bladerf_devinfo info;
/* Initialize all fields to "don't care" wildcard values.
*
* Immediately passing this to bladerf_open_with_devinfo() would cause
* libbladeRF to open any device on any available backend. */
bladerf_init_devinfo(&info);
/* Specify the desired device's serial number, while leaving all other
* fields in the info structure wildcard values */
if (serial != NULL)
{
strncpy(info.serial, serial, BLADERF_SERIAL_LENGTH - 1);
info.serial[BLADERF_SERIAL_LENGTH - 1] = '\0';
}
status = bladerf_open_with_devinfo(&dev, &info);
if (status == BLADERF_ERR_NODEV)
{
fprintf(stderr, "No devices available with serial=%s\n", serial);
return NULL;
}
else if (status != 0)
{
fprintf(stderr, "Failed to open device with serial=%s (%s)\n",
serial, bladerf_strerror(status));
return NULL;
}
else
{
return dev;
}
}
@@ -0,0 +1,95 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 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 //
// //
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_BLADERFINPUT_H
#define INCLUDE_BLADERFINPUT_H
#include <dsp/devicesamplesource.h>
#include <libbladeRF.h>
#include <QString>
#include "../bladerfinput/bladerfinputsettings.h"
class DeviceSourceAPI;
class BladerfInputThread;
class BladerfInput : public DeviceSampleSource {
public:
class MsgConfigureBladerf : public Message {
MESSAGE_CLASS_DECLARATION
public:
const BladeRFInputSettings& getSettings() const { return m_settings; }
static MsgConfigureBladerf* create(const BladeRFInputSettings& settings)
{
return new MsgConfigureBladerf(settings);
}
private:
BladeRFInputSettings m_settings;
MsgConfigureBladerf(const BladeRFInputSettings& settings) :
Message(),
m_settings(settings)
{ }
};
class MsgReportBladerf : public Message {
MESSAGE_CLASS_DECLARATION
public:
static MsgReportBladerf* create()
{
return new MsgReportBladerf();
}
protected:
MsgReportBladerf() :
Message()
{ }
};
BladerfInput(DeviceSourceAPI *deviceAPI);
virtual ~BladerfInput();
virtual bool init(const Message& message);
virtual bool start(int device);
virtual void stop();
virtual const QString& getDeviceDescription() const;
virtual int getSampleRate() const;
virtual quint64 getCenterFrequency() const;
virtual bool handleMessage(const Message& message);
private:
bool applySettings(const BladeRFInputSettings& settings, bool force);
bladerf_lna_gain getLnaGain(int lnaGain);
struct bladerf *open_bladerf_from_serial(const char *serial);
DeviceSourceAPI *m_deviceAPI;
QMutex m_mutex;
BladeRFInputSettings m_settings;
struct bladerf* m_dev;
BladerfInputThread* m_bladerfThread;
QString m_deviceDescription;
};
#endif // INCLUDE_BLADERFINPUT_H
@@ -0,0 +1,45 @@
#--------------------------------------------
#
# Pro file for Windows builds with Qt Creator
#
#--------------------------------------------
TEMPLATE = lib
CONFIG += plugin
QT += core gui widgets multimedia opengl
TARGET = inputbladerf
DEFINES += USE_SSE2=1
QMAKE_CXXFLAGS += -msse2
DEFINES += USE_SSE4_1=1
QMAKE_CXXFLAGS += -msse4.1
CONFIG(MINGW32):LIBBLADERFSRC = "D:\softs\bladeRF\host\libraries\libbladeRF\include"
CONFIG(MINGW64):LIBBLADERFSRC = "D:\softs\bladeRF\host\libraries\libbladeRF\include"
INCLUDEPATH += $$PWD
INCLUDEPATH += ../../../sdrbase
INCLUDEPATH += $$LIBBLADERFSRC
CONFIG(Release):build_subdir = release
CONFIG(Debug):build_subdir = debug
SOURCES += bladerfinputgui.cpp\
bladerfinput.cpp\
bladerfinputplugin.cpp\
bladerfinputsettings.cpp\
bladerfinputthread.cpp
HEADERS += bladerfinputgui.h\
bladerfinput.h\
bladerfinputplugin.h\
bladerfinputsettings.h\
bladerfinputthread.h
FORMS += bladerfinputgui.ui
LIBS += -L../../../sdrbase/$${build_subdir} -lsdrbase
LIBS += -L../../../libbladerf/$${build_subdir} -llibbladerf
RESOURCES = ../../../sdrbase/resources/res.qrc
@@ -0,0 +1,533 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 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 //
// //
// 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 "../bladerfinput/bladerfinputgui.h"
#include <QDebug>
#include <QMessageBox>
#include <libbladeRF.h>
#include "ui_bladerfinputgui.h"
#include "gui/colormapper.h"
#include "gui/glspectrum.h"
#include "dsp/dspengine.h"
#include "dsp/dspcommands.h"
#include <device/devicesourceapi.h>
#include <dsp/filerecord.h>
BladerfInputGui::BladerfInputGui(DeviceSourceAPI *deviceAPI, QWidget* parent) :
QWidget(parent),
ui(new Ui::BladerfInputGui),
m_deviceAPI(deviceAPI),
m_settings(),
m_sampleSource(NULL),
m_sampleRate(0),
m_lastEngineState((DSPDeviceSourceEngine::State)-1)
{
ui->setupUi(this);
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
ui->centerFrequency->setValueRange(7, BLADERF_FREQUENCY_MIN_XB200/1000, BLADERF_FREQUENCY_MAX/1000);
ui->samplerate->clear();
for (int i = 0; i < BladerfSampleRates::getNbRates(); i++)
{
ui->samplerate->addItem(QString::number(BladerfSampleRates::getRate(i)));
}
ui->bandwidth->clear();
for (int i = 0; i < BladerfBandwidths::getNbBandwidths(); i++)
{
ui->bandwidth->addItem(QString::number(BladerfBandwidths::getBandwidth(i)));
}
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
m_statusTimer.start(500);
displaySettings();
m_sampleSource = new BladerfInput(m_deviceAPI);
m_deviceAPI->setSource(m_sampleSource);
char recFileNameCStr[30];
sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID());
m_fileSink = new FileRecord(std::string(recFileNameCStr));
m_deviceAPI->addSink(m_fileSink);
connect(m_deviceAPI->getDeviceOutputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleDSPMessages()), Qt::QueuedConnection);
}
BladerfInputGui::~BladerfInputGui()
{
m_deviceAPI->removeSink(m_fileSink);
delete m_fileSink;
delete m_sampleSource; // Valgrind memcheck
delete ui;
}
void BladerfInputGui::destroy()
{
delete this;
}
void BladerfInputGui::setName(const QString& name)
{
setObjectName(name);
}
QString BladerfInputGui::getName() const
{
return objectName();
}
void BladerfInputGui::resetToDefaults()
{
m_settings.resetToDefaults();
displaySettings();
sendSettings();
}
qint64 BladerfInputGui::getCenterFrequency() const
{
return m_settings.m_centerFrequency;
}
void BladerfInputGui::setCenterFrequency(qint64 centerFrequency)
{
m_settings.m_centerFrequency = centerFrequency;
displaySettings();
sendSettings();
}
QByteArray BladerfInputGui::serialize() const
{
return m_settings.serialize();
}
bool BladerfInputGui::deserialize(const QByteArray& data)
{
if(m_settings.deserialize(data)) {
displaySettings();
sendSettings();
return true;
} else {
resetToDefaults();
return false;
}
}
bool BladerfInputGui::handleMessage(const Message& message)
{
if (BladerfInput::MsgReportBladerf::match(message))
{
displaySettings();
return true;
}
else
{
return false;
}
}
void BladerfInputGui::handleDSPMessages()
{
Message* message;
while ((message = m_deviceAPI->getDeviceOutputMessageQueue()->pop()) != 0)
{
qDebug("BladerfGui::handleDSPMessages: message: %s", message->getIdentifier());
if (DSPSignalNotification::match(*message))
{
DSPSignalNotification* notif = (DSPSignalNotification*) message;
m_sampleRate = notif->getSampleRate();
m_deviceCenterFrequency = notif->getCenterFrequency();
qDebug("BladerfGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
updateSampleRateAndFrequency();
m_fileSink->handleMessage(*notif); // forward to file sink
delete message;
}
}
}
void BladerfInputGui::updateSampleRateAndFrequency()
{
m_deviceAPI->getSpectrum()->setSampleRate(m_sampleRate);
m_deviceAPI->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency);
ui->deviceRateLabel->setText(tr("%1k").arg((float)m_sampleRate / 1000));
}
void BladerfInputGui::displaySettings()
{
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
ui->dcOffset->setChecked(m_settings.m_dcBlock);
ui->iqImbalance->setChecked(m_settings.m_iqCorrection);
unsigned int sampleRateIndex = BladerfSampleRates::getRateIndex(m_settings.m_devSampleRate);
ui->samplerate->setCurrentIndex(sampleRateIndex);
unsigned int bandwidthIndex = BladerfBandwidths::getBandwidthIndex(m_settings.m_bandwidth);
ui->bandwidth->setCurrentIndex(bandwidthIndex);
ui->decim->setCurrentIndex(m_settings.m_log2Decim);
ui->fcPos->setCurrentIndex((int) m_settings.m_fcPos);
ui->lna->setCurrentIndex(m_settings.m_lnaGain);
ui->vga1Text->setText(tr("%1dB").arg(m_settings.m_vga1));
ui->vga1->setValue(m_settings.m_vga1);
ui->vga2Text->setText(tr("%1dB").arg(m_settings.m_vga2));
ui->vga2->setValue(m_settings.m_vga2);
ui->xb200->setCurrentIndex(getXb200Index(m_settings.m_xb200, m_settings.m_xb200Path, m_settings.m_xb200Filter));
}
void BladerfInputGui::sendSettings()
{
if(!m_updateTimer.isActive())
m_updateTimer.start(100);
}
void BladerfInputGui::on_centerFrequency_changed(quint64 value)
{
m_settings.m_centerFrequency = value * 1000;
sendSettings();
}
void BladerfInputGui::on_dcOffset_toggled(bool checked)
{
m_settings.m_dcBlock = checked;
sendSettings();
}
void BladerfInputGui::on_iqImbalance_toggled(bool checked)
{
m_settings.m_iqCorrection = checked;
sendSettings();
}
void BladerfInputGui::on_samplerate_currentIndexChanged(int index)
{
int newrate = BladerfSampleRates::getRate(index);
m_settings.m_devSampleRate = newrate * 1000;
sendSettings();
}
void BladerfInputGui::on_bandwidth_currentIndexChanged(int index)
{
int newbw = BladerfBandwidths::getBandwidth(index);
m_settings.m_bandwidth = newbw * 1000;
sendSettings();
}
void BladerfInputGui::on_decim_currentIndexChanged(int index)
{
if ((index <0) || (index > 5))
return;
m_settings.m_log2Decim = index;
sendSettings();
}
void BladerfInputGui::on_fcPos_currentIndexChanged(int index)
{
if (index == 0) {
m_settings.m_fcPos = BladeRFInputSettings::FC_POS_INFRA;
sendSettings();
} else if (index == 1) {
m_settings.m_fcPos = BladeRFInputSettings::FC_POS_SUPRA;
sendSettings();
} else if (index == 2) {
m_settings.m_fcPos = BladeRFInputSettings::FC_POS_CENTER;
sendSettings();
}
}
void BladerfInputGui::on_lna_currentIndexChanged(int index)
{
qDebug() << "BladerfGui: LNA gain = " << index * 3 << " dB";
if ((index < 0) || (index > 2))
return;
m_settings.m_lnaGain = index;
sendSettings();
}
void BladerfInputGui::on_vga1_valueChanged(int value)
{
if ((value < BLADERF_RXVGA1_GAIN_MIN) || (value > BLADERF_RXVGA1_GAIN_MAX))
return;
ui->vga1Text->setText(tr("%1dB").arg(value));
m_settings.m_vga1 = value;
sendSettings();
}
void BladerfInputGui::on_vga2_valueChanged(int value)
{
if ((value < BLADERF_RXVGA2_GAIN_MIN) || (value > BLADERF_RXVGA2_GAIN_MAX))
return;
ui->vga2Text->setText(tr("%1dB").arg(value));
m_settings.m_vga2 = value;
sendSettings();
}
void BladerfInputGui::on_xb200_currentIndexChanged(int index)
{
if (index == 1) // bypass
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_BYPASS;
}
else if (index == 2) // Auto 1dB
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_MIX;
m_settings.m_xb200Filter = BLADERF_XB200_AUTO_1DB;
}
else if (index == 3) // Auto 3dB
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_MIX;
m_settings.m_xb200Filter = BLADERF_XB200_AUTO_3DB;
}
else if (index == 4) // Custom
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_MIX;
m_settings.m_xb200Filter = BLADERF_XB200_CUSTOM;
}
else if (index == 5) // 50 MHz
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_MIX;
m_settings.m_xb200Filter = BLADERF_XB200_50M;
}
else if (index == 6) // 144 MHz
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_MIX;
m_settings.m_xb200Filter = BLADERF_XB200_144M;
}
else if (index == 7) // 222 MHz
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_MIX;
m_settings.m_xb200Filter = BLADERF_XB200_222M;
}
else // no xb200
{
m_settings.m_xb200 = false;
}
if (m_settings.m_xb200)
{
ui->centerFrequency->setValueRange(7, BLADERF_FREQUENCY_MIN_XB200/1000, BLADERF_FREQUENCY_MAX/1000);
}
else
{
ui->centerFrequency->setValueRange(7, BLADERF_FREQUENCY_MIN/1000, BLADERF_FREQUENCY_MAX/1000);
}
sendSettings();
}
void BladerfInputGui::on_startStop_toggled(bool checked)
{
if (checked)
{
if (m_deviceAPI->initAcquisition())
{
m_deviceAPI->startAcquisition();
DSPEngine::instance()->startAudioOutput();
}
}
else
{
m_deviceAPI->stopAcquisition();
DSPEngine::instance()->stopAudioOutput();
}
}
void BladerfInputGui::on_record_toggled(bool checked)
{
if (checked)
{
ui->record->setStyleSheet("QToolButton { background-color : red; }");
m_fileSink->startRecording();
}
else
{
ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
m_fileSink->stopRecording();
}
}
void BladerfInputGui::updateHardware()
{
qDebug() << "BladerfGui::updateHardware";
BladerfInput::MsgConfigureBladerf* message = BladerfInput::MsgConfigureBladerf::create( m_settings);
m_sampleSource->getInputMessageQueue()->push(message);
m_updateTimer.stop();
}
void BladerfInputGui::updateStatus()
{
int state = m_deviceAPI->state();
if(m_lastEngineState != state)
{
switch(state)
{
case DSPDeviceSourceEngine::StNotStarted:
ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
break;
case DSPDeviceSourceEngine::StIdle:
ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
break;
case DSPDeviceSourceEngine::StRunning:
ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
break;
case DSPDeviceSourceEngine::StError:
ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
QMessageBox::information(this, tr("Message"), m_deviceAPI->errorMessage());
break;
default:
break;
}
m_lastEngineState = state;
}
}
unsigned int BladerfInputGui::getXb200Index(bool xb_200, bladerf_xb200_path xb200Path, bladerf_xb200_filter xb200Filter)
{
if (xb_200)
{
if (xb200Path == BLADERF_XB200_BYPASS)
{
return 1;
}
else
{
if (xb200Filter == BLADERF_XB200_AUTO_1DB)
{
return 2;
}
else if (xb200Filter == BLADERF_XB200_AUTO_3DB)
{
return 3;
}
else if (xb200Filter == BLADERF_XB200_CUSTOM)
{
return 4;
}
else if (xb200Filter == BLADERF_XB200_50M)
{
return 5;
}
else if (xb200Filter == BLADERF_XB200_144M)
{
return 6;
}
else if (xb200Filter == BLADERF_XB200_222M)
{
return 7;
}
else
{
return 0;
}
}
}
else
{
return 0;
}
}
unsigned int BladerfSampleRates::m_rates[] = {1536, 1600, 2000, 2304, 2400, 3072, 3200, 4608, 4800, 6144, 7680, 9216, 9600, 10752, 12288, 18432, 19200, 24576, 30720, 36864, 39936};
unsigned int BladerfSampleRates::m_nb_rates = 21;
unsigned int BladerfSampleRates::getRate(unsigned int rate_index)
{
if (rate_index < m_nb_rates)
{
return m_rates[rate_index];
}
else
{
return m_rates[0];
}
}
unsigned int BladerfSampleRates::getRateIndex(unsigned int rate)
{
for (unsigned int i=0; i < m_nb_rates; i++)
{
if (rate/1000 == m_rates[i])
{
return i;
}
}
return 0;
}
unsigned int BladerfSampleRates::getNbRates()
{
return BladerfSampleRates::m_nb_rates;
}
unsigned int BladerfBandwidths::m_halfbw[] = {750, 875, 1250, 1375, 1500, 1920, 2500, 2750, 3000, 3500, 4375, 5000, 6000, 7000, 10000, 14000};
unsigned int BladerfBandwidths::m_nb_halfbw = 16;
unsigned int BladerfBandwidths::getBandwidth(unsigned int bandwidth_index)
{
if (bandwidth_index < m_nb_halfbw)
{
return m_halfbw[bandwidth_index] * 2;
}
else
{
return m_halfbw[0] * 2;
}
}
unsigned int BladerfBandwidths::getBandwidthIndex(unsigned int bandwidth)
{
for (unsigned int i=0; i < m_nb_halfbw; i++)
{
if (bandwidth/2000 == m_halfbw[i])
{
return i;
}
}
return 0;
}
unsigned int BladerfBandwidths::getNbBandwidths()
{
return BladerfBandwidths::m_nb_halfbw;
}
@@ -0,0 +1,109 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 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 //
// //
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_BLADERFINPUTGUI_H
#define INCLUDE_BLADERFINPUTGUI_H
#include <QTimer>
#include "plugin/plugingui.h"
#include "../bladerfinput/bladerfinput.h"
class DeviceSourceAPI;
class FileRecord;
namespace Ui {
class BladerfInputGui;
class BladerfSampleRates;
}
class BladerfInputGui : public QWidget, public PluginGUI {
Q_OBJECT
public:
explicit BladerfInputGui(DeviceSourceAPI *deviceAPI, QWidget* parent = NULL);
virtual ~BladerfInputGui();
void destroy();
void setName(const QString& name);
QString getName() const;
void resetToDefaults();
virtual qint64 getCenterFrequency() const;
virtual void setCenterFrequency(qint64 centerFrequency);
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
virtual bool handleMessage(const Message& message);
private:
Ui::BladerfInputGui* ui;
DeviceSourceAPI* m_deviceAPI;
BladeRFInputSettings m_settings;
QTimer m_updateTimer;
QTimer m_statusTimer;
std::vector<int> m_gains;
DeviceSampleSource* m_sampleSource;
FileRecord *m_fileSink; //!< File sink to record device I/Q output
int m_sampleRate;
quint64 m_deviceCenterFrequency; //!< Center frequency in device
int m_lastEngineState;
void displaySettings();
void sendSettings();
unsigned int getXb200Index(bool xb_200, bladerf_xb200_path xb200Path, bladerf_xb200_filter xb200Filter);
void updateSampleRateAndFrequency();
private slots:
void handleDSPMessages();
void on_centerFrequency_changed(quint64 value);
void on_dcOffset_toggled(bool checked);
void on_iqImbalance_toggled(bool checked);
void on_samplerate_currentIndexChanged(int index);
void on_bandwidth_currentIndexChanged(int index);
void on_decim_currentIndexChanged(int index);
void on_lna_currentIndexChanged(int index);
void on_vga1_valueChanged(int value);
void on_vga2_valueChanged(int value);
void on_xb200_currentIndexChanged(int index);
void on_fcPos_currentIndexChanged(int index);
void on_startStop_toggled(bool checked);
void on_record_toggled(bool checked);
void updateHardware();
void updateStatus();
};
class BladerfSampleRates {
public:
static unsigned int getRate(unsigned int rate_index);
static unsigned int getRateIndex(unsigned int rate);
static unsigned int getNbRates();
private:
static unsigned int m_rates[21];
static unsigned int m_nb_rates;
};
class BladerfBandwidths {
public:
static unsigned int getBandwidth(unsigned int bandwidth_index);
static unsigned int getBandwidthIndex(unsigned int bandwidth);
static unsigned int getNbBandwidths();
private:
static unsigned int m_halfbw[16];
static unsigned int m_nb_halfbw;
};
#endif // INCLUDE_BLADERFINPUTGUI_H
@@ -0,0 +1,705 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BladerfInputGui</class>
<widget class="QWidget" name="BladerfInputGui">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>259</width>
<height>210</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>210</height>
</size>
</property>
<property name="font">
<font>
<family>Sans Serif</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="windowTitle">
<string>BladeRF</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="margin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_freq">
<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="../../../sdrbase/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="../../../sdrbase/resources/res.qrc">
<normaloff>:/record_off.png</normaloff>
<normalon>:/record_on.png</normalon>:/record_off.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="deviceRateLayout">
<item>
<widget class="QLabel" name="deviceRateLabel">
<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>Monospace</family>
<pointsize>20</pointsize>
</font>
</property>
<property name="cursor">
<cursorShape>SizeVerCursor</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">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_corr">
<item row="0" column="2">
<widget class="ButtonSwitch" name="iqImbalance">
<property name="toolTip">
<string>Automatic IQ imbalance correction</string>
</property>
<property name="text">
<string>IQ</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="ButtonSwitch" name="dcOffset">
<property name="toolTip">
<string>Automatic DC offset removal</string>
</property>
<property name="text">
<string>DC</string>
</property>
</widget>
</item>
<item row="0" column="3">
<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>
<item row="0" column="0">
<widget class="QLabel" name="corrLabel">
<property name="text">
<string>Auto</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="xb200Label">
<property name="text">
<string>xb200</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QComboBox" name="xb200">
<property name="toolTip">
<string>XB200 board mode</string>
</property>
<property name="currentText" stdset="0">
<string>None</string>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<property name="maxVisibleItems">
<number>5</number>
</property>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Bypass</string>
</property>
</item>
<item>
<property name="text">
<string>Auto 1dB</string>
</property>
</item>
<item>
<property name="text">
<string>Auto 3dB</string>
</property>
</item>
<item>
<property name="text">
<string>Custom</string>
</property>
</item>
<item>
<property name="text">
<string>50M</string>
</property>
</item>
<item>
<property name="text">
<string>144M</string>
</property>
</item>
<item>
<property name="text">
<string>222M</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_freq">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_samplerate">
<property name="spacing">
<number>3</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="samplerateLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>SR</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="samplerate">
<property name="maximumSize">
<size>
<width>70</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Sample rate in kS/s</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="samplerateUnit">
<property name="text">
<string>kS/s</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QComboBox" name="bandwidth">
<property name="maximumSize">
<size>
<width>70</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>IF bandwidth in kHz</string>
</property>
</widget>
</item>
<item row="0" column="3">
<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>
<item row="0" column="4">
<widget class="QLabel" name="bandwidthLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>BW </string>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QLabel" name="bandwidthUnit">
<property name="text">
<string>kHz</string>
</property>
</widget>
</item>
<item row="0" column="7">
<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="QGridLayout" name="gridLayout_decim" columnstretch="0,0,0,0,0,0,0,0,0">
<property name="spacing">
<number>3</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_decim">
<property name="text">
<string>Dec</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="decim">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Decimation factor</string>
</property>
<property name="currentIndex">
<number>3</number>
</property>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>8</string>
</property>
</item>
<item>
<property name="text">
<string>16</string>
</property>
</item>
<item>
<property name="text">
<string>32</string>
</property>
</item>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_fcPos">
<property name="text">
<string>Fp</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QComboBox" name="fcPos">
<property name="toolTip">
<string>Relative position of device center frequency</string>
</property>
<item>
<property name="text">
<string>Inf</string>
</property>
</item>
<item>
<property name="text">
<string>Sup</string>
</property>
</item>
<item>
<property name="text">
<string>Cen</string>
</property>
</item>
</widget>
</item>
<item row="0" column="6">
<widget class="QLabel" name="lnaGainLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>LNA </string>
</property>
</widget>
</item>
<item row="0" column="5">
<spacer name="fcPosRightSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="7">
<widget class="QComboBox" name="lna">
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<item>
<property name="text">
<string>0</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>6</string>
</property>
</item>
</widget>
</item>
<item row="0" column="8">
<widget class="QLabel" name="label">
<property name="text">
<string>dB</string>
</property>
</widget>
</item>
<item row="0" column="2">
<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>
<item>
<widget class="Line" name="line_lna">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_vga1">
<property name="spacing">
<number>3</number>
</property>
<item row="0" column="1">
<widget class="QSlider" name="vga1">
<property name="toolTip">
<string>Amplifier before filtering gain (dB)</string>
</property>
<property name="minimum">
<number>5</number>
</property>
<property name="maximum">
<number>30</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>20</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="vga1Text">
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>20</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="vga1Label">
<property name="text">
<string>VGA1</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_vga1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_vga2" columnstretch="0,0,0">
<property name="spacing">
<number>3</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="vga2Label">
<property name="text">
<string>VGA2</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="vga2">
<property name="toolTip">
<string>Amplifier before ADC gain (dB)</string>
</property>
<property name="maximum">
<number>30</number>
</property>
<property name="singleStep">
<number>3</number>
</property>
<property name="pageStep">
<number>3</number>
</property>
<property name="value">
<number>9</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="vga2Text">
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>9</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="padLayout">
<item>
<spacer name="verticalPadSpacer">
<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>
<item>
<widget class="Line" name="line_vga2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</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="../../../sdrbase/resources/res.qrc"/>
</resources>
<connections/>
</ui>
@@ -0,0 +1,91 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 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 //
// //
// 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 "../bladerfinput/bladerfinputplugin.h"
#include <QtPlugin>
#include <QAction>
#include <libbladeRF.h>
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
#include <device/devicesourceapi.h>
#include "../bladerfinput/bladerfinputgui.h"
const PluginDescriptor BlderfInputPlugin::m_pluginDescriptor = {
QString("BladerRF Input"),
QString("2.0.0"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,
QString("https://github.com/f4exb/sdrangel")
};
const QString BlderfInputPlugin::m_deviceTypeID = BLADERF_DEVICE_TYPE_ID;
BlderfInputPlugin::BlderfInputPlugin(QObject* parent) :
QObject(parent)
{
}
const PluginDescriptor& BlderfInputPlugin::getPluginDescriptor() const
{
return m_pluginDescriptor;
}
void BlderfInputPlugin::initPlugin(PluginAPI* pluginAPI)
{
pluginAPI->registerSampleSource(m_deviceTypeID, this);
}
PluginInterface::SamplingDevices BlderfInputPlugin::enumSampleSources()
{
SamplingDevices result;
struct bladerf_devinfo *devinfo = 0;
int count = bladerf_get_device_list(&devinfo);
for(int i = 0; i < count; i++)
{
QString displayedName(QString("BladeRF[%1] %2").arg(devinfo[i].instance).arg(devinfo[i].serial));
result.append(SamplingDevice(displayedName,
m_deviceTypeID,
QString(devinfo[i].serial),
i));
}
if (devinfo)
{
bladerf_free_device_list(devinfo); // Valgrind memcheck
}
return result;
}
PluginGUI* BlderfInputPlugin::createSampleSourcePluginGUI(const QString& sourceId,QWidget **widget, DeviceSourceAPI *deviceAPI)
{
if(sourceId == m_deviceTypeID)
{
BladerfInputGui* gui = new BladerfInputGui(deviceAPI);
*widget = gui;
return gui;
}
else
{
return 0;
}
}
@@ -0,0 +1,47 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 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 //
// //
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_BLADERFINPUTPLUGIN_H
#define INCLUDE_BLADERFINPUTPLUGIN_H
#include <QObject>
#include "plugin/plugininterface.h"
class PluginAPI;
#define BLADERF_DEVICE_TYPE_ID "sdrangel.samplesource.bladerf"
class BlderfInputPlugin : public QObject, public PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)
Q_PLUGIN_METADATA(IID BLADERF_DEVICE_TYPE_ID)
public:
explicit BlderfInputPlugin(QObject* parent = NULL);
const PluginDescriptor& getPluginDescriptor() const;
void initPlugin(PluginAPI* pluginAPI);
virtual SamplingDevices enumSampleSources();
virtual PluginGUI* createSampleSourcePluginGUI(const QString& sourceId, QWidget **widget, DeviceSourceAPI *deviceAPI);
static const QString m_deviceTypeID;
private:
static const PluginDescriptor m_pluginDescriptor;
};
#endif // INCLUDE_BLADERFINPUTPLUGIN_H
@@ -0,0 +1,102 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 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 //
// //
// 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 "bladerfinputsettings.h"
#include <QtGlobal>
#include "util/simpleserializer.h"
BladeRFInputSettings::BladeRFInputSettings()
{
resetToDefaults();
}
void BladeRFInputSettings::resetToDefaults()
{
m_centerFrequency = 435000*1000;
m_devSampleRate = 3072000;
m_lnaGain = 0;
m_vga1 = 20;
m_vga2 = 9;
m_bandwidth = 1500000;
m_log2Decim = 0;
m_fcPos = FC_POS_INFRA;
m_xb200 = false;
m_xb200Path = BLADERF_XB200_MIX;
m_xb200Filter = BLADERF_XB200_AUTO_1DB;
m_dcBlock = false;
m_iqCorrection = false;
}
QByteArray BladeRFInputSettings::serialize() const
{
SimpleSerializer s(1);
s.writeS32(1, m_devSampleRate);
s.writeS32(2, m_lnaGain);
s.writeS32(3, m_vga1);
s.writeS32(4, m_vga2);
s.writeS32(5, m_bandwidth);
s.writeU32(6, m_log2Decim);
s.writeS32(7, (int) m_fcPos);
s.writeBool(8, m_xb200);
s.writeS32(9, (int) m_xb200Path);
s.writeS32(10, (int) m_xb200Filter);
s.writeBool(11, m_dcBlock);
s.writeBool(12, m_iqCorrection);
return s.final();
}
bool BladeRFInputSettings::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if (!d.isValid())
{
resetToDefaults();
return false;
}
if (d.getVersion() == 1)
{
int intval;
d.readS32(1, &m_devSampleRate);
d.readS32(2, &m_lnaGain);
d.readS32(3, &m_vga1);
d.readS32(4, &m_vga2);
d.readS32(5, &m_bandwidth);
d.readU32(6, &m_log2Decim);
d.readS32(7, &intval);
m_fcPos = (fcPos_t) intval;
d.readBool(8, &m_xb200);
d.readS32(9, &intval);
m_xb200Path = (bladerf_xb200_path) intval;
d.readS32(10, &intval);
m_xb200Filter = (bladerf_xb200_filter) intval;
d.readBool(11, &m_dcBlock);
d.readBool(12, &m_iqCorrection);
return true;
}
else
{
resetToDefaults();
return false;
}
}
@@ -0,0 +1,50 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 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 //
// //
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef _BLADERF_BLADERFINPUTSETTINGS_H_
#define _BLADERF_BLADERFINPUTSETTINGS_H_
#include <QtGlobal>
#include <libbladeRF.h>
struct BladeRFInputSettings {
typedef enum {
FC_POS_INFRA = 0,
FC_POS_SUPRA,
FC_POS_CENTER
} fcPos_t;
quint64 m_centerFrequency;
qint32 m_devSampleRate;
qint32 m_lnaGain;
qint32 m_vga1;
qint32 m_vga2;
qint32 m_bandwidth;
quint32 m_log2Decim;
fcPos_t m_fcPos;
bool m_xb200;
bladerf_xb200_path m_xb200Path;
bladerf_xb200_filter m_xb200Filter;
bool m_dcBlock;
bool m_iqCorrection;
BladeRFInputSettings();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
#endif /* _BLADERF_BLADERFINPUTSETTINGS_H_ */
@@ -0,0 +1,169 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 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 //
// //
// 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 "../bladerfinput/bladerfinputthread.h"
#include <stdio.h>
#include <errno.h>
#include "dsp/samplesinkfifo.h"
BladerfInputThread::BladerfInputThread(struct bladerf* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
QThread(parent),
m_running(false),
m_dev(dev),
m_convertBuffer(BLADERF_BLOCKSIZE),
m_sampleFifo(sampleFifo),
m_log2Decim(0),
m_fcPos(0)
{
}
BladerfInputThread::~BladerfInputThread()
{
stopWork();
}
void BladerfInputThread::startWork()
{
m_startWaitMutex.lock();
start();
while(!m_running)
m_startWaiter.wait(&m_startWaitMutex, 100);
m_startWaitMutex.unlock();
}
void BladerfInputThread::stopWork()
{
m_running = false;
wait();
}
void BladerfInputThread::setLog2Decimation(unsigned int log2_decim)
{
m_log2Decim = log2_decim;
}
void BladerfInputThread::setFcPos(int fcPos)
{
m_fcPos = fcPos;
}
void BladerfInputThread::run()
{
int res;
m_running = true;
m_startWaiter.wakeAll();
while(m_running) {
if((res = bladerf_sync_rx(m_dev, m_buf, BLADERF_BLOCKSIZE, NULL, 10000)) < 0) {
qCritical("BladerfThread: sync error: %s", strerror(errno));
break;
}
callback(m_buf, 2 * BLADERF_BLOCKSIZE);
}
m_running = false;
}
// Decimate according to specified log2 (ex: log2=4 => decim=16)
void BladerfInputThread::callback(const qint16* buf, qint32 len)
{
SampleVector::iterator it = m_convertBuffer.begin();
if (m_log2Decim == 0)
{
m_decimators.decimate1(&it, buf, len);
}
else
{
if (m_fcPos == 0) // Infra
{
switch (m_log2Decim)
{
case 1:
m_decimators.decimate2_inf(&it, buf, len);
break;
case 2:
m_decimators.decimate4_inf(&it, buf, len);
break;
case 3:
m_decimators.decimate8_inf(&it, buf, len);
break;
case 4:
m_decimators.decimate16_inf(&it, buf, len);
break;
case 5:
m_decimators.decimate32_inf(&it, buf, len);
break;
default:
break;
}
}
else if (m_fcPos == 1) // Supra
{
switch (m_log2Decim)
{
case 1:
m_decimators.decimate2_sup(&it, buf, len);
break;
case 2:
m_decimators.decimate4_sup(&it, buf, len);
break;
case 3:
m_decimators.decimate8_sup(&it, buf, len);
break;
case 4:
m_decimators.decimate16_sup(&it, buf, len);
break;
case 5:
m_decimators.decimate32_sup(&it, buf, len);
break;
default:
break;
}
}
else if (m_fcPos == 2) // Center
{
switch (m_log2Decim)
{
case 1:
m_decimators.decimate2_cen(&it, buf, len);
break;
case 2:
m_decimators.decimate4_cen(&it, buf, len);
break;
case 3:
m_decimators.decimate8_cen(&it, buf, len);
break;
case 4:
m_decimators.decimate16_cen(&it, buf, len);
break;
case 5:
m_decimators.decimate32_cen(&it, buf, len);
break;
default:
break;
}
}
}
m_sampleFifo->write(m_convertBuffer.begin(), it);
}
@@ -0,0 +1,60 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 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 //
// //
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_BLADERFINPUTTHREAD_H
#define INCLUDE_BLADERFINPUTTHREAD_H
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <libbladeRF.h>
#include "dsp/samplesinkfifo.h"
#include "dsp/decimators.h"
#define BLADERF_BLOCKSIZE (1<<14)
class BladerfInputThread : public QThread {
Q_OBJECT
public:
BladerfInputThread(struct bladerf* dev, SampleSinkFifo* sampleFifo, QObject* parent = NULL);
~BladerfInputThread();
void startWork();
void stopWork();
void setLog2Decimation(unsigned int log2_decim);
void setFcPos(int fcPos);
private:
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
bool m_running;
struct bladerf* m_dev;
qint16 m_buf[2*BLADERF_BLOCKSIZE];
SampleVector m_convertBuffer;
SampleSinkFifo* m_sampleFifo;
unsigned int m_log2Decim;
int m_fcPos;
Decimators<qint16, SDR_SAMP_SZ, 12> m_decimators;
void run();
void callback(const qint16* buf, qint32 len);
};
#endif // INCLUDE_BLADERFINPUTTHREAD_H