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

HackRF Tx support: rename more Rx files and cmake items

This commit is contained in:
f4exb
2016-12-27 03:14:50 +01:00
parent 7ef54cc2e0
commit dc2df804f7
14 changed files with 30 additions and 22 deletions
@@ -0,0 +1,69 @@
project(hackrfinput)
set(hackrfinput_SOURCES
hackrfinputgui.cpp
hackrfinput.cpp
hackrfinputplugin.cpp
hackrfinputsettings.cpp
hackrfinputthread.cpp
)
set(hackrfinput_HEADERS
hackrfinputgui.h
hackrfinput.h
hackrfinputplugin.h
hackrfinputsettings.h
hackrfinputthread.h
)
set(hackrfinput_FORMS
hackrfinputgui.ui
)
if (BUILD_DEBIAN)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${LIBHACKRFSRC}
${LIBHACKRFSRC}/libhackrf/src
)
else (BUILD_DEBIAN)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${LIBHACKRF_INCLUDE_DIR}
)
endif (BUILD_DEBIAN)
#include(${QT_USE_FILE})
#add_definitions(${QT_DEFINITIONS})
add_definitions("${QT_DEFINITIONS} -DLIBHACKRF_DYN_RATES")
add_definitions(-DQT_PLUGIN)
add_definitions(-DQT_SHARED)
#qt4_wrap_cpp(hackrfinput_HEADERS_MOC ${hackrfinput_HEADERS})
qt5_wrap_ui(hackrfinput_FORMS_HEADERS ${hackrfinput_FORMS})
add_library(inputhackrf SHARED
${hackrfinput_SOURCES}
${hackrfinput_HEADERS_MOC}
${hackrfinput_FORMS_HEADERS}
)
if (BUILD_DEBIAN)
target_link_libraries(inputhackrf
${QT_LIBRARIES}
hackrf
sdrbase
)
else (BUILD_DEBIAN)
target_link_libraries(inputhackrf
${QT_LIBRARIES}
${LIBHACKRF_LIBRARIES}
sdrbase
)
endif (BUILD_DEBIAN)
qt5_use_modules(inputhackrf Core Widgets)
install(TARGETS inputhackrf DESTINATION lib/plugins/samplesource)
@@ -0,0 +1,424 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 "../hackrfinput/hackrfinput.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 "../hackrfinput/hackrfinputgui.h"
#include "../hackrfinput/hackrfinputthread.h"
MESSAGE_CLASS_DEFINITION(HackRFInput::MsgConfigureHackRF, Message)
MESSAGE_CLASS_DEFINITION(HackRFInput::MsgReportHackRF, Message)
HackRFInput::HackRFInput(DeviceSourceAPI *deviceAPI) :
m_deviceAPI(deviceAPI),
m_settings(),
m_dev(0),
m_hackRFThread(0),
m_deviceDescription("HackRF")
{
}
HackRFInput::~HackRFInput()
{
stop();
}
bool HackRFInput::init(const Message& cmd)
{
return false;
}
bool HackRFInput::start(int device)
{
QMutexLocker mutexLocker(&m_mutex);
hackrf_error rc;
rc = (hackrf_error) hackrf_init();
if (rc != HACKRF_SUCCESS)
{
qCritical("HackRFInput::start: failed to initiate HackRF library %s", hackrf_error_name(rc));
}
if (m_dev != 0)
{
stop();
}
if (!m_sampleFifo.setSize(1<<19))
{
qCritical("HackRFInput::start: could not allocate SampleFifo");
return false;
}
if ((m_dev = open_hackrf_from_sequence(device)) == 0)
{
qCritical("HackRFInput::start: could not open HackRF #%d", device);
return false;
}
if((m_hackRFThread = new HackRFInputThread(m_dev, &m_sampleFifo)) == 0)
{
qFatal("HackRFInput::start: out of memory");
stop();
return false;
}
mutexLocker.unlock();
applySettings(m_settings, true);
m_hackRFThread->startWork();
qDebug("HackRFInput::startInput: started");
return true;
}
void HackRFInput::stop()
{
qDebug("HackRFInput::stop");
QMutexLocker mutexLocker(&m_mutex);
if(m_hackRFThread != 0)
{
m_hackRFThread->stopWork();
delete m_hackRFThread;
m_hackRFThread = 0;
}
if(m_dev != 0)
{
hackrf_stop_rx(m_dev);
hackrf_close(m_dev);
m_dev = 0;
}
hackrf_exit();
}
const QString& HackRFInput::getDeviceDescription() const
{
return m_deviceDescription;
}
int HackRFInput::getSampleRate() const
{
int rate = HackRFSampleRates::m_rates_k[m_settings.m_devSampleRateIndex] * 1000;
return (rate / (1<<m_settings.m_log2Decim));
}
quint64 HackRFInput::getCenterFrequency() const
{
return m_settings.m_centerFrequency;
}
bool HackRFInput::handleMessage(const Message& message)
{
if (MsgConfigureHackRF::match(message))
{
MsgConfigureHackRF& conf = (MsgConfigureHackRF&) message;
qDebug() << "HackRFInput::handleMessage: MsgConfigureHackRF";
bool success = applySettings(conf.getSettings(), false);
if (!success)
{
qDebug("HackRFInput::handleMessage: config error");
}
return true;
}
else
{
return false;
}
}
void HackRFInput::setCenterFrequency(quint64 freq_hz)
{
qint64 df = ((qint64)freq_hz * m_settings.m_LOppmTenths) / 10000000LL;
freq_hz += df;
hackrf_error rc = (hackrf_error) hackrf_set_freq(m_dev, static_cast<uint64_t>(freq_hz));
if (rc != HACKRF_SUCCESS)
{
qWarning("HackRFInput::setCenterFrequency: could not frequency to %llu Hz", freq_hz);
}
else
{
qWarning("HackRFInput::setCenterFrequency: frequency set to %llu Hz", freq_hz);
}
}
bool HackRFInput::applySettings(const HackRFInputSettings& settings, bool force)
{
QMutexLocker mutexLocker(&m_mutex);
bool forwardChange = false;
hackrf_error rc;
qDebug() << "HackRFInput::applySettings";
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_devSampleRateIndex != settings.m_devSampleRateIndex) || force)
{
forwardChange = true;
if (settings.m_devSampleRateIndex < HackRFSampleRates::m_nb_rates)
{
m_settings.m_devSampleRateIndex = settings.m_devSampleRateIndex;
}
else
{
m_settings.m_devSampleRateIndex = HackRFSampleRates::m_nb_rates - 1;
}
if (m_dev != 0)
{
rc = (hackrf_error) hackrf_set_sample_rate_manual(m_dev, HackRFSampleRates::m_rates_k[m_settings.m_devSampleRateIndex]*1000, 1);
if (rc != HACKRF_SUCCESS)
{
qCritical("HackRFInput::applySettings: could not set sample rate index %u (%d kS/s): %s", m_settings.m_devSampleRateIndex, HackRFSampleRates::m_rates_k[m_settings.m_devSampleRateIndex], hackrf_error_name(rc));
}
else
{
qDebug("HackRFInput::applySettings: sample rate set to index: %u (%d kS/s)", m_settings.m_devSampleRateIndex, HackRFSampleRates::m_rates_k[m_settings.m_devSampleRateIndex]);
m_hackRFThread->setSamplerate(HackRFSampleRates::m_rates_k[m_settings.m_devSampleRateIndex]);
}
}
}
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
{
m_settings.m_log2Decim = settings.m_log2Decim;
forwardChange = true;
if(m_dev != 0)
{
m_hackRFThread->setLog2Decimation(m_settings.m_log2Decim);
qDebug() << "HackRFInput: set decimation to " << (1<<m_settings.m_log2Decim);
}
}
qint64 deviceCenterFrequency = m_settings.m_centerFrequency;
qint64 f_img = deviceCenterFrequency;
quint32 devSampleRate = HackRFSampleRates::m_rates_k[m_settings.m_devSampleRateIndex] * 1000;
if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency) ||
(m_settings.m_LOppmTenths != settings.m_LOppmTenths) ||
(m_settings.m_fcPos != settings.m_fcPos))
{
m_settings.m_centerFrequency = settings.m_centerFrequency;
m_settings.m_LOppmTenths = settings.m_LOppmTenths;
if ((m_settings.m_log2Decim == 0) || (settings.m_fcPos == HackRFInputSettings::FC_POS_CENTER))
{
deviceCenterFrequency = m_settings.m_centerFrequency;
f_img = deviceCenterFrequency;
}
else
{
if (settings.m_fcPos == HackRFInputSettings::FC_POS_INFRA)
{
deviceCenterFrequency = m_settings.m_centerFrequency + (devSampleRate / 4);
f_img = deviceCenterFrequency + devSampleRate/2;
}
else if (settings.m_fcPos == HackRFInputSettings::FC_POS_SUPRA)
{
deviceCenterFrequency = m_settings.m_centerFrequency - (devSampleRate / 4);
f_img = deviceCenterFrequency - devSampleRate/2;
}
}
if (m_dev != 0)
{
setCenterFrequency(deviceCenterFrequency);
qDebug() << "HackRFInput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz"
<< " device center freq: " << deviceCenterFrequency << " Hz"
<< " device sample rate: " << devSampleRate << "Hz"
<< " Actual sample rate: " << devSampleRate/(1<<m_settings.m_log2Decim) << "Hz"
<< " img: " << f_img << "Hz";
}
forwardChange = true;
}
if ((m_settings.m_fcPos != settings.m_fcPos) || force)
{
m_settings.m_fcPos = settings.m_fcPos;
if(m_dev != 0)
{
m_hackRFThread->setFcPos((int) m_settings.m_fcPos);
qDebug() << "HackRFInput: set fc pos (enum) to " << (int) m_settings.m_fcPos;
}
}
if ((m_settings.m_lnaGain != settings.m_lnaGain) || force)
{
m_settings.m_lnaGain = settings.m_lnaGain;
if (m_dev != 0)
{
rc = (hackrf_error) hackrf_set_lna_gain(m_dev, m_settings.m_lnaGain);
if(rc != HACKRF_SUCCESS)
{
qDebug("HackRFInput::applySettings: airspy_set_lna_gain failed: %s", hackrf_error_name(rc));
}
else
{
qDebug() << "HackRFInput:applySettings: LNA gain set to " << m_settings.m_lnaGain;
}
}
}
if ((m_settings.m_vgaGain != settings.m_vgaGain) || force)
{
m_settings.m_vgaGain = settings.m_vgaGain;
if (m_dev != 0)
{
rc = (hackrf_error) hackrf_set_vga_gain(m_dev, m_settings.m_vgaGain);
if (rc != HACKRF_SUCCESS)
{
qDebug("HackRFInput::applySettings: hackrf_set_vga_gain failed: %s", hackrf_error_name(rc));
}
else
{
qDebug() << "HackRFInput:applySettings: VGA gain set to " << m_settings.m_vgaGain;
}
}
}
if ((m_settings.m_bandwidthIndex != settings.m_bandwidthIndex) || force)
{
if (settings.m_bandwidthIndex < HackRFBandwidths::m_nb_bw)
{
m_settings.m_bandwidthIndex = settings.m_bandwidthIndex;
}
else
{
m_settings.m_bandwidthIndex = HackRFBandwidths::m_nb_bw - 1;
}
if (m_dev != 0)
{
uint32_t bw_index = hackrf_compute_baseband_filter_bw_round_down_lt(HackRFBandwidths::m_bw_k[m_settings.m_bandwidthIndex]*1000);
rc = (hackrf_error) hackrf_set_baseband_filter_bandwidth(m_dev, bw_index);
if (rc != HACKRF_SUCCESS)
{
qDebug("HackRFInput::applySettings: hackrf_set_baseband_filter_bandwidth failed: %s", hackrf_error_name(rc));
}
else
{
qDebug() << "HackRFInput:applySettings: Baseband BW filter set to " << HackRFBandwidths::m_bw_k[m_settings.m_bandwidthIndex] << " kHz";
}
}
}
if ((m_settings.m_biasT != settings.m_biasT) || force)
{
m_settings.m_biasT = settings.m_biasT;
if (m_dev != 0)
{
rc = (hackrf_error) hackrf_set_antenna_enable(m_dev, (m_settings.m_biasT ? 1 : 0));
if(rc != HACKRF_SUCCESS)
{
qDebug("HackRFInput::applySettings: hackrf_set_antenna_enable failed: %s", hackrf_error_name(rc));
}
else
{
qDebug() << "HackRFInput:applySettings: bias tee set to " << m_settings.m_biasT;
}
}
}
if ((m_settings.m_lnaExt != settings.m_lnaExt) || force)
{
m_settings.m_lnaExt = settings.m_lnaExt;
if (m_dev != 0)
{
rc = (hackrf_error) hackrf_set_amp_enable(m_dev, (m_settings.m_lnaExt ? 1 : 0));
if(rc != HACKRF_SUCCESS)
{
qDebug("HackRFInput::applySettings: hackrf_set_amp_enable failed: %s", hackrf_error_name(rc));
}
else
{
qDebug() << "HackRFInput:applySettings: extra LNA set to " << m_settings.m_lnaExt;
}
}
}
if (forwardChange)
{
int sampleRate = devSampleRate/(1<<m_settings.m_log2Decim);
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency);
m_deviceAPI->getDeviceInputMessageQueue()->push(notif);
}
return true;
}
hackrf_device *HackRFInput::open_hackrf_from_sequence(int sequence)
{
hackrf_device_list_t *hackrf_devices = hackrf_device_list();
hackrf_device *hackrf_ptr;
hackrf_error rc;
rc = (hackrf_error) hackrf_device_list_open(hackrf_devices, sequence, &hackrf_ptr);
if (rc == HACKRF_SUCCESS)
{
return hackrf_ptr;
}
else
{
return 0;
}
}
@@ -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_HACKRFINPUT_H
#define INCLUDE_HACKRFINPUT_H
#include <dsp/devicesamplesource.h>
#include "libhackrf/hackrf.h"
#include <QString>
#include "../hackrfinput/hackrfinputsettings.h"
class DeviceSourceAPI;
class HackRFInputThread;
class HackRFInput : public DeviceSampleSource {
public:
class MsgConfigureHackRF : public Message {
MESSAGE_CLASS_DECLARATION
public:
const HackRFInputSettings& getSettings() const { return m_settings; }
static MsgConfigureHackRF* create(const HackRFInputSettings& settings)
{
return new MsgConfigureHackRF(settings);
}
private:
HackRFInputSettings m_settings;
MsgConfigureHackRF(const HackRFInputSettings& settings) :
Message(),
m_settings(settings)
{ }
};
class MsgReportHackRF : public Message {
MESSAGE_CLASS_DECLARATION
public:
static MsgReportHackRF* create()
{
return new MsgReportHackRF();
}
protected:
MsgReportHackRF() :
Message()
{ }
};
HackRFInput(DeviceSourceAPI *deviceAPI);
virtual ~HackRFInput();
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 HackRFInputSettings& settings, bool force);
hackrf_device *open_hackrf_from_sequence(int sequence);
void setCenterFrequency(quint64 freq);
DeviceSourceAPI *m_deviceAPI;
QMutex m_mutex;
HackRFInputSettings m_settings;
struct hackrf_device* m_dev;
HackRFInputThread* m_hackRFThread;
QString m_deviceDescription;
};
#endif // INCLUDE_HACKRFINPUT_H
@@ -0,0 +1,45 @@
#--------------------------------------------------------
#
# Pro file for Android and Windows builds with Qt Creator
#
#--------------------------------------------------------
TEMPLATE = lib
CONFIG += plugin
QT += core gui widgets multimedia opengl
TARGET = inputhackrf
DEFINES += USE_SSE2=1
QMAKE_CXXFLAGS += -msse2
DEFINES += USE_SSE4_1=1
QMAKE_CXXFLAGS += -msse4.1
CONFIG(MINGW32):LIBHACKRFSRC = "D:\softs\hackrf\host"
CONFIG(MINGW64):LIBHACKRFSRC = "D:\softs\hackrf\host"
INCLUDEPATH += $$PWD
INCLUDEPATH += ../../../sdrbase
INCLUDEPATH += $$LIBHACKRFSRC
CONFIG(Release):build_subdir = release
CONFIG(Debug):build_subdir = debug
SOURCES += hackrfinputgui.cpp\
hackrfinput.cpp\
hackrfinputplugin.cpp\
hackrfinputsettings.cpp\
hackrfinputthread.cpp
HEADERS += hackrfinputgui.h\
hackrfinput.h\
hackrfinputplugin.h\
hackrfinputsettings.h\
hackrfinputthread.h
FORMS += hackrfinputgui.ui
LIBS += -L../../../sdrbase/$${build_subdir} -lsdrbase
LIBS += -L../../../libhackrf/$${build_subdir} -llibhackrf
RESOURCES = ../../../sdrbase/resources/res.qrc
@@ -0,0 +1,450 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 "../hackrfinput/hackrfinputgui.h"
#include <QDebug>
#include <QMessageBox>
#include <libhackrf/hackrf.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>
#include "ui_hackrfinputgui.h"
HackRFInputGui::HackRFInputGui(DeviceSourceAPI *deviceAPI, QWidget* parent) :
QWidget(parent),
ui(new Ui::HackRFInputGui),
m_deviceAPI(deviceAPI),
m_settings(),
m_sampleSource(NULL),
m_lastEngineState((DSPDeviceSourceEngine::State)-1)
{
ui->setupUi(this);
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
ui->centerFrequency->setValueRange(7, 0U, 7250000U);
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
m_statusTimer.start(500);
displaySettings();
m_sampleSource = new HackRFInput(m_deviceAPI);
displaySampleRates();
displayBandwidths();
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);
}
HackRFInputGui::~HackRFInputGui()
{
m_deviceAPI->removeSink(m_fileSink);
delete m_fileSink;
delete m_sampleSource; // Valgrind memcheck
delete ui;
}
void HackRFInputGui::destroy()
{
delete this;
}
void HackRFInputGui::setName(const QString& name)
{
setObjectName(name);
}
QString HackRFInputGui::getName() const
{
return objectName();
}
void HackRFInputGui::resetToDefaults()
{
m_settings.resetToDefaults();
displaySettings();
sendSettings();
}
qint64 HackRFInputGui::getCenterFrequency() const
{
return m_settings.m_centerFrequency;
}
void HackRFInputGui::setCenterFrequency(qint64 centerFrequency)
{
m_settings.m_centerFrequency = centerFrequency;
displaySettings();
sendSettings();
}
QByteArray HackRFInputGui::serialize() const
{
return m_settings.serialize();
}
bool HackRFInputGui::deserialize(const QByteArray& data)
{
if(m_settings.deserialize(data)) {
displaySettings();
sendSettings();
return true;
} else {
resetToDefaults();
return false;
}
}
bool HackRFInputGui::handleMessage(const Message& message)
{
return false;
}
void HackRFInputGui::handleDSPMessages()
{
Message* message;
while ((message = m_deviceAPI->getDeviceOutputMessageQueue()->pop()) != 0)
{
qDebug("HackRFGui::handleDSPMessages: message: %s", message->getIdentifier());
if (DSPSignalNotification::match(*message))
{
DSPSignalNotification* notif = (DSPSignalNotification*) message;
m_sampleRate = notif->getSampleRate();
m_deviceCenterFrequency = notif->getCenterFrequency();
qDebug("HackRFGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
updateSampleRateAndFrequency();
m_fileSink->handleMessage(*notif); // forward to file sink
delete message;
}
}
}
void HackRFInputGui::updateSampleRateAndFrequency()
{
m_deviceAPI->getSpectrum()->setSampleRate(m_sampleRate);
m_deviceAPI->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency);
ui->deviceRateText->setText(tr("%1k").arg((float)m_sampleRate / 1000));
}
void HackRFInputGui::displaySettings()
{
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
ui->LOppm->setValue(m_settings.m_LOppmTenths);
ui->LOppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
ui->dcOffset->setChecked(m_settings.m_dcBlock);
ui->iqImbalance->setChecked(m_settings.m_iqCorrection);
ui->sampleRate->setCurrentIndex(m_settings.m_devSampleRateIndex);
ui->biasT->setChecked(m_settings.m_biasT);
ui->decim->setCurrentIndex(m_settings.m_log2Decim);
ui->fcPos->setCurrentIndex((int) m_settings.m_fcPos);
ui->lnaExt->setChecked(m_settings.m_lnaExt);
ui->lnaGainText->setText(tr("%1dB").arg(m_settings.m_lnaGain));
ui->lna->setValue(m_settings.m_lnaGain);
ui->bbFilter->setCurrentIndex(m_settings.m_bandwidthIndex);
ui->vgaText->setText(tr("%1dB").arg(m_settings.m_vgaGain));
ui->vga->setValue(m_settings.m_vgaGain);
}
void HackRFInputGui::displaySampleRates()
{
int savedIndex = m_settings.m_devSampleRateIndex;
ui->sampleRate->blockSignals(true);
ui->sampleRate->clear();
for (int i = 0; i < HackRFSampleRates::m_nb_rates; i++)
{
ui->sampleRate->addItem(QString("%1M").arg(QString::number(HackRFSampleRates::m_rates_k[i]/1000.0, 'f', 1)));
}
ui->sampleRate->blockSignals(false);
if (savedIndex < HackRFSampleRates::m_nb_rates)
{
ui->sampleRate->setCurrentIndex(savedIndex);
}
else
{
ui->sampleRate->setCurrentIndex((int) HackRFSampleRates::m_nb_rates-1);
}
}
void HackRFInputGui::displayBandwidths()
{
int savedIndex = m_settings.m_bandwidthIndex;
ui->bbFilter->blockSignals(true);
ui->bbFilter->clear();
for (int i = 0; i < HackRFBandwidths::m_nb_bw; i++)
{
ui->bbFilter->addItem(QString("%1M").arg(QString::number(HackRFBandwidths::m_bw_k[i]/1000.0, 'f', 2)));
}
ui->bbFilter->blockSignals(false);
if (savedIndex < HackRFBandwidths::m_nb_bw)
{
ui->bbFilter->setCurrentIndex(savedIndex);
}
else
{
ui->bbFilter->setCurrentIndex((int) HackRFBandwidths::m_nb_bw-1);
}
}
void HackRFInputGui::sendSettings()
{
if(!m_updateTimer.isActive())
m_updateTimer.start(100);
}
void HackRFInputGui::on_centerFrequency_changed(quint64 value)
{
m_settings.m_centerFrequency = value * 1000;
sendSettings();
}
void HackRFInputGui::on_LOppm_valueChanged(int value)
{
m_settings.m_LOppmTenths = value;
ui->LOppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
sendSettings();
}
void HackRFInputGui::on_dcOffset_toggled(bool checked)
{
m_settings.m_dcBlock = checked;
sendSettings();
}
void HackRFInputGui::on_iqImbalance_toggled(bool checked)
{
m_settings.m_iqCorrection = checked;
sendSettings();
}
void HackRFInputGui::on_sampleRate_currentIndexChanged(int index)
{
m_settings.m_devSampleRateIndex = index;
sendSettings();
}
void HackRFInputGui::on_bbFilter_currentIndexChanged(int index)
{
m_settings.m_bandwidthIndex = index;
sendSettings();
}
void HackRFInputGui::on_biasT_stateChanged(int state)
{
m_settings.m_biasT = (state == Qt::Checked);
sendSettings();
}
void HackRFInputGui::on_lnaExt_stateChanged(int state)
{
m_settings.m_lnaExt = (state == Qt::Checked);
sendSettings();
}
void HackRFInputGui::on_decim_currentIndexChanged(int index)
{
if ((index <0) || (index > 6))
return;
m_settings.m_log2Decim = index;
sendSettings();
}
void HackRFInputGui::on_fcPos_currentIndexChanged(int index)
{
if (index == 0) {
m_settings.m_fcPos = HackRFInputSettings::FC_POS_INFRA;
sendSettings();
} else if (index == 1) {
m_settings.m_fcPos = HackRFInputSettings::FC_POS_SUPRA;
sendSettings();
} else if (index == 2) {
m_settings.m_fcPos = HackRFInputSettings::FC_POS_CENTER;
sendSettings();
}
}
void HackRFInputGui::on_lna_valueChanged(int value)
{
if ((value < 0) || (value > 40))
return;
ui->lnaGainText->setText(tr("%1dB").arg(value));
m_settings.m_lnaGain = value;
sendSettings();
}
void HackRFInputGui::on_vga_valueChanged(int value)
{
if ((value < 0) || (value > 62))
return;
ui->vgaText->setText(tr("%1dB").arg(value));
m_settings.m_vgaGain = value;
sendSettings();
}
void HackRFInputGui::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 HackRFInputGui::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 HackRFInputGui::updateHardware()
{
qDebug() << "HackRFGui::updateHardware";
HackRFInput::MsgConfigureHackRF* message = HackRFInput::MsgConfigureHackRF::create( m_settings);
m_sampleSource->getInputMessageQueue()->push(message);
m_updateTimer.stop();
}
void HackRFInputGui::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 HackRFSampleRates::m_rates_k[] = {2400, 3200, 4800, 5600, 6400, 8000, 9600, 12800, 19200};
unsigned int HackRFSampleRates::getRate(unsigned int rate_index)
{
if (rate_index < m_nb_rates)
{
return m_rates_k[rate_index];
}
else
{
return m_rates_k[0];
}
}
unsigned int HackRFSampleRates::getRateIndex(unsigned int rate)
{
for (unsigned int i=0; i < m_nb_rates; i++)
{
if (rate/1000 == m_rates_k[i])
{
return i;
}
}
return 0;
}
unsigned int HackRFBandwidths::m_bw_k[] = {1750, 2500, 3500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, 12000, 14000, 15000, 20000, 24000, 28000};
unsigned int HackRFBandwidths::getBandwidth(unsigned int bandwidth_index)
{
if (bandwidth_index < m_nb_bw)
{
return m_bw_k[bandwidth_index];
}
else
{
return m_bw_k[0];
}
}
unsigned int HackRFBandwidths::getBandwidthIndex(unsigned int bandwidth)
{
for (unsigned int i=0; i < m_nb_bw; i++)
{
if (bandwidth == m_bw_k[i])
{
return i;
}
}
return 0;
}
@@ -0,0 +1,115 @@
///////////////////////////////////////////////////////////////////////////////////
// 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_HACKRFINPUTGUI_H
#define INCLUDE_HACKRFINPUTGUI_H
#include <QTimer>
#include "plugin/plugingui.h"
#include "../hackrfinput/hackrfinput.h"
#define HACKRF_MAX_DEVICE (32)
class DeviceSourceAPI;
class FileRecord;
namespace Ui {
class HackRFInputGui;
}
class HackRFInputGui : public QWidget, public PluginGUI {
Q_OBJECT
public:
typedef enum
{
HACKRF_IMGREJ_BYPASS = 0,
HACKRF_IMGREJ_LOWPASS,
HACKRF_IMGREJ_HIGHPASS,
HACKRF_IMGREJ_NB
} HackRFImgRejValue;
explicit HackRFInputGui(DeviceSourceAPI *deviceAPI, QWidget* parent = NULL);
virtual ~HackRFInputGui();
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::HackRFInputGui* ui;
DeviceSourceAPI* m_deviceAPI;
HackRFInputSettings m_settings;
QTimer m_updateTimer;
QTimer m_statusTimer;
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 displaySampleRates();
void displayBandwidths();
void sendSettings();
void updateSampleRateAndFrequency();
private slots:
void handleDSPMessages();
void on_centerFrequency_changed(quint64 value);
void on_LOppm_valueChanged(int value);
void on_dcOffset_toggled(bool checked);
void on_iqImbalance_toggled(bool checked);
void on_sampleRate_currentIndexChanged(int index);
void on_biasT_stateChanged(int state);
void on_decim_currentIndexChanged(int index);
void on_fcPos_currentIndexChanged(int index);
void on_lnaExt_stateChanged(int state);
void on_lna_valueChanged(int value);
void on_bbFilter_currentIndexChanged(int index);
void on_vga_valueChanged(int value);
void on_startStop_toggled(bool checked);
void on_record_toggled(bool checked);
void updateHardware();
void updateStatus();
};
class HackRFSampleRates {
public:
static unsigned int getRate(unsigned int rate_index);
static unsigned int getRateIndex(unsigned int rate);
static const unsigned int m_nb_rates = 9;
static unsigned int m_rates_k[m_nb_rates];
};
class HackRFBandwidths {
public:
static unsigned int getBandwidth(unsigned int bandwidth_index);
static unsigned int getBandwidthIndex(unsigned int bandwidth);
static const unsigned int m_nb_bw = 16;
static unsigned int m_bw_k[m_nb_bw];
};
#endif // INCLUDE_HACKRFINPUTGUI_H
@@ -0,0 +1,606 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HackRFInputGui</class>
<widget class="QWidget" name="HackRFInputGui">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>260</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>260</width>
<height>210</height>
</size>
</property>
<property name="font">
<font>
<family>Sans Serif</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="windowTitle">
<string>HackRF</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>:/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>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>
<layout class="QGridLayout" name="gridLayout_LOppm">
<property name="spacing">
<number>3</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="LOppmLabel">
<property name="toolTip">
<string>LO correction ppm</string>
</property>
<property name="text">
<string>LO ppm</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="LOppm">
<property name="toolTip">
<string>Local Oscullator ppm correction</string>
</property>
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="LOppmText">
<property name="text">
<string>0.0</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_corr">
<item row="0" column="1">
<widget class="ButtonSwitch" name="dcOffset">
<property name="toolTip">
<string>DC Offset auto correction</string>
</property>
<property name="text">
<string>DC</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="ButtonSwitch" name="iqImbalance">
<property name="toolTip">
<string>IQ Imbalance auto correction</string>
</property>
<property name="text">
<string>IQ</string>
</property>
</widget>
</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="QCheckBox" name="biasT">
<property name="toolTip">
<string>Activate antenna bias tee</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Bias T</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QCheckBox" name="lnaExt">
<property name="toolTip">
<string>Extra LNA +14dB</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>RF Amp</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>
</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>Rate</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="sampleRate">
<property name="toolTip">
<string>Device sample rate</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="bbFiltLabel">
<property name="text">
<string>BBF</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QComboBox" name="bbFilter">
<property name="toolTip">
<string>RF bandpas filter</string>
</property>
</widget>
</item>
<item row="0" column="2">
<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="QGridLayout" name="gridLayout_decim" columnstretch="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="3">
<widget class="QLabel" name="label_fcPos">
<property name="text">
<string>Fc pos</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="decim">
<property name="maximumSize">
<size>
<width>55</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>
<item>
<property name="text">
<string>64</string>
</property>
</item>
</widget>
</item>
<item row="0" column="4">
<widget class="QComboBox" name="fcPos">
<property name="maximumSize">
<size>
<width>55</width>
<height>16777215</height>
</size>
</property>
<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="2">
<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>
<widget class="Line" name="line_fcPos">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_lna">
<property name="spacing">
<number>3</number>
</property>
<item row="0" column="0">
<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="1">
<widget class="QSlider" name="lna">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>LNA gain dB</string>
</property>
<property name="maximum">
<number>40</number>
</property>
<property name="singleStep">
<number>8</number>
</property>
<property name="pageStep">
<number>8</number>
</property>
<property name="value">
<number>16</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="lnaGainText">
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>0dB</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_vga" columnstretch="0,0,0">
<property name="spacing">
<number>3</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="vgaLabel">
<property name="text">
<string>VGA</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="vga">
<property name="toolTip">
<string>VGA gain dB</string>
</property>
<property name="maximum">
<number>62</number>
</property>
<property name="singleStep">
<number>2</number>
</property>
<property name="pageStep">
<number>2</number>
</property>
<property name="value">
<number>16</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="vgaText">
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>0dB</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="verticaPadlSpacer">
<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="../../../sdrbase/resources/res.qrc"/>
</resources>
<connections/>
</ui>
@@ -0,0 +1,128 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 "../hackrfinput/hackrfinputplugin.h"
#include <QtPlugin>
#include <QAction>
#include "libhackrf/hackrf.h"
#include <device/devicesourceapi.h>
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
#include "../hackrfinput/hackrfinputgui.h"
const PluginDescriptor HackRFInputPlugin::m_pluginDescriptor = {
QString("HackRF 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 HackRFInputPlugin::m_deviceTypeID = HACKRF_DEVICE_TYPE_ID;
HackRFInputPlugin::HackRFInputPlugin(QObject* parent) :
QObject(parent)
{
}
const PluginDescriptor& HackRFInputPlugin::getPluginDescriptor() const
{
return m_pluginDescriptor;
}
void HackRFInputPlugin::initPlugin(PluginAPI* pluginAPI)
{
pluginAPI->registerSampleSource(m_deviceTypeID, this);
}
PluginInterface::SamplingDevices HackRFInputPlugin::enumSampleSources()
{
hackrf_error rc = (hackrf_error) hackrf_init();
if (rc != HACKRF_SUCCESS)
{
qCritical("HackRFPlugin::SampleSourceDevices: failed to initiate HackRF library: %s", hackrf_error_name(rc));
}
SamplingDevices result;
hackrf_device_list_t *hackrf_devices = hackrf_device_list();
hackrf_device *hackrf_ptr;
read_partid_serialno_t read_partid_serialno;
int i;
for (i=0; i < hackrf_devices->devicecount; i++)
{
rc = (hackrf_error) hackrf_device_list_open(hackrf_devices, i, &hackrf_ptr);
if (rc == HACKRF_SUCCESS)
{
qDebug("HackRFPlugin::enumSampleSources: try to enumerate HackRF device #%d", i);
rc = (hackrf_error) hackrf_board_partid_serialno_read(hackrf_ptr, &read_partid_serialno);
if (rc != HACKRF_SUCCESS)
{
qDebug("HackRFPlugin::enumSampleSources: failed to read serial no: %s", hackrf_error_name(rc));
hackrf_close(hackrf_ptr);
continue; // next
}
uint32_t serial_msb = read_partid_serialno.serial_no[2];
uint32_t serial_lsb = read_partid_serialno.serial_no[3];
QString serial_str = QString::number(serial_msb, 16) + QString::number(serial_lsb, 16);
uint64_t serial_num = (((uint64_t) serial_msb)<<32) + serial_lsb;
QString displayedName(QString("HackRF[%1] %2").arg(i).arg(serial_str));
result.append(SamplingDevice(displayedName, m_deviceTypeID,
serial_str,
i));
qDebug("HackRFPlugin::enumSampleSources: enumerated HackRF device #%d", i);
hackrf_close(hackrf_ptr);
}
else
{
qDebug("HackRFPlugin::enumSampleSources: failed to enumerate HackRF device #%d: %s", i, hackrf_error_name(rc));
}
}
hackrf_device_list_free(hackrf_devices);
rc = (hackrf_error) hackrf_exit();
qDebug("HackRFPlugin::enumSampleSources: hackrf_exit: %s", hackrf_error_name(rc));
return result;
}
PluginGUI* HackRFInputPlugin::createSampleSourcePluginGUI(const QString& sourceId, QWidget **widget, DeviceSourceAPI *deviceAPI)
{
if(sourceId == m_deviceTypeID)
{
HackRFInputGui* gui = new HackRFInputGui(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_HACKRFINPUTPLUGIN_H
#define INCLUDE_HACKRFINPUTPLUGIN_H
#include <QObject>
#include "plugin/plugininterface.h"
#define HACKRF_DEVICE_TYPE_ID "sdrangel.samplesource.hackrf"
class PluginAPI;
class HackRFInputPlugin : public QObject, public PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)
Q_PLUGIN_METADATA(IID HACKRF_DEVICE_TYPE_ID)
public:
explicit HackRFInputPlugin(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_HACKRFINPUTPLUGIN_H
@@ -0,0 +1,97 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 "../hackrfinput/hackrfinputsettings.h"
#include <QtGlobal>
#include "util/simpleserializer.h"
HackRFInputSettings::HackRFInputSettings()
{
resetToDefaults();
}
void HackRFInputSettings::resetToDefaults()
{
m_centerFrequency = 435000 * 1000;
m_LOppmTenths = 0;
m_devSampleRateIndex = 0;
m_biasT = false;
m_log2Decim = 0;
m_fcPos = FC_POS_CENTER;
m_lnaExt = false;
m_lnaGain = 16;
m_bandwidthIndex = 0;
m_vgaGain = 16;
m_dcBlock = false;
m_iqCorrection = false;
}
QByteArray HackRFInputSettings::serialize() const
{
SimpleSerializer s(1);
s.writeS32(1, m_LOppmTenths);
s.writeU32(2, m_devSampleRateIndex);
s.writeBool(3, m_biasT);
s.writeU32(4, m_log2Decim);
s.writeS32(5, m_fcPos);
s.writeBool(6, m_lnaExt);
s.writeU32(7, m_lnaGain);
s.writeU32(8, m_bandwidthIndex);
s.writeU32(9, m_vgaGain);
s.writeBool(10, m_dcBlock);
s.writeBool(11, m_iqCorrection);
return s.final();
}
bool HackRFInputSettings::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if (!d.isValid())
{
resetToDefaults();
return false;
}
if (d.getVersion() == 1)
{
int intval;
d.readS32(1, &m_LOppmTenths, 0);
d.readU32(2, &m_devSampleRateIndex, 0);
d.readBool(3, &m_biasT, false);
d.readU32(4, &m_log2Decim, 0);
d.readS32(5, &intval, 0);
m_fcPos = (fcPos_t) intval;
d.readBool(6, &m_lnaExt, false);
d.readU32(7, &m_lnaGain, 16);
d.readU32(8, &m_bandwidthIndex, 0);
d.readU32(9, &m_vgaGain, 16);
d.readBool(10, &m_dcBlock, false);
d.readBool(11, &m_iqCorrection, false);
return true;
}
else
{
resetToDefaults();
return false;
}
}
@@ -0,0 +1,48 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 _HACKRF_HACKRFINPUTSETTINGS_H_
#define _HACKRF_HACKRFINPUTSETTINGS_H_
#include <QtGlobal>
struct HackRFInputSettings {
typedef enum {
FC_POS_INFRA = 0,
FC_POS_SUPRA,
FC_POS_CENTER
} fcPos_t;
quint64 m_centerFrequency;
qint32 m_LOppmTenths;
quint32 m_devSampleRateIndex;
quint32 m_bandwidthIndex;
quint32 m_lnaGain;
quint32 m_vgaGain;
quint32 m_log2Decim;
fcPos_t m_fcPos;
bool m_biasT;
bool m_lnaExt;
bool m_dcBlock;
bool m_iqCorrection;
HackRFInputSettings();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
#endif /* _HACKRF_HACKRFINPUTSETTINGS_H_ */
@@ -0,0 +1,213 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 "../hackrfinput/hackrfinputthread.h"
#include <stdio.h>
#include <errno.h>
#include "../../../sdrbase/dsp/samplesinkfifo.h"
HackRFInputThread *HackRFInputThread::m_this = 0;
HackRFInputThread::HackRFInputThread(hackrf_device* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
QThread(parent),
m_running(false),
m_dev(dev),
m_convertBuffer(HACKRF_BLOCKSIZE),
m_sampleFifo(sampleFifo),
m_samplerate(10),
m_log2Decim(0),
m_fcPos(0)
{
m_this = this;
}
HackRFInputThread::~HackRFInputThread()
{
stopWork();
m_this = 0;
}
void HackRFInputThread::startWork()
{
//m_startWaitMutex.lock();
m_running = true;
start();
/*
while(!m_running)
m_startWaiter.wait(&m_startWaitMutex, 100);
m_startWaitMutex.unlock();*/
}
void HackRFInputThread::stopWork()
{
qDebug("HackRFThread::stopWork");
m_running = false;
wait();
}
void HackRFInputThread::setSamplerate(uint32_t samplerate)
{
m_samplerate = samplerate;
}
void HackRFInputThread::setLog2Decimation(unsigned int log2_decim)
{
m_log2Decim = log2_decim;
}
void HackRFInputThread::setFcPos(int fcPos)
{
m_fcPos = fcPos;
}
void HackRFInputThread::run()
{
hackrf_error rc;
//m_running = true;
m_startWaiter.wakeAll();
rc = (hackrf_error) hackrf_start_rx(m_dev, rx_callback, NULL);
if (rc != HACKRF_SUCCESS)
{
qCritical("HackRFThread::run: failed to start HackRF Rx: %s", hackrf_error_name(rc));
}
else
{
while ((m_running) && (hackrf_is_streaming(m_dev) == HACKRF_TRUE))
{
sleep(1);
}
}
rc = (hackrf_error) hackrf_stop_rx(m_dev);
if (rc == HACKRF_SUCCESS)
{
qDebug("HackRFThread::run: stopped HackRF Rx");
}
else
{
qDebug("HackRFThread::run: failed to stop HackRF Rx: %s", hackrf_error_name(rc));
}
//m_running = false;
}
// Decimate according to specified log2 (ex: log2=4 => decim=16)
void HackRFInputThread::callback(const qint8* 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;
case 6:
m_decimators.decimate64_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;
case 6:
m_decimators.decimate64_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;
case 6:
m_decimators.decimate64_cen(&it, buf, len);
break;
default:
break;
}
}
}
m_sampleFifo->write(m_convertBuffer.begin(), it);
}
int HackRFInputThread::rx_callback(hackrf_transfer* transfer)
{
qint32 bytes_to_write = transfer->valid_length;
m_this->callback((qint8 *) transfer->buffer, bytes_to_write);
return 0;
}
@@ -0,0 +1,65 @@
///////////////////////////////////////////////////////////////////////////////////
// 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_HACKRFINPUTTHREAD_H
#define INCLUDE_HACKRFINPUTTHREAD_H
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <libhackrf/hackrf.h>
#include "dsp/samplesinkfifo.h"
#include "dsp/decimators.h"
#define HACKRF_BLOCKSIZE (1<<17)
class HackRFInputThread : public QThread {
Q_OBJECT
public:
HackRFInputThread(hackrf_device* dev, SampleSinkFifo* sampleFifo, QObject* parent = NULL);
~HackRFInputThread();
void startWork();
void stopWork();
void setSamplerate(uint32_t samplerate);
void setLog2Decimation(unsigned int log2_decim);
void setFcPos(int fcPos);
private:
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
bool m_running;
hackrf_device* m_dev;
qint16 m_buf[2*HACKRF_BLOCKSIZE];
SampleVector m_convertBuffer;
SampleSinkFifo* m_sampleFifo;
int m_samplerate;
unsigned int m_log2Decim;
int m_fcPos;
static HackRFInputThread *m_this;
Decimators<qint8, SDR_SAMP_SZ, 8> m_decimators;
void run();
void callback(const qint8* buf, qint32 len);
static int rx_callback(hackrf_transfer* transfer);
};
#endif // INCLUDE_HACKRFINPUTTHREAD_H