1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 10:05:46 -05:00
sdrangel/plugins/samplesink/bladerf1output/bladerf1outputgui.cpp

485 lines
14 KiB
C++
Raw Normal View History

///////////////////////////////////////////////////////////////////////////////////
// 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 //
2019-04-11 00:39:30 -04:00
// (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. 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 <QDebug>
#include <QMessageBox>
#include <libbladeRF.h>
#include "ui_bladerf1outputgui.h"
#include "gui/colormapper.h"
#include "gui/glspectrum.h"
2018-12-26 13:22:52 -05:00
#include "gui/crightclickenabler.h"
#include "gui/basicdevicesettingsdialog.h"
#include "dsp/dspengine.h"
#include "dsp/dspcommands.h"
2019-05-08 16:11:53 -04:00
#include "device/deviceapi.h"
#include "device/deviceuiset.h"
#include "bladerf1outputgui.h"
Bladerf1OutputGui::Bladerf1OutputGui(DeviceUISet *deviceUISet, QWidget* parent) :
QWidget(parent),
ui(new Ui::Bladerf1OutputGui),
m_deviceUISet(deviceUISet),
m_doApplySettings(true),
m_forceSettings(true),
m_settings(),
m_sampleRateMode(true),
m_deviceSampleSink(nullptr),
m_sampleRate(0),
2019-05-08 16:11:53 -04:00
m_lastEngineState(DeviceAPI::StNotStarted)
{
2019-05-08 16:11:53 -04:00
m_deviceSampleSink = (Bladerf1Output*) m_deviceUISet->m_deviceAPI->getSampleSink();
ui->setupUi(this);
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
ui->centerFrequency->setValueRange(7, BLADERF_FREQUENCY_MIN_XB200/1000, BLADERF_FREQUENCY_MAX/1000);
ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow));
ui->sampleRate->setValueRange(8, BLADERF_SAMPLERATE_MIN, BLADERF_SAMPLERATE_REC_MAX);
ui->bandwidth->clear();
2017-05-25 14:13:34 -04:00
for (unsigned int i = 0; i < BladerfBandwidths::getNbBandwidths(); i++)
{
ui->bandwidth->addItem(QString::number(BladerfBandwidths::getBandwidth(i)));
}
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
m_statusTimer.start(500);
2018-12-26 13:22:52 -05:00
CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
displaySettings();
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
}
Bladerf1OutputGui::~Bladerf1OutputGui()
{
delete ui;
}
void Bladerf1OutputGui::destroy()
{
delete this;
}
void Bladerf1OutputGui::setName(const QString& name)
{
setObjectName(name);
}
QString Bladerf1OutputGui::getName() const
{
return objectName();
}
void Bladerf1OutputGui::resetToDefaults()
{
m_settings.resetToDefaults();
displaySettings();
sendSettings();
}
qint64 Bladerf1OutputGui::getCenterFrequency() const
{
return m_settings.m_centerFrequency;
}
void Bladerf1OutputGui::setCenterFrequency(qint64 centerFrequency)
{
m_settings.m_centerFrequency = centerFrequency;
displaySettings();
sendSettings();
}
QByteArray Bladerf1OutputGui::serialize() const
{
return m_settings.serialize();
}
bool Bladerf1OutputGui::deserialize(const QByteArray& data)
{
if(m_settings.deserialize(data)) {
displaySettings();
m_forceSettings = true;
sendSettings();
return true;
} else {
resetToDefaults();
return false;
}
}
bool Bladerf1OutputGui::handleMessage(const Message& message)
{
if (Bladerf1Output::MsgConfigureBladerf1::match(message))
{
const Bladerf1Output::MsgConfigureBladerf1& cfg = (Bladerf1Output::MsgConfigureBladerf1&) message;
m_settings = cfg.getSettings();
blockApplySettings(true);
displaySettings();
blockApplySettings(false);
return true;
}
else if (Bladerf1Output::MsgReportBladerf1::match(message))
{
displaySettings();
return true;
}
else if (Bladerf1Output::MsgStartStop::match(message))
{
Bladerf1Output::MsgStartStop& notif = (Bladerf1Output::MsgStartStop&) message;
blockApplySettings(true);
ui->startStop->setChecked(notif.getStartStop());
blockApplySettings(false);
return true;
}
else
{
return false;
}
}
void Bladerf1OutputGui::handleInputMessages()
{
Message* message;
while ((message = m_inputMessageQueue.pop()) != 0)
{
qDebug("BladerfOutputGui::handleInputMessages: message: %s", message->getIdentifier());
if (DSPSignalNotification::match(*message))
{
DSPSignalNotification* notif = (DSPSignalNotification*) message;
m_sampleRate = notif->getSampleRate();
m_deviceCenterFrequency = notif->getCenterFrequency();
qDebug("BladerfOutputGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
updateSampleRateAndFrequency();
delete message;
}
else
{
if (handleMessage(*message))
{
delete message;
}
}
}
}
void Bladerf1OutputGui::updateSampleRateAndFrequency()
{
m_deviceUISet->getSpectrum()->setSampleRate(m_sampleRate);
m_deviceUISet->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency);
displaySampleRate();
}
void Bladerf1OutputGui::displaySampleRate()
{
ui->sampleRate->blockSignals(true);
if (m_sampleRateMode)
{
ui->sampleRateMode->setStyleSheet("QToolButton { background:rgb(60,60,60); }");
ui->sampleRateMode->setText("SR");
ui->sampleRate->setValueRange(8, BLADERF_SAMPLERATE_MIN, BLADERF_SAMPLERATE_REC_MAX);
ui->sampleRate->setValue(m_settings.m_devSampleRate);
ui->sampleRate->setToolTip("Host to device sample rate (S/s)");
ui->deviceRateText->setToolTip("Baseband sample rate (S/s)");
uint32_t basebandSampleRate = m_settings.m_devSampleRate/(1<<m_settings.m_log2Interp);
ui->deviceRateText->setText(tr("%1k").arg(QString::number(basebandSampleRate / 1000.0f, 'g', 5)));
}
else
{
ui->sampleRateMode->setStyleSheet("QToolButton { background:rgb(50,50,50); }");
ui->sampleRateMode->setText("BB");
ui->sampleRate->setValueRange(8, BLADERF_SAMPLERATE_MIN/(1<<m_settings.m_log2Interp), BLADERF_SAMPLERATE_REC_MAX/(1<<m_settings.m_log2Interp));
ui->sampleRate->setValue(m_settings.m_devSampleRate/(1<<m_settings.m_log2Interp));
ui->sampleRate->setToolTip("Baseband sample rate (S/s)");
ui->deviceRateText->setToolTip("Host to device sample rate (S/s)");
ui->deviceRateText->setText(tr("%1k").arg(QString::number(m_settings.m_devSampleRate / 1000.0f, 'g', 5)));
}
ui->sampleRate->blockSignals(false);
}
void Bladerf1OutputGui::displaySettings()
{
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
displaySampleRate();
unsigned int bandwidthIndex = BladerfBandwidths::getBandwidthIndex(m_settings.m_bandwidth);
ui->bandwidth->setCurrentIndex(bandwidthIndex);
ui->interp->setCurrentIndex(m_settings.m_log2Interp);
ui->vga1Text->setText(tr("%1dB").arg(m_settings.m_vga1));
ui->vga1->setValue(m_settings.m_vga1);
ui->vga2Text->setText(tr("%1dB").arg(m_settings.m_vga2));
ui->vga2->setValue(m_settings.m_vga2);
ui->xb200->setCurrentIndex(getXb200Index(m_settings.m_xb200, m_settings.m_xb200Path, m_settings.m_xb200Filter));
}
void Bladerf1OutputGui::sendSettings()
{
if(!m_updateTimer.isActive())
m_updateTimer.start(100);
}
void Bladerf1OutputGui::on_centerFrequency_changed(quint64 value)
{
m_settings.m_centerFrequency = value * 1000;
sendSettings();
}
void Bladerf1OutputGui::on_sampleRate_changed(quint64 value)
{
if (m_sampleRateMode) {
m_settings.m_devSampleRate = value;
} else {
m_settings.m_devSampleRate = value * (1 << m_settings.m_log2Interp);
}
sendSettings();
}
void Bladerf1OutputGui::on_bandwidth_currentIndexChanged(int index)
{
int newbw = BladerfBandwidths::getBandwidth(index);
m_settings.m_bandwidth = newbw * 1000;
sendSettings();
}
void Bladerf1OutputGui::on_interp_currentIndexChanged(int index)
{
if ((index <0) || (index > 6)) {
return;
}
m_settings.m_log2Interp = index;
displaySampleRate();
if (m_sampleRateMode) {
m_settings.m_devSampleRate = ui->sampleRate->getValueNew();
} else {
m_settings.m_devSampleRate = ui->sampleRate->getValueNew() * (1 << m_settings.m_log2Interp);
}
sendSettings();
}
void Bladerf1OutputGui::on_vga1_valueChanged(int value)
{
if ((value < BLADERF_TXVGA1_GAIN_MIN) || (value > BLADERF_TXVGA1_GAIN_MAX))
return;
ui->vga1Text->setText(tr("%1dB").arg(value));
m_settings.m_vga1 = value;
sendSettings();
}
void Bladerf1OutputGui::on_vga2_valueChanged(int value)
{
if ((value < BLADERF_TXVGA2_GAIN_MIN) || (value > BLADERF_TXVGA2_GAIN_MAX))
return;
ui->vga2Text->setText(tr("%1dB").arg(value));
m_settings.m_vga2 = value;
sendSettings();
}
void Bladerf1OutputGui::on_xb200_currentIndexChanged(int index)
{
if (index == 1) // bypass
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_BYPASS;
}
else if (index == 2) // Auto 1dB
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_MIX;
m_settings.m_xb200Filter = BLADERF_XB200_AUTO_1DB;
}
else if (index == 3) // Auto 3dB
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_MIX;
m_settings.m_xb200Filter = BLADERF_XB200_AUTO_3DB;
}
else if (index == 4) // Custom
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_MIX;
m_settings.m_xb200Filter = BLADERF_XB200_CUSTOM;
}
else if (index == 5) // 50 MHz
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_MIX;
m_settings.m_xb200Filter = BLADERF_XB200_50M;
}
else if (index == 6) // 144 MHz
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_MIX;
m_settings.m_xb200Filter = BLADERF_XB200_144M;
}
else if (index == 7) // 222 MHz
{
m_settings.m_xb200 = true;
m_settings.m_xb200Path = BLADERF_XB200_MIX;
m_settings.m_xb200Filter = BLADERF_XB200_222M;
}
else // no xb200
{
m_settings.m_xb200 = false;
}
if (m_settings.m_xb200)
{
ui->centerFrequency->setValueRange(7, BLADERF_FREQUENCY_MIN_XB200/1000, BLADERF_FREQUENCY_MAX/1000);
}
else
{
ui->centerFrequency->setValueRange(7, BLADERF_FREQUENCY_MIN/1000, BLADERF_FREQUENCY_MAX/1000);
}
sendSettings();
}
void Bladerf1OutputGui::on_startStop_toggled(bool checked)
{
if (m_doApplySettings)
{
Bladerf1Output::MsgStartStop *message = Bladerf1Output::MsgStartStop::create(checked);
m_deviceSampleSink->getInputMessageQueue()->push(message);
}
}
void Bladerf1OutputGui::on_sampleRateMode_toggled(bool checked)
{
m_sampleRateMode = checked;
displaySampleRate();
}
void Bladerf1OutputGui::updateHardware()
{
qDebug() << "BladerfGui::updateHardware";
Bladerf1Output::MsgConfigureBladerf1* message = Bladerf1Output::MsgConfigureBladerf1::create( m_settings, m_forceSettings);
m_deviceSampleSink->getInputMessageQueue()->push(message);
m_forceSettings = false;
m_updateTimer.stop();
}
void Bladerf1OutputGui::updateStatus()
{
2019-05-08 16:11:53 -04:00
int state = m_deviceUISet->m_deviceAPI->state();
if(m_lastEngineState != state)
{
switch(state)
{
2019-05-08 16:11:53 -04:00
case DeviceAPI::StNotStarted:
ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
break;
2019-05-08 16:11:53 -04:00
case DeviceAPI::StIdle:
ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
break;
2019-05-08 16:11:53 -04:00
case DeviceAPI::StRunning:
ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
break;
2019-05-08 16:11:53 -04:00
case DeviceAPI::StError:
ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
2019-05-08 16:11:53 -04:00
QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
break;
default:
break;
}
m_lastEngineState = state;
}
}
unsigned int Bladerf1OutputGui::getXb200Index(bool xb_200, bladerf_xb200_path xb200Path, bladerf_xb200_filter xb200Filter)
{
if (xb_200)
{
if (xb200Path == BLADERF_XB200_BYPASS)
{
return 1;
}
else
{
if (xb200Filter == BLADERF_XB200_AUTO_1DB)
{
return 2;
}
else if (xb200Filter == BLADERF_XB200_AUTO_3DB)
{
return 3;
}
else if (xb200Filter == BLADERF_XB200_CUSTOM)
{
return 4;
}
else if (xb200Filter == BLADERF_XB200_50M)
{
return 5;
}
else if (xb200Filter == BLADERF_XB200_144M)
{
return 6;
}
else // xb200Filter == BLADERF_XB200_222M
{
return 7;
}
}
}
else
{
return 0;
}
}
2018-12-26 13:22:52 -05:00
void Bladerf1OutputGui::openDeviceSettingsDialog(const QPoint& p)
{
BasicDeviceSettingsDialog dialog(this);
dialog.setUseReverseAPI(m_settings.m_useReverseAPI);
dialog.setReverseAPIAddress(m_settings.m_reverseAPIAddress);
dialog.setReverseAPIPort(m_settings.m_reverseAPIPort);
dialog.setReverseAPIDeviceIndex(m_settings.m_reverseAPIDeviceIndex);
dialog.move(p);
dialog.exec();
m_settings.m_useReverseAPI = dialog.useReverseAPI();
m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress();
m_settings.m_reverseAPIPort = dialog.getReverseAPIPort();
m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex();
sendSettings();
}