2015-08-25 20:03:20 -04:00
|
|
|
#include <QDebug>
|
2014-05-18 11:52:39 -04:00
|
|
|
#include "rtlsdrgui.h"
|
|
|
|
#include "ui_rtlsdrgui.h"
|
|
|
|
#include "plugin/pluginapi.h"
|
2015-08-01 19:45:53 -04:00
|
|
|
#include "gui/colormapper.h"
|
2015-08-17 02:29:34 -04:00
|
|
|
#include "dsp/dspengine.h"
|
2014-05-18 11:52:39 -04:00
|
|
|
|
|
|
|
RTLSDRGui::RTLSDRGui(PluginAPI* pluginAPI, QWidget* parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::RTLSDRGui),
|
|
|
|
m_pluginAPI(pluginAPI),
|
|
|
|
m_settings(),
|
2015-08-17 02:29:34 -04:00
|
|
|
m_sampleSource(0)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2015-08-01 19:45:53 -04:00
|
|
|
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
|
2014-11-09 07:56:53 -05:00
|
|
|
ui->centerFrequency->setValueRange(7, 28500U, 1700000U);
|
2014-05-18 11:52:39 -04:00
|
|
|
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
|
|
|
|
displaySettings();
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
m_sampleSource = new RTLSDRInput();
|
2015-08-25 20:03:20 -04:00
|
|
|
connect(m_sampleSource->getOutputMessageQueueToGUI(), SIGNAL(messageEnqueued()), this, SLOT(HandleSourceMessages()));
|
2015-08-17 02:29:34 -04:00
|
|
|
DSPEngine::instance()->setSource(m_sampleSource);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
RTLSDRGui::~RTLSDRGui()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLSDRGui::destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLSDRGui::setName(const QString& name)
|
|
|
|
{
|
|
|
|
setObjectName(name);
|
|
|
|
}
|
|
|
|
|
2015-06-06 21:30:28 -04:00
|
|
|
QString RTLSDRGui::getName() const
|
|
|
|
{
|
|
|
|
return objectName();
|
|
|
|
}
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
void RTLSDRGui::resetToDefaults()
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
displaySettings();
|
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
2015-07-18 20:07:40 -04:00
|
|
|
qint64 RTLSDRGui::getCenterFrequency() const
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
return m_settings.m_centerFrequency;
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray RTLSDRGui::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLSDRGui::deserialize(const QByteArray& data)
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
2014-05-18 11:52:39 -04:00
|
|
|
displaySettings();
|
|
|
|
sendSettings();
|
|
|
|
return true;
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-18 11:52:39 -04:00
|
|
|
resetToDefaults();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
bool RTLSDRGui::handleMessage(const Message& message)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
if (RTLSDRInput::MsgReportRTLSDR::match(message))
|
|
|
|
{
|
2015-08-25 20:03:20 -04:00
|
|
|
qDebug() << "RTLSDRGui::handleMessage: MsgReportRTLSDR";
|
2015-08-17 02:29:34 -04:00
|
|
|
m_gains = ((RTLSDRInput::MsgReportRTLSDR&) message).getGains();
|
2014-05-18 11:52:39 -04:00
|
|
|
displaySettings();
|
|
|
|
return true;
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-18 11:52:39 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-25 20:03:20 -04:00
|
|
|
void RTLSDRGui::HandleSourceMessages()
|
|
|
|
{
|
|
|
|
Message* message;
|
|
|
|
|
|
|
|
while ((message = m_sampleSource->getOutputMessageQueueToGUI()->pop()) != 0)
|
|
|
|
{
|
|
|
|
qDebug("RTLSDRGui::HandleSourceMessages: message: %s", message->getIdentifier());
|
|
|
|
|
|
|
|
if (handleMessage(*message))
|
|
|
|
{
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
void RTLSDRGui::displaySettings()
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
|
|
|
|
ui->samplerateText->setText(tr("%1k").arg(m_settings.m_devSampleRate / 1000));
|
|
|
|
unsigned int sampleRateIndex = RTLSDRSampleRates::getRateIndex(m_settings.m_devSampleRate);
|
2015-05-09 18:08:42 -04:00
|
|
|
ui->samplerate->setValue(sampleRateIndex);
|
|
|
|
ui->ppm->setValue(m_settings.m_loPpmCorrection);
|
|
|
|
ui->ppmText->setText(tr("%1").arg(m_settings.m_loPpmCorrection));
|
|
|
|
ui->decimText->setText(tr("%1").arg(1<<m_settings.m_log2Decim));
|
|
|
|
ui->decim->setValue(m_settings.m_log2Decim);
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (m_gains.size() > 0)
|
|
|
|
{
|
2014-05-18 11:52:39 -04:00
|
|
|
int dist = abs(m_settings.m_gain - m_gains[0]);
|
|
|
|
int pos = 0;
|
2015-08-17 02:29:34 -04:00
|
|
|
|
|
|
|
for (uint i = 1; i < m_gains.size(); i++)
|
|
|
|
{
|
|
|
|
if (abs(m_settings.m_gain - m_gains[i]) < dist)
|
|
|
|
{
|
2014-05-18 11:52:39 -04:00
|
|
|
dist = abs(m_settings.m_gain - m_gains[i]);
|
|
|
|
pos = i;
|
|
|
|
}
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
ui->gainText->setText(tr("%1.%2").arg(m_gains[pos] / 10).arg(abs(m_gains[pos] % 10)));
|
|
|
|
ui->gain->setMaximum(m_gains.size() - 1);
|
|
|
|
ui->gain->setEnabled(true);
|
|
|
|
ui->gain->setValue(pos);
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-18 11:52:39 -04:00
|
|
|
ui->gain->setMaximum(0);
|
|
|
|
ui->gain->setEnabled(false);
|
|
|
|
ui->gain->setValue(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLSDRGui::sendSettings()
|
|
|
|
{
|
|
|
|
if(!m_updateTimer.isActive())
|
2015-08-17 02:29:34 -04:00
|
|
|
{
|
2014-05-18 11:52:39 -04:00
|
|
|
m_updateTimer.start(100);
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTLSDRGui::on_centerFrequency_changed(quint64 value)
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
m_settings.m_centerFrequency = value * 1000;
|
2014-05-18 11:52:39 -04:00
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
2015-05-09 10:44:26 -04:00
|
|
|
void RTLSDRGui::on_decim_valueChanged(int value)
|
|
|
|
{
|
|
|
|
if ((value <0) || (value > 4))
|
2015-08-17 02:29:34 -04:00
|
|
|
{
|
2015-05-09 10:44:26 -04:00
|
|
|
return;
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 10:44:26 -04:00
|
|
|
ui->decimText->setText(tr("%1").arg(1<<value));
|
|
|
|
m_settings.m_log2Decim = value;
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2015-05-09 10:44:26 -04:00
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
2015-05-08 18:54:01 -04:00
|
|
|
void RTLSDRGui::on_ppm_valueChanged(int value)
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
if ((value > 99) || (value < -99))
|
|
|
|
{
|
2015-05-08 18:54:01 -04:00
|
|
|
return;
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
|
2015-05-08 18:54:01 -04:00
|
|
|
ui->ppmText->setText(tr("%1").arg(value));
|
|
|
|
m_settings.m_loPpmCorrection = value;
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2015-05-08 18:54:01 -04:00
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
void RTLSDRGui::on_gain_valueChanged(int value)
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
if (value > (int)m_gains.size())
|
|
|
|
{
|
2014-05-18 11:52:39 -04:00
|
|
|
return;
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
int gain = m_gains[value];
|
|
|
|
ui->gainText->setText(tr("%1.%2").arg(gain / 10).arg(abs(gain % 10)));
|
|
|
|
m_settings.m_gain = gain;
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
2014-11-08 18:42:43 -05:00
|
|
|
void RTLSDRGui::on_samplerate_valueChanged(int value)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-05-09 18:08:42 -04:00
|
|
|
int newrate = RTLSDRSampleRates::getRate(value);
|
2014-11-08 18:42:43 -05:00
|
|
|
ui->samplerateText->setText(tr("%1k").arg(newrate));
|
2015-08-17 02:29:34 -04:00
|
|
|
m_settings.m_devSampleRate = newrate * 1000;
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
sendSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLSDRGui::updateHardware()
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
RTLSDRInput::MsgConfigureRTLSDR* message = RTLSDRInput::MsgConfigureRTLSDR::create(m_settings);
|
|
|
|
m_sampleSource->getInputMessageQueue()->push(message);
|
2014-05-18 11:52:39 -04:00
|
|
|
m_updateTimer.stop();
|
|
|
|
}
|
2014-11-07 14:26:02 -05:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
void RTLSDRGui::on_checkBox_stateChanged(int state)
|
|
|
|
{
|
|
|
|
if (state == Qt::Checked)
|
|
|
|
{
|
2014-11-09 07:56:53 -05:00
|
|
|
// Direct Modes: 0: off, 1: I, 2: Q, 3: NoMod.
|
|
|
|
((RTLSDRInput*)m_sampleSource)->set_ds_mode(3);
|
2014-11-07 14:26:02 -05:00
|
|
|
ui->gain->setEnabled(false);
|
2014-11-09 07:56:53 -05:00
|
|
|
ui->centerFrequency->setValueRange(7, 1000U, 275000U);
|
|
|
|
ui->centerFrequency->setValue(7000);
|
2015-08-17 02:29:34 -04:00
|
|
|
m_settings.m_centerFrequency = 7000 * 1000;
|
2014-11-07 14:26:02 -05:00
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
else
|
|
|
|
{
|
2014-11-07 14:26:02 -05:00
|
|
|
((RTLSDRInput*)m_sampleSource)->set_ds_mode(0);
|
|
|
|
ui->gain->setEnabled(true);
|
2014-11-09 07:56:53 -05:00
|
|
|
ui->centerFrequency->setValueRange(7, 28500U, 1700000U);
|
|
|
|
ui->centerFrequency->setValue(434000);
|
|
|
|
ui->gain->setValue(0);
|
2015-08-17 02:29:34 -04:00
|
|
|
m_settings.m_centerFrequency = 435000 * 1000;
|
2014-11-07 14:26:02 -05:00
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2014-11-09 07:56:53 -05:00
|
|
|
sendSettings();
|
2014-11-07 14:26:02 -05:00
|
|
|
}
|
|
|
|
|
2015-08-25 20:03:20 -04:00
|
|
|
unsigned int RTLSDRSampleRates::m_rates[] = {288, 1152, 1536, 2304};
|
|
|
|
unsigned int RTLSDRSampleRates::m_nb_rates = 4;
|
2015-05-09 18:08:42 -04:00
|
|
|
|
|
|
|
unsigned int RTLSDRSampleRates::getRate(unsigned int rate_index)
|
|
|
|
{
|
|
|
|
if (rate_index < m_nb_rates)
|
|
|
|
{
|
|
|
|
return m_rates[rate_index];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_rates[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int RTLSDRSampleRates::getRateIndex(unsigned int rate)
|
|
|
|
{
|
|
|
|
for (unsigned int i=0; i < m_nb_rates; i++)
|
|
|
|
{
|
|
|
|
if (rate/1000 == m_rates[i])
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|