1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 01:18:38 -05:00

HackRF output plugin: compiles

This commit is contained in:
f4exb 2017-01-08 04:13:20 +01:00
parent 1a8d96d874
commit 85ed39c767
18 changed files with 2094 additions and 10 deletions

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
sdrangel (3.1.0-1) unstable; urgency=medium
* HackRF Tx support
-- Edouard Griffiths, F4EXB <f4exb06@gmail.com> Sun, 08 Jan 2017 23:14:18 +0100
sdrangel (3.0.1-1) unstable; urgency=medium
* Fixed audio preferences dialog and handling

View File

@ -7,8 +7,14 @@ if(LIBUSB_FOUND AND LIBBLADERF_FOUND)
add_subdirectory(bladerfoutput)
endif(LIBUSB_FOUND AND LIBBLADERF_FOUND)
find_package(LibHACKRF)
if(LIBUSB_FOUND AND LIBHACKRF_FOUND)
add_subdirectory(hackrfoutput)
endif(LIBUSB_FOUND AND LIBHACKRF_FOUND)
if (BUILD_DEBIAN)
add_subdirectory(bladerfoutput)
add_subdirectory(hackrfoutput)
endif (BUILD_DEBIAN)
add_subdirectory(filesink)

View File

@ -0,0 +1,73 @@
project(hackrfoutput)
set(hackrfoutput_SOURCES
hackrfoutputgui.cpp
hackrfoutput.cpp
hackrfoutputplugin.cpp
hackrfoutputsettings.cpp
hackrfoutputthread.cpp
)
set(hackrfoutput_HEADERS
hackrfoutputgui.h
hackrfoutput.h
hackrfoutputplugin.h
hackrfoutputsettings.h
hackrfoutputthread.h
)
set(hackrfoutput_FORMS
hackrfoutputgui.ui
)
if (BUILD_DEBIAN)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/devices
${LIBHACKRFSRC}
${LIBHACKRFSRC}/libhackrf/src
)
else (BUILD_DEBIAN)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/devices
${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(hackrfoutput_HEADERS_MOC ${hackrfoutput_HEADERS})
qt5_wrap_ui(hackrfoutput_FORMS_HEADERS ${hackrfoutput_FORMS})
add_library(outputhackrf SHARED
${hackrfoutput_SOURCES}
${hackrfoutput_HEADERS_MOC}
${hackrfoutput_FORMS_HEADERS}
)
if (BUILD_DEBIAN)
target_link_libraries(outputhackrf
${QT_LIBRARIES}
hackrf
sdrbase
hackrfdevice
)
else (BUILD_DEBIAN)
target_link_libraries(outputhackrf
${QT_LIBRARIES}
${LIBHACKRF_LIBRARIES}
sdrbase
hackrfdevice
)
endif (BUILD_DEBIAN)
qt5_use_modules(outputhackrf Core Widgets)
install(TARGETS outputhackrf DESTINATION lib/plugins/samplesink)

View File

@ -0,0 +1,415 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// 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 "hackrfoutput.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 "device/devicesinkapi.h"
#include "hackrfoutputgui.h"
#include "hackrfoutputthread.h"
MESSAGE_CLASS_DEFINITION(HackRFOutput::MsgConfigureHackRF, Message)
MESSAGE_CLASS_DEFINITION(HackRFOutput::MsgReportHackRF, Message)
HackRFOutput::HackRFOutput(DeviceSinkAPI *deviceAPI) :
m_deviceAPI(deviceAPI),
m_settings(),
m_dev(0),
m_hackRFThread(0),
m_deviceDescription("HackRFOutput")
{
m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
}
HackRFOutput::~HackRFOutput()
{
if (m_dev != 0)
{
stop();
}
m_deviceAPI->setBuddySharedPtr(0);
}
bool HackRFOutput::init(const Message& cmd)
{
return false;
}
bool HackRFOutput::start(int device)
{
// QMutexLocker mutexLocker(&m_mutex);
if (m_dev != 0)
{
stop();
}
// 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));
// }
m_sampleSourceFifo.resize(m_settings.m_devSampleRate); // 1s long
if (m_deviceAPI->getSourceBuddies().size() > 0)
{
DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[0];
DeviceHackRFParams *buddySharedParams = (DeviceHackRFParams *) buddy->getBuddySharedPtr();
if (buddySharedParams == 0)
{
qCritical("HackRFOutput::start: could not get shared parameters from buddy");
return false;
}
if (buddy->getDeviceSourceEngine()->state() == DSPDeviceSourceEngine::StRunning) // Rx side is running so it must have device ownership
{
if ((m_dev = buddySharedParams->m_dev) == 0) // get device handle from Rx but do not take ownership
{
qCritical("HackRFOutput::start: could not get HackRF handle from buddy");
return false;
}
}
else // Rx is not running so Tx opens device and takes ownership
{
if ((m_dev = DeviceHackRF::open_hackrf(device)) == 0)
{
qCritical("HackRFOutput::start: could not open HackRF #%d", device);
return false;
}
m_sharedParams.m_dev = m_dev;
}
}
else // No Rx part open so Tx opens device and takes ownership
{
if ((m_dev = DeviceHackRF::open_hackrf(device)) == 0)
{
qCritical("HackRFOutput::start: could not open HackRF #%d", device);
return false;
}
m_sharedParams.m_dev = m_dev;
}
if((m_hackRFThread = new HackRFOutputThread(m_dev, &m_sampleSourceFifo)) == 0)
{
qFatal("HackRFOutput::start: out of memory");
stop();
return false;
}
// mutexLocker.unlock();
applySettings(m_settings, true);
m_hackRFThread->startWork();
qDebug("HackRFOutput::start: started");
return true;
}
void HackRFOutput::stop()
{
qDebug("HackRFOutput::stop");
// QMutexLocker mutexLocker(&m_mutex);
if(m_hackRFThread != 0)
{
m_hackRFThread->stopWork();
delete m_hackRFThread;
m_hackRFThread = 0;
}
if(m_dev != 0)
{
hackrf_stop_tx(m_dev);
}
if (m_deviceAPI->getSourceBuddies().size() > 0)
{
DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[0];
DeviceHackRFParams *buddySharedParams = (DeviceHackRFParams *) buddy->getBuddySharedPtr();
if (buddy->getDeviceSourceEngine()->state() == DSPDeviceSourceEngine::StRunning) // Rx side running
{
if ((m_sharedParams.m_dev != 0) && (buddySharedParams->m_dev == 0)) // Tx has the ownership but not the Rx
{
buddySharedParams->m_dev = m_dev; // transfer ownership
}
}
else // Rx is not running so Tx must have the ownership
{
if(m_dev != 0) // close HackRF
{
hackrf_close(m_dev);
hackrf_exit(); // TODO: this may not work if several HackRF Devices are running concurrently. It should be handled globally in the application
}
}
}
else // No Rx part open
{
if(m_dev != 0) // close HackRF
{
hackrf_close(m_dev);
hackrf_exit(); // TODO: this may not work if several HackRF Devices are running concurrently. It should be handled globally in the application
}
}
m_sharedParams.m_dev = 0;
m_dev = 0;
}
const QString& HackRFOutput::getDeviceDescription() const
{
return m_deviceDescription;
}
int HackRFOutput::getSampleRate() const
{
int rate = m_settings.m_devSampleRate;
return (rate / (1<<m_settings.m_log2Interp));
}
quint64 HackRFOutput::getCenterFrequency() const
{
return m_settings.m_centerFrequency;
}
bool HackRFOutput::handleMessage(const Message& message)
{
if (MsgConfigureHackRF::match(message))
{
MsgConfigureHackRF& conf = (MsgConfigureHackRF&) message;
qDebug() << "HackRFOutput::handleMessage: MsgConfigureHackRF";
bool success = applySettings(conf.getSettings(), false);
if (!success)
{
qDebug("HackRFOutput::handleMessage: config error");
}
return true;
}
else
{
return false;
}
}
void HackRFOutput::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("HackRFOutput::setCenterFrequency: could not frequency to %llu Hz", freq_hz);
}
else
{
qWarning("HackRFOutput::setCenterFrequency: frequency set to %llu Hz", freq_hz);
}
}
bool HackRFOutput::applySettings(const HackRFOutputSettings& settings, bool force)
{
// QMutexLocker mutexLocker(&m_mutex);
bool forwardChange = false;
hackrf_error rc;
qDebug() << "HackRFOutput::applySettings";
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force)
{
m_settings.m_devSampleRate = settings.m_devSampleRate;
forwardChange = true;
if (m_dev != 0)
{
rc = (hackrf_error) hackrf_set_sample_rate_manual(m_dev, m_settings.m_devSampleRate, 1);
if (rc != HACKRF_SUCCESS)
{
qCritical("HackRFOutput::applySettings: could not set sample rate to %d S/s: %s",
m_settings.m_devSampleRate,
hackrf_error_name(rc));
}
else
{
qDebug("HackRFOutput::applySettings: sample rate set to %d S/s",
m_settings.m_devSampleRate);
m_hackRFThread->setSamplerate(m_settings.m_devSampleRate);
}
}
}
if ((m_settings.m_log2Interp != settings.m_log2Interp) || force)
{
m_settings.m_log2Interp = settings.m_log2Interp;
forwardChange = true;
if(m_dev != 0)
{
m_hackRFThread->setLog2Interpolation(m_settings.m_log2Interp);
qDebug() << "HackRFOutput: set interpolation to " << (1<<m_settings.m_log2Interp);
}
}
quint32 devSampleRate = m_settings.m_devSampleRate;
if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency) ||
(m_settings.m_LOppmTenths != settings.m_LOppmTenths))
{
m_settings.m_centerFrequency = settings.m_centerFrequency;
m_settings.m_LOppmTenths = settings.m_LOppmTenths;
if (m_dev != 0)
{
setCenterFrequency(m_settings.m_centerFrequency);
qDebug() << "HackRFOutput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz"
<< " device sample rate: " << devSampleRate << "Hz"
<< " Actual sample rate: " << devSampleRate/(1<<m_settings.m_log2Interp) << "Hz";
}
forwardChange = true;
}
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("HackRFOutput::applySettings: hackrf_set_vga_gain failed: %s", hackrf_error_name(rc));
}
else
{
qDebug() << "HackRFOutput:applySettings: VGA gain set to " << m_settings.m_vgaGain;
}
}
}
if ((m_settings.m_txvgaGain != settings.m_txvgaGain) || force)
{
m_settings.m_txvgaGain = settings.m_txvgaGain;
if (m_dev != 0)
{
rc = (hackrf_error) hackrf_set_txvga_gain(m_dev, m_settings.m_txvgaGain);
if (rc != HACKRF_SUCCESS)
{
qDebug("HackRFOutput::applySettings: hackrf_set_txvga_gain failed: %s", hackrf_error_name(rc));
}
else
{
qDebug() << "HackRFOutput:applySettings: TxVGA gain set to " << m_settings.m_txvgaGain;
}
}
}
if ((m_settings.m_bandwidth != settings.m_bandwidth) || force)
{
m_settings.m_bandwidth = settings.m_bandwidth;
if (m_dev != 0)
{
uint32_t bw_index = hackrf_compute_baseband_filter_bw_round_down_lt(m_settings.m_bandwidth);
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 " << m_settings.m_bandwidth << " Hz";
}
}
}
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_log2Interp);
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency);
m_deviceAPI->getDeviceInputMessageQueue()->push(notif);
}
return true;
}

View File

@ -0,0 +1,98 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// 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_HACKRFOUTPUT_H
#define INCLUDE_HACKRFOUTPUT_H
#include "dsp/devicesamplesink.h"
#include "libhackrf/hackrf.h"
#include <QString>
#include "hackrf/devicehackrf.h"
#include "hackrf/devicehackrfparam.h"
#include "hackrfoutputsettings.h"
class DeviceSinkAPI;
class HackRFOutputThread;
class HackRFOutput : public DeviceSampleSink {
public:
class MsgConfigureHackRF : public Message {
MESSAGE_CLASS_DECLARATION
public:
const HackRFOutputSettings& getSettings() const { return m_settings; }
static MsgConfigureHackRF* create(const HackRFOutputSettings& settings)
{
return new MsgConfigureHackRF(settings);
}
private:
HackRFOutputSettings m_settings;
MsgConfigureHackRF(const HackRFOutputSettings& settings) :
Message(),
m_settings(settings)
{ }
};
class MsgReportHackRF : public Message {
MESSAGE_CLASS_DECLARATION
public:
static MsgReportHackRF* create()
{
return new MsgReportHackRF();
}
protected:
MsgReportHackRF() :
Message()
{ }
};
HackRFOutput(DeviceSinkAPI *deviceAPI);
virtual ~HackRFOutput();
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 HackRFOutputSettings& settings, bool force);
// hackrf_device *open_hackrf_from_sequence(int sequence);
void setCenterFrequency(quint64 freq);
DeviceSinkAPI *m_deviceAPI;
QMutex m_mutex;
HackRFOutputSettings m_settings;
struct hackrf_device* m_dev;
HackRFOutputThread* m_hackRFThread;
QString m_deviceDescription;
DeviceHackRFParams m_sharedParams;
};
#endif // INCLUDE_HACKRFINPUT_H

View File

@ -0,0 +1,358 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// 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 "hackrfoutputgui.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/devicesinkapi.h"
#include "hackrf/devicehackrfvalues.h"
#include "ui_hackrfoutputgui.h"
HackRFOutputGui::HackRFOutputGui(DeviceSinkAPI *deviceAPI, QWidget* parent) :
QWidget(parent),
ui(new Ui::HackRFOutputGui),
m_deviceAPI(deviceAPI),
m_settings(),
m_deviceSampleSink(0),
m_lastEngineState((DSPDeviceSinkEngine::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_deviceSampleSink = new HackRFOutput(m_deviceAPI);
displaySampleRates();
displayBandwidths();
m_deviceAPI->setSink(m_deviceSampleSink);
connect(m_deviceAPI->getDeviceOutputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleDSPMessages()), Qt::QueuedConnection);
}
HackRFOutputGui::~HackRFOutputGui()
{
delete m_deviceSampleSink; // Valgrind memcheck
delete ui;
}
void HackRFOutputGui::destroy()
{
delete this;
}
void HackRFOutputGui::setName(const QString& name)
{
setObjectName(name);
}
QString HackRFOutputGui::getName() const
{
return objectName();
}
void HackRFOutputGui::resetToDefaults()
{
m_settings.resetToDefaults();
displaySettings();
sendSettings();
}
qint64 HackRFOutputGui::getCenterFrequency() const
{
return m_settings.m_centerFrequency;
}
void HackRFOutputGui::setCenterFrequency(qint64 centerFrequency)
{
m_settings.m_centerFrequency = centerFrequency;
displaySettings();
sendSettings();
}
QByteArray HackRFOutputGui::serialize() const
{
return m_settings.serialize();
}
bool HackRFOutputGui::deserialize(const QByteArray& data)
{
if(m_settings.deserialize(data))
{
displaySettings();
sendSettings();
return true;
}
else
{
resetToDefaults();
return false;
}
}
bool HackRFOutputGui::handleMessage(const Message& message)
{
if (HackRFOutput::MsgReportHackRF::match(message))
{
displaySettings();
return true;
}
else
{
return false;
}
}
void HackRFOutputGui::handleDSPMessages()
{
Message* message;
while ((message = m_deviceAPI->getDeviceOutputMessageQueue()->pop()) != 0)
{
qDebug("HackRFOutputGui::handleDSPMessages: message: %s", message->getIdentifier());
if (DSPSignalNotification::match(*message))
{
DSPSignalNotification* notif = (DSPSignalNotification*) message;
m_sampleRate = notif->getSampleRate();
m_deviceCenterFrequency = notif->getCenterFrequency();
qDebug("HackRFOutputGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
updateSampleRateAndFrequency();
delete message;
}
}
}
void HackRFOutputGui::updateSampleRateAndFrequency()
{
m_deviceAPI->getSpectrum()->setSampleRate(m_sampleRate);
m_deviceAPI->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency);
ui->deviceRateText->setText(tr("%1k").arg((float)m_sampleRate / 1000));
}
void HackRFOutputGui::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)));
unsigned int sampleRateIndex = HackRFSampleRates::getRateIndex(m_settings.m_devSampleRate/1000);
ui->sampleRate->setCurrentIndex(sampleRateIndex);
ui->biasT->setChecked(m_settings.m_biasT);
ui->interp->setCurrentIndex(m_settings.m_log2Interp);
ui->lnaExt->setChecked(m_settings.m_lnaExt);
ui->vgaGainText->setText(tr("%1dB").arg(m_settings.m_vgaGain));
ui->vga->setValue(m_settings.m_vgaGain);
unsigned int bandwidthIndex = HackRFBandwidths::getBandwidthIndex(m_settings.m_bandwidth/1000);
ui->bbFilter->setCurrentIndex(bandwidthIndex);
ui->txvgaGainText->setText(tr("%1dB").arg(m_settings.m_txvgaGain));
ui->txvga->setValue(m_settings.m_txvgaGain);
}
void HackRFOutputGui::displaySampleRates()
{
int savedIndex = HackRFSampleRates::getRateIndex(m_settings.m_devSampleRate/1000);
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 HackRFOutputGui::displayBandwidths()
{
int savedIndex = HackRFBandwidths::getBandwidthIndex(m_settings.m_bandwidth/1000);
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 HackRFOutputGui::sendSettings()
{
if(!m_updateTimer.isActive())
m_updateTimer.start(100);
}
void HackRFOutputGui::on_centerFrequency_changed(quint64 value)
{
m_settings.m_centerFrequency = value * 1000;
sendSettings();
}
void HackRFOutputGui::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 HackRFOutputGui::on_sampleRate_currentIndexChanged(int index)
{
int newrate = HackRFSampleRates::getRate(index);
m_settings.m_devSampleRate = newrate * 1000;
sendSettings();
}
void HackRFOutputGui::on_bbFilter_currentIndexChanged(int index)
{
int newBandwidth = HackRFBandwidths::getBandwidth(index);
m_settings.m_bandwidth = newBandwidth * 1000;
sendSettings();
}
void HackRFOutputGui::on_biasT_stateChanged(int state)
{
m_settings.m_biasT = (state == Qt::Checked);
sendSettings();
}
void HackRFOutputGui::on_lnaExt_stateChanged(int state)
{
m_settings.m_lnaExt = (state == Qt::Checked);
sendSettings();
}
void HackRFOutputGui::on_interp_currentIndexChanged(int index)
{
if ((index <0) || (index > 6))
return;
m_settings.m_log2Interp = index;
sendSettings();
}
void HackRFOutputGui::on_vga_valueChanged(int value)
{
if ((value < 0) || (value > 62))
return;
ui->vgaGainText->setText(tr("%1dB").arg(value));
m_settings.m_vgaGain = value;
sendSettings();
}
void HackRFOutputGui::on_txvga_valueChanged(int value)
{
if ((value < 0) || (value > 47))
return;
ui->txvgaGainText->setText(tr("%1dB").arg(value));
m_settings.m_vgaGain = value;
sendSettings();
}
void HackRFOutputGui::on_startStop_toggled(bool checked)
{
if (checked)
{
if (m_deviceAPI->initGeneration())
{
m_deviceAPI->startGeneration();
DSPEngine::instance()->startAudioOutput();
}
}
else
{
m_deviceAPI->stopGeneration();
DSPEngine::instance()->stopAudioOutput();
}
}
void HackRFOutputGui::updateHardware()
{
qDebug() << "HackRFOutputGui::updateHardware";
HackRFOutput::MsgConfigureHackRF* message = HackRFOutput::MsgConfigureHackRF::create(m_settings);
m_deviceSampleSink->getInputMessageQueue()->push(message);
m_updateTimer.stop();
}
void HackRFOutputGui::updateStatus()
{
int state = m_deviceAPI->state();
if(m_lastEngineState != state)
{
switch(state)
{
case DSPDeviceSinkEngine::StNotStarted:
ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
break;
case DSPDeviceSinkEngine::StIdle:
ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
break;
case DSPDeviceSinkEngine::StRunning:
ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
break;
case DSPDeviceSinkEngine::StError:
ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
QMessageBox::information(this, tr("Message"), m_deviceAPI->errorMessage());
break;
default:
break;
}
m_lastEngineState = state;
}
}

View File

@ -0,0 +1,94 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// 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_HACKRFOUTPUTGUI_H
#define INCLUDE_HACKRFOUTPUTGUI_H
#include <QTimer>
#include "plugin/plugingui.h"
#include "hackrfoutput.h"
#define HACKRF_MAX_DEVICE (32)
class DeviceSinkAPI;
class DeviceSampleSink;
namespace Ui {
class HackRFOutputGui;
}
class HackRFOutputGui : public QWidget, public PluginGUI {
Q_OBJECT
public:
typedef enum
{
HACKRF_IMGREJ_BYPASS = 0,
HACKRF_IMGREJ_LOWPASS,
HACKRF_IMGREJ_HIGHPASS,
HACKRF_IMGREJ_NB
} HackRFImgRejValue;
explicit HackRFOutputGui(DeviceSinkAPI *deviceAPI, QWidget* parent = NULL);
virtual ~HackRFOutputGui();
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::HackRFOutputGui* ui;
DeviceSinkAPI* m_deviceAPI;
HackRFOutputSettings m_settings;
QTimer m_updateTimer;
QTimer m_statusTimer;
DeviceSampleSink* m_deviceSampleSink;
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_sampleRate_currentIndexChanged(int index);
void on_biasT_stateChanged(int state);
void on_interp_currentIndexChanged(int index);
void on_lnaExt_stateChanged(int state);
void on_vga_valueChanged(int value);
void on_bbFilter_currentIndexChanged(int index);
void on_txvga_valueChanged(int value);
void on_startStop_toggled(bool checked);
void updateHardware();
void updateStatus();
};
#endif // INCLUDE_HACKRFOUTPUTGUI_H

View File

@ -0,0 +1,512 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HackRFOutputGui</class>
<widget class="QWidget" name="HackRFOutputGui">
<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="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_freq">
<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>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="deviceRateLayout">
<item>
<widget class="QLabel" name="deviceRateText">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<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>
<widget class="Line" name="line_freq">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_corr">
<item row="0" column="0">
<widget class="QLabel" name="label_interp">
<property name="text">
<string>Int</string>
</property>
</widget>
</item>
<item row="0" column="3">
<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="4">
<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="2">
<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="1">
<widget class="QComboBox" name="interp">
<property name="maximumSize">
<size>
<width>55</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Decimation factor</string>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
</widget>
</item>
</layout>
</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>
<widget class="Line" name="line_fcPos">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_vga">
<property name="spacing">
<number>3</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="vgaGainLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>42</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>VGA</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="vga">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>LNA 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>30</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="vgaGainText">
<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_txvga" columnstretch="0,0,0">
<property name="spacing">
<number>3</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="txvgaGainLabel">
<property name="minimumSize">
<size>
<width>42</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>TxVGA</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="txvga">
<property name="toolTip">
<string>VGA gain dB</string>
</property>
<property name="maximum">
<number>47</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>22</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="txvgaGainText">
<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>

View File

@ -0,0 +1,131 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// 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 "hackrfoutputplugin.h"
#include <QtPlugin>
#include <QAction>
#include "libhackrf/hackrf.h"
#include "device/devicesourceapi.h"
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
#include "hackrfoutputgui.h"
const PluginDescriptor HackRFOutputPlugin::m_pluginDescriptor = {
QString("HackRF Output"),
QString("3.1.0"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,
QString("https://github.com/f4exb/sdrangel")
};
const QString HackRFOutputPlugin::m_hardwareID = "HackRF";
const QString HackRFOutputPlugin::m_deviceTypeID = HACKRFOUTPUT_DEVICE_TYPE_ID;
HackRFOutputPlugin::HackRFOutputPlugin(QObject* parent) :
QObject(parent)
{
}
const PluginDescriptor& HackRFOutputPlugin::getPluginDescriptor() const
{
return m_pluginDescriptor;
}
void HackRFOutputPlugin::initPlugin(PluginAPI* pluginAPI)
{
pluginAPI->registerSampleSink(m_deviceTypeID, this);
}
PluginInterface::SamplingDevices HackRFOutputPlugin::enumSampleSinks()
{
hackrf_error rc = (hackrf_error) hackrf_init();
if (rc != HACKRF_SUCCESS)
{
qCritical("HackRFOutputPlugin::enumSampleSinks: 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("HackRFOutputPlugin::enumSampleSinks: 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("HackRFOutputPlugin::enumSampleSinks: 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_hardwareID,
m_deviceTypeID,
serial_str,
i));
qDebug("HackRFOutputPlugin::enumSampleSinks: enumerated HackRF device #%d", i);
hackrf_close(hackrf_ptr);
}
else
{
qDebug("HackRFOutputPlugin::enumSampleSinks: failed to enumerate HackRF device #%d: %s", i, hackrf_error_name(rc));
}
}
hackrf_device_list_free(hackrf_devices);
rc = (hackrf_error) hackrf_exit();
qDebug("HackRFOutputPlugin::enumSampleSinks: hackrf_exit: %s", hackrf_error_name(rc));
return result;
}
PluginGUI* HackRFOutputPlugin::createSampleSinkPluginGUI(const QString& sinkId, QWidget **widget, DeviceSinkAPI *deviceAPI)
{
if(sinkId == m_deviceTypeID)
{
HackRFOutputGui* gui = new HackRFOutputGui(deviceAPI);
*widget = gui;
return gui;
}
else
{
return 0;
}
}

View File

@ -0,0 +1,48 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// 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_HACKRFOUTPUTPLUGIN_H
#define INCLUDE_HACKRFOUTPUTPLUGIN_H
#include <QObject>
#include "plugin/plugininterface.h"
#define HACKRFOUTPUT_DEVICE_TYPE_ID "sdrangel.samplesource.hackrfoutput"
class PluginAPI;
class HackRFOutputPlugin : public QObject, public PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)
Q_PLUGIN_METADATA(IID HACKRFOUTPUT_DEVICE_TYPE_ID)
public:
explicit HackRFOutputPlugin(QObject* parent = NULL);
const PluginDescriptor& getPluginDescriptor() const;
void initPlugin(PluginAPI* pluginAPI);
virtual SamplingDevices enumSampleSinks();
virtual PluginGUI* createSampleSinkPluginGUI(const QString& sinkId, QWidget **widget, DeviceSinkAPI *deviceAPI);
static const QString m_hardwareID;
static const QString m_deviceTypeID;
private:
static const PluginDescriptor m_pluginDescriptor;
};
#endif // INCLUDE_HACKRFOUTPUTPLUGIN_H

View File

@ -0,0 +1,87 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// 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 "hackrfoutputsettings.h"
#include <QtGlobal>
#include "util/simpleserializer.h"
HackRFOutputSettings::HackRFOutputSettings()
{
resetToDefaults();
}
void HackRFOutputSettings::resetToDefaults()
{
m_centerFrequency = 435000 * 1000;
m_LOppmTenths = 0;
m_devSampleRate = 2400000;
m_biasT = false;
m_log2Interp = 0;
m_lnaExt = false;
m_vgaGain = 30;
m_bandwidth = 1750000;
m_txvgaGain = 22;
}
QByteArray HackRFOutputSettings::serialize() const
{
SimpleSerializer s(1);
s.writeS32(1, m_LOppmTenths);
s.writeU32(2, m_devSampleRate);
s.writeBool(3, m_biasT);
s.writeU32(4, m_log2Interp);
s.writeBool(5, m_lnaExt);
s.writeU32(6, m_vgaGain);
s.writeU32(7, m_bandwidth);
s.writeU32(8, m_txvgaGain);
return s.final();
}
bool HackRFOutputSettings::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_devSampleRate, 2400000);
d.readBool(3, &m_biasT, false);
d.readU32(4, &m_log2Interp, 0);
d.readBool(5, &m_lnaExt, false);
d.readU32(6, &m_vgaGain, 30);
d.readU32(7, &m_bandwidth, 1750000);
d.readU32(8, &m_txvgaGain, 22);
return true;
}
else
{
resetToDefaults();
return false;
}
}

View File

@ -0,0 +1,39 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// 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_HACKRFOUTPUTSETTINGS_H_
#define _HACKRF_HACKRFOUTPUTSETTINGS_H_
#include <QtGlobal>
struct HackRFOutputSettings {
quint64 m_centerFrequency;
qint32 m_LOppmTenths;
quint32 m_devSampleRate;
quint32 m_bandwidth;
quint32 m_vgaGain;
quint32 m_txvgaGain;
quint32 m_log2Interp;
bool m_biasT;
bool m_lnaExt;
HackRFOutputSettings();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
#endif /* _HACKRF_HACKRFOUTPUTSETTINGS_H_ */

View File

@ -0,0 +1,152 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// 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 "hackrfoutputthread.h"
#include <stdio.h>
#include <errno.h>
#include "dsp/samplesourcefifo.h"
HackRFOutputThread *HackRFOutputThread::m_this = 0;
HackRFOutputThread::HackRFOutputThread(hackrf_device* dev, SampleSourceFifo* sampleFifo, QObject* parent) :
QThread(parent),
m_running(false),
m_dev(dev),
m_convertBuffer(HACKRF_BLOCKSIZE),
m_sampleFifo(sampleFifo),
m_samplerate(10),
m_log2Interp(0)
{
m_this = this;
}
HackRFOutputThread::~HackRFOutputThread()
{
stopWork();
m_this = 0;
}
void HackRFOutputThread::startWork()
{
//m_startWaitMutex.lock();
m_running = true;
start();
/*
while(!m_running)
m_startWaiter.wait(&m_startWaitMutex, 100);
m_startWaitMutex.unlock();*/
}
void HackRFOutputThread::stopWork()
{
qDebug("HackRFOutputThread::stopWork");
m_running = false;
wait();
}
void HackRFOutputThread::setSamplerate(uint32_t samplerate)
{
m_samplerate = samplerate;
}
void HackRFOutputThread::setLog2Interpolation(unsigned int log2Interp)
{
m_log2Interp = log2Interp;
}
void HackRFOutputThread::run()
{
hackrf_error rc;
//m_running = true;
m_startWaiter.wakeAll();
rc = (hackrf_error) hackrf_start_tx(m_dev, tx_callback, NULL);
if (rc != HACKRF_SUCCESS)
{
qCritical("HackRFOutputThread::run: failed to start HackRF Tx: %s", hackrf_error_name(rc));
}
else
{
while ((m_running) && (hackrf_is_streaming(m_dev) == HACKRF_TRUE))
{
sleep(1);
}
}
rc = (hackrf_error) hackrf_stop_tx(m_dev);
if (rc == HACKRF_SUCCESS)
{
qDebug("HackRFOutputThread::run: stopped HackRF Tx");
}
else
{
qDebug("HackRFOutputThread::run: failed to stop HackRF Tx: %s", hackrf_error_name(rc));
}
//m_running = false;
}
// Interpolate according to specified log2 (ex: log2=4 => interp=16)
void HackRFOutputThread::callback(qint16* buf, qint32 len)
{
SampleVector::iterator beginRead;
m_sampleFifo->readAdvance(beginRead, len/(1<<m_log2Interp));
beginRead -= len;
if (m_log2Interp == 0)
{
m_interpolators.interpolate1(&beginRead, buf, len*2);
}
else
{
switch (m_log2Interp)
{
case 1:
m_interpolators.interpolate2_cen(&beginRead, buf, len*2);
break;
case 2:
m_interpolators.interpolate4_cen(&beginRead, buf, len*2);
break;
case 3:
m_interpolators.interpolate8_cen(&beginRead, buf, len*2);
break;
case 4:
m_interpolators.interpolate16_cen(&beginRead, buf, len*2);
break;
case 5:
m_interpolators.interpolate32_cen(&beginRead, buf, len*2);
break;
case 6:
m_interpolators.interpolate64_cen(&beginRead, buf, len*2);
break;
default:
break;
}
}
}
int HackRFOutputThread::tx_callback(hackrf_transfer* transfer)
{
qint32 bytes_to_write = transfer->valid_length;
m_this->callback((qint16 *) transfer->buffer, bytes_to_write);
return 0;
}

View File

@ -0,0 +1,63 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// 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_HACKRFOUTPUTTHREAD_H
#define INCLUDE_HACKRFOUTPUTTHREAD_H
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <libhackrf/hackrf.h>
#include "dsp/samplesourcefifo.h"
#include "dsp/interpolators.h"
#define HACKRF_BLOCKSIZE (1<<17)
class HackRFOutputThread : public QThread {
Q_OBJECT
public:
HackRFOutputThread(hackrf_device* dev, SampleSourceFifo* sampleFifo, QObject* parent = NULL);
~HackRFOutputThread();
void startWork();
void stopWork();
void setSamplerate(uint32_t samplerate);
void setLog2Interpolation(unsigned int log2_interp);
private:
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
bool m_running;
hackrf_device* m_dev;
qint16 m_buf[2*HACKRF_BLOCKSIZE];
SampleVector m_convertBuffer;
SampleSourceFifo* m_sampleFifo;
int m_samplerate;
unsigned int m_log2Interp;
static HackRFOutputThread *m_this;
Interpolators<qint16, SDR_SAMP_SZ, 12> m_interpolators;
void run();
void callback(qint16* buf, qint32 len);
static int tx_callback(hackrf_transfer* transfer);
};
#endif // INCLUDE_HACKRFOUTPUTTHREAD_H

View File

@ -278,12 +278,12 @@ bool HackRFInput::applySettings(const HackRFInputSettings& settings, bool force)
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force)
{
forwardChange = true;
m_settings.m_devSampleRate = settings.m_devSampleRate;
m_settings.m_devSampleRate = settings.m_devSampleRate;
forwardChange = true;
if (m_dev != 0)
if (m_dev != 0)
{
rc = (hackrf_error) hackrf_set_sample_rate_manual(m_dev, m_settings.m_devSampleRate, 1);
rc = (hackrf_error) hackrf_set_sample_rate_manual(m_dev, m_settings.m_devSampleRate, 1);
if (rc != HACKRF_SUCCESS)
{
@ -404,9 +404,11 @@ bool HackRFInput::applySettings(const HackRFInputSettings& settings, bool force)
if ((m_settings.m_bandwidth != settings.m_bandwidth) || force)
{
if (m_dev != 0)
m_settings.m_bandwidth = settings.m_bandwidth;
if (m_dev != 0)
{
uint32_t bw_index = hackrf_compute_baseband_filter_bw_round_down_lt(m_settings.m_bandwidth);
uint32_t bw_index = hackrf_compute_baseband_filter_bw_round_down_lt(m_settings.m_bandwidth);
rc = (hackrf_error) hackrf_set_baseband_filter_bandwidth(m_dev, bw_index);
if (rc != HACKRF_SUCCESS)

View File

@ -29,7 +29,7 @@
const PluginDescriptor HackRFInputPlugin::m_pluginDescriptor = {
QString("HackRF Input"),
QString("3.0.0"),
QString("3.1.0"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,

View File

@ -84,7 +84,7 @@
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Version 3.0.1 - Copyright (C) 2015-2017 Edouard Griffiths, F4EXB. &lt;/p&gt;&lt;p&gt;Code at &lt;a href=&quot;https://github.com/f4exb/sdrangel&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;https://github.com/f4exb/sdrangel&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Many thanks to the original developers:&lt;/p&gt;&lt;p&gt;The osmocom developer team - especially horizon, Hoernchen &amp;amp; tnt.&lt;/p&gt;&lt;p&gt;Christian Daniel from maintech GmbH.&lt;/p&gt;&lt;p&gt;John Greb (hexameron) for the contributions in &lt;a href=&quot;https://github.com/hexameron/rtl-sdrangelove&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;RTL-SDRangelove&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The following rules apply to the SDRangel main application and libsdrbase:&lt;br/&gt;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; either version 2 of the License, or (at your option) any later version. 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. You should have received a copy of the GNU General Public License along with this program. If not, see &lt;a href=&quot;http://www.gnu.org/licenses/&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;http://www.gnu.org/licenses/&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;For the license of installed plugins, look into the plugin list.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Version 3.1,0 - Copyright (C) 2015-2017 Edouard Griffiths, F4EXB. &lt;/p&gt;&lt;p&gt;Code at &lt;a href=&quot;https://github.com/f4exb/sdrangel&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;https://github.com/f4exb/sdrangel&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Many thanks to the original developers:&lt;/p&gt;&lt;p&gt;The osmocom developer team - especially horizon, Hoernchen &amp;amp; tnt.&lt;/p&gt;&lt;p&gt;Christian Daniel from maintech GmbH.&lt;/p&gt;&lt;p&gt;John Greb (hexameron) for the contributions in &lt;a href=&quot;https://github.com/hexameron/rtl-sdrangelove&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;RTL-SDRangelove&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The following rules apply to the SDRangel main application and libsdrbase:&lt;br/&gt;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; either version 2 of the License, or (at your option) any later version. 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. You should have received a copy of the GNU General Public License along with this program. If not, see &lt;a href=&quot;http://www.gnu.org/licenses/&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;http://www.gnu.org/licenses/&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;For the license of installed plugins, look into the plugin list.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -454,9 +454,9 @@ void MainWindow::createStatusBar()
{
QString qtVersionStr = QString("Qt %1 ").arg(QT_VERSION_STR);
#if QT_VERSION >= 0x050400
m_showSystemWidget = new QLabel("SDRangel v3.0.1 " + qtVersionStr + QSysInfo::prettyProductName(), this);
m_showSystemWidget = new QLabel("SDRangel v3.1.0 " + qtVersionStr + QSysInfo::prettyProductName(), this);
#else
m_showSystemWidget = new QLabel("SDRangel v3.0.1 " + qtVersionStr, this);
m_showSystemWidget = new QLabel("SDRangel v3.1.0 " + qtVersionStr, this);
#endif
statusBar()->addPermanentWidget(m_showSystemWidget);