TCP source: use settings in GUI

This commit is contained in:
f4exb 2017-10-07 10:24:25 +02:00
parent 62b8a9d95d
commit 8cc0f53635
7 changed files with 470 additions and 187 deletions

View File

@ -31,7 +31,7 @@ TCPSrc::TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, BasebandSampl
setObjectName("TCPSrc"); setObjectName("TCPSrc");
m_inputSampleRate = 96000; m_inputSampleRate = 96000;
m_sampleFormat = FormatSSB; m_sampleFormat = TCPSrcSettings::FormatSSB;
m_outputSampleRate = 48000; m_outputSampleRate = 48000;
m_rfBandwidth = 32000; m_rfBandwidth = 32000;
m_tcpServer = 0; m_tcpServer = 0;
@ -61,7 +61,7 @@ TCPSrc::~TCPSrc()
if (TCPFilter) delete TCPFilter; if (TCPFilter) delete TCPFilter;
} }
void TCPSrc::configure(MessageQueue* messageQueue, SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost) void TCPSrc::configure(MessageQueue* messageQueue, TCPSrcSettings::SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost)
{ {
Message* cmd = MsgTCPSrcConfigure::create(sampleFormat, outputSampleRate, rfBandwidth, tcpPort, boost); Message* cmd = MsgTCPSrcConfigure::create(sampleFormat, outputSampleRate, rfBandwidth, tcpPort, boost);
messageQueue->push(cmd); messageQueue->push(cmd);
@ -110,7 +110,7 @@ void TCPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector:
m_s16leSockets[i].socket->write((const char*)&m_sampleBuffer[0], m_sampleBuffer.size() * 4); m_s16leSockets[i].socket->write((const char*)&m_sampleBuffer[0], m_sampleBuffer.size() * 4);
} }
if((m_sampleFormat == FormatSSB) && (m_ssbSockets.count() > 0)) { if((m_sampleFormat == TCPSrcSettings::FormatSSB) && (m_ssbSockets.count() > 0)) {
for(SampleVector::const_iterator it = m_sampleBuffer.begin(); it != m_sampleBuffer.end(); ++it) { for(SampleVector::const_iterator it = m_sampleBuffer.begin(); it != m_sampleBuffer.end(); ++it) {
//Complex cj(it->real() / 30000.0, it->imag() / 30000.0); //Complex cj(it->real() / 30000.0, it->imag() / 30000.0);
Complex cj(it->real(), it->imag()); Complex cj(it->real(), it->imag());
@ -130,7 +130,7 @@ void TCPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector:
} }
} }
if((m_sampleFormat == FormatNFM) && (m_ssbSockets.count() > 0)) { if((m_sampleFormat == TCPSrcSettings::FormatNFM) && (m_ssbSockets.count() > 0)) {
for(SampleVector::const_iterator it = m_sampleBuffer.begin(); it != m_sampleBuffer.end(); ++it) { for(SampleVector::const_iterator it = m_sampleBuffer.begin(); it != m_sampleBuffer.end(); ++it) {
Complex cj(it->real() / 32768.0f, it->imag() / 32768.0f); Complex cj(it->real() / 32768.0f, it->imag() / 32768.0f);
// An FFT filter here is overkill, but was already set up for SSB // An FFT filter here is overkill, but was already set up for SSB
@ -225,7 +225,7 @@ bool TCPSrc::handleMessage(const Message& cmd)
m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.0); m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.0);
m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate; m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate;
if (m_sampleFormat == FormatSSB) if (m_sampleFormat == TCPSrcSettings::FormatSSB)
{ {
TCPFilter->create_filter(0.3 / 48.0, m_rfBandwidth / 2.0 / m_outputSampleRate); TCPFilter->create_filter(0.3 / 48.0, m_rfBandwidth / 2.0 / m_outputSampleRate);
} }
@ -311,10 +311,10 @@ void TCPSrc::processNewConnection()
switch(m_sampleFormat) { switch(m_sampleFormat) {
case FormatNFM: case TCPSrcSettings::FormatNFM:
case FormatSSB: case TCPSrcSettings::FormatSSB:
{ {
quint32 id = (FormatSSB << 24) | m_nextSSBId; quint32 id = (TCPSrcSettings::FormatSSB << 24) | m_nextSSBId;
MsgTCPSrcConnection* msg = MsgTCPSrcConnection::create(true, id, connection->peerAddress(), connection->peerPort()); MsgTCPSrcConnection* msg = MsgTCPSrcConnection::create(true, id, connection->peerAddress(), connection->peerPort());
m_nextSSBId = (m_nextSSBId + 1) & 0xffffff; m_nextSSBId = (m_nextSSBId + 1) & 0xffffff;
m_ssbSockets.push_back(Socket(id, connection)); m_ssbSockets.push_back(Socket(id, connection));
@ -322,10 +322,10 @@ void TCPSrc::processNewConnection()
break; break;
} }
case FormatS16LE: case TCPSrcSettings::FormatS16LE:
{ {
qDebug("TCPSrc::processNewConnection: establish new S16LE connection"); qDebug("TCPSrc::processNewConnection: establish new S16LE connection");
quint32 id = (FormatS16LE << 24) | m_nextS16leId; quint32 id = (TCPSrcSettings::FormatS16LE << 24) | m_nextS16leId;
MsgTCPSrcConnection* msg = MsgTCPSrcConnection::create(true, id, connection->peerAddress(), connection->peerPort()); MsgTCPSrcConnection* msg = MsgTCPSrcConnection::create(true, id, connection->peerAddress(), connection->peerPort());
m_nextS16leId = (m_nextS16leId + 1) & 0xffffff; m_nextS16leId = (m_nextS16leId + 1) & 0xffffff;
m_s16leSockets.push_back(Socket(id, connection)); m_s16leSockets.push_back(Socket(id, connection));

View File

@ -1,14 +1,17 @@
#ifndef INCLUDE_TCPSRC_H #ifndef INCLUDE_TCPSRC_H
#define INCLUDE_TCPSRC_H #define INCLUDE_TCPSRC_H
#include <dsp/basebandsamplesink.h>
#include <QMutex> #include <QMutex>
#include <QHostAddress> #include <QHostAddress>
#include <dsp/basebandsamplesink.h>
#include "dsp/nco.h" #include "dsp/nco.h"
#include "dsp/fftfilt.h" #include "dsp/fftfilt.h"
#include "dsp/interpolator.h" #include "dsp/interpolator.h"
#include "util/message.h" #include "util/message.h"
#include "tcpsrcsettings.h"
#define tcpFftLen 2048 #define tcpFftLen 2048
class QTcpServer; class QTcpServer;
@ -19,17 +22,10 @@ class TCPSrc : public BasebandSampleSink {
Q_OBJECT Q_OBJECT
public: public:
enum SampleFormat {
FormatSSB,
FormatNFM,
FormatS16LE,
FormatNone
};
TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, BasebandSampleSink* spectrum); TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, BasebandSampleSink* spectrum);
virtual ~TCPSrc(); virtual ~TCPSrc();
void configure(MessageQueue* messageQueue, SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost); void configure(MessageQueue* messageQueue, TCPSrcSettings::SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost);
void setSpectrum(MessageQueue* messageQueue, bool enabled); void setSpectrum(MessageQueue* messageQueue, bool enabled);
double getMagSq() const { return m_magsq; } double getMagSq() const { return m_magsq; }
@ -72,25 +68,25 @@ protected:
MESSAGE_CLASS_DECLARATION MESSAGE_CLASS_DECLARATION
public: public:
SampleFormat getSampleFormat() const { return m_sampleFormat; } TCPSrcSettings::SampleFormat getSampleFormat() const { return m_sampleFormat; }
Real getOutputSampleRate() const { return m_outputSampleRate; } Real getOutputSampleRate() const { return m_outputSampleRate; }
Real getRFBandwidth() const { return m_rfBandwidth; } Real getRFBandwidth() const { return m_rfBandwidth; }
int getTCPPort() const { return m_tcpPort; } int getTCPPort() const { return m_tcpPort; }
int getBoost() const { return m_boost; } int getBoost() const { return m_boost; }
static MsgTCPSrcConfigure* create(SampleFormat sampleFormat, Real sampleRate, Real rfBandwidth, int tcpPort, int boost) static MsgTCPSrcConfigure* create(TCPSrcSettings::SampleFormat sampleFormat, Real sampleRate, Real rfBandwidth, int tcpPort, int boost)
{ {
return new MsgTCPSrcConfigure(sampleFormat, sampleRate, rfBandwidth, tcpPort, boost); return new MsgTCPSrcConfigure(sampleFormat, sampleRate, rfBandwidth, tcpPort, boost);
} }
private: private:
SampleFormat m_sampleFormat; TCPSrcSettings::SampleFormat m_sampleFormat;
Real m_outputSampleRate; Real m_outputSampleRate;
Real m_rfBandwidth; Real m_rfBandwidth;
int m_tcpPort; int m_tcpPort;
int m_boost; int m_boost;
MsgTCPSrcConfigure(SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost) : MsgTCPSrcConfigure(TCPSrcSettings::SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost) :
Message(), Message(),
m_sampleFormat(sampleFormat), m_sampleFormat(sampleFormat),
m_outputSampleRate(outputSampleRate), m_outputSampleRate(outputSampleRate),

View File

@ -49,93 +49,97 @@ QString TCPSrcGUI::getName() const
void TCPSrcGUI::resetToDefaults() void TCPSrcGUI::resetToDefaults()
{ {
blockApplySettings(true); m_settings.resetToDefaults();
displaySettings();
ui->sampleFormat->setCurrentIndex(0);
ui->sampleRate->setText("48000");
ui->rfBandwidth->setText("32000");
ui->tcpPort->setText("9999");
ui->spectrumGUI->resetToDefaults();
ui->boost->setValue(1);
blockApplySettings(false);
applySettings(); applySettings();
} }
QByteArray TCPSrcGUI::serialize() const QByteArray TCPSrcGUI::serialize() const
{ {
SimpleSerializer s(1); return m_settings.serialize();
s.writeS32(2, m_channelMarker.getCenterFrequency()); // SimpleSerializer s(1);
s.writeS32(3, m_sampleFormat); // s.writeS32(2, m_channelMarker.getCenterFrequency());
s.writeReal(4, m_outputSampleRate); // s.writeS32(3, m_sampleFormat);
s.writeReal(5, m_rfBandwidth); // s.writeReal(4, m_outputSampleRate);
s.writeS32(6, m_tcpPort); // s.writeReal(5, m_rfBandwidth);
s.writeBlob(7, ui->spectrumGUI->serialize()); // s.writeS32(6, m_tcpPort);
s.writeS32(8, (qint32)m_boost); // s.writeBlob(7, ui->spectrumGUI->serialize());
s.writeS32(9, m_channelMarker.getCenterFrequency()); // s.writeS32(8, (qint32)m_boost);
return s.final(); // s.writeS32(9, m_channelMarker.getCenterFrequency());
// return s.final();
} }
bool TCPSrcGUI::deserialize(const QByteArray& data) bool TCPSrcGUI::deserialize(const QByteArray& data)
{ {
SimpleDeserializer d(data); if(m_settings.deserialize(data))
if (!d.isValid())
{ {
resetToDefaults(); qDebug("TCPSrcGUI::deserialize: m_squelchGate: %d", m_settings.m_squelchGate);
return false; displaySettings();
}
if (d.getVersion() == 1)
{
QByteArray bytetmp;
qint32 s32tmp;
Real realtmp;
blockApplySettings(true);
m_channelMarker.blockSignals(true);
d.readS32(2, &s32tmp, 0);
m_channelMarker.setCenterFrequency(s32tmp);
d.readS32(3, &s32tmp, TCPSrc::FormatSSB);
switch(s32tmp) {
case TCPSrc::FormatSSB:
ui->sampleFormat->setCurrentIndex(0);
break;
case TCPSrc::FormatNFM:
ui->sampleFormat->setCurrentIndex(1);
break;
case TCPSrc::FormatS16LE:
ui->sampleFormat->setCurrentIndex(2);
break;
default:
ui->sampleFormat->setCurrentIndex(0);
break;
}
d.readReal(4, &realtmp, 48000);
ui->sampleRate->setText(QString("%1").arg(realtmp, 0));
d.readReal(5, &realtmp, 32000);
ui->rfBandwidth->setText(QString("%1").arg(realtmp, 0));
d.readS32(6, &s32tmp, 9999);
ui->tcpPort->setText(QString("%1").arg(s32tmp));
d.readBlob(7, &bytetmp);
ui->spectrumGUI->deserialize(bytetmp);
d.readS32(8, &s32tmp, 1);
ui->boost->setValue(s32tmp);
d.readS32(9, &s32tmp, 0);
m_channelMarker.setCenterFrequency(s32tmp);
blockApplySettings(false);
m_channelMarker.blockSignals(false);
applySettings(); applySettings();
return true; return true;
} } else {
else
{
resetToDefaults(); resetToDefaults();
return false; return false;
} }
// SimpleDeserializer d(data);
//
// if (!d.isValid())
// {
// resetToDefaults();
// return false;
// }
//
// if (d.getVersion() == 1)
// {
// QByteArray bytetmp;
// qint32 s32tmp;
// Real realtmp;
//
// blockApplySettings(true);
// m_channelMarker.blockSignals(true);
//
// d.readS32(2, &s32tmp, 0);
// m_channelMarker.setCenterFrequency(s32tmp);
// d.readS32(3, &s32tmp, TCPSrcSettings::FormatSSB);
// switch(s32tmp) {
// case TCPSrcSettings::FormatSSB:
// ui->sampleFormat->setCurrentIndex(0);
// break;
// case TCPSrcSettings::FormatNFM:
// ui->sampleFormat->setCurrentIndex(1);
// break;
// case TCPSrcSettings::FormatS16LE:
// ui->sampleFormat->setCurrentIndex(2);
// break;
// default:
// ui->sampleFormat->setCurrentIndex(0);
// break;
// }
// d.readReal(4, &realtmp, 48000);
// ui->sampleRate->setText(QString("%1").arg(realtmp, 0));
// d.readReal(5, &realtmp, 32000);
// ui->rfBandwidth->setText(QString("%1").arg(realtmp, 0));
// d.readS32(6, &s32tmp, 9999);
// ui->tcpPort->setText(QString("%1").arg(s32tmp));
// d.readBlob(7, &bytetmp);
// ui->spectrumGUI->deserialize(bytetmp);
// d.readS32(8, &s32tmp, 1);
// ui->volume->setValue(s32tmp);
// d.readS32(9, &s32tmp, 0);
// m_channelMarker.setCenterFrequency(s32tmp);
//
// blockApplySettings(false);
// m_channelMarker.blockSignals(false);
//
// applySettings();
// return true;
// }
// else
// {
// resetToDefaults();
// return false;
// }
} }
bool TCPSrcGUI::handleMessage(const Message& message) bool TCPSrcGUI::handleMessage(const Message& message)
@ -189,6 +193,7 @@ TCPSrcGUI::TCPSrcGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget*
m_channelMarker(this), m_channelMarker(this),
m_channelPowerDbAvg(40,0), m_channelPowerDbAvg(40,0),
m_basicSettingsShown(false), m_basicSettingsShown(false),
m_rfBandwidthChanged(false),
m_doApplySettings(true) m_doApplySettings(true)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -216,11 +221,11 @@ TCPSrcGUI::TCPSrcGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget*
ui->glSpectrum->connectTimer(m_pluginAPI->getMainWindow()->getMasterTimer()); ui->glSpectrum->connectTimer(m_pluginAPI->getMainWindow()->getMasterTimer());
connect(&m_pluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); connect(&m_pluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick()));
//m_channelMarker = new ChannelMarker(this);
m_channelMarker.setBandwidth(16000); m_channelMarker.setBandwidth(16000);
m_channelMarker.setCenterFrequency(0); m_channelMarker.setCenterFrequency(0);
m_channelMarker.setColor(Qt::green);
m_channelMarker.setVisible(true); m_channelMarker.setVisible(true);
m_channelMarker.setColor(m_settings.m_rgbColor);
setTitleColor(m_channelMarker.getColor());
connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(channelMarkerChanged())); connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(channelMarkerChanged()));
@ -241,7 +246,6 @@ TCPSrcGUI::~TCPSrcGUI()
delete m_channelizer; delete m_channelizer;
delete m_tcpSrc; delete m_tcpSrc;
delete m_spectrumVis; delete m_spectrumVis;
//delete m_channelMarker;
delete ui; delete ui;
} }
@ -254,115 +258,177 @@ void TCPSrcGUI::applySettings()
{ {
if (m_doApplySettings) if (m_doApplySettings)
{ {
bool ok; ui->glSpectrum->setSampleRate(m_settings.m_outputSampleRate);
Real outputSampleRate = ui->sampleRate->text().toDouble(&ok);
if((!ok) || (outputSampleRate < 1000))
{
outputSampleRate = 48000;
}
Real rfBandwidth = ui->rfBandwidth->text().toDouble(&ok);
if((!ok) || (rfBandwidth > outputSampleRate))
{
rfBandwidth = outputSampleRate;
}
int tcpPort = ui->tcpPort->text().toInt(&ok);
if((!ok) || (tcpPort < 1) || (tcpPort > 65535))
{
tcpPort = 9999;
}
int boost = ui->boost->value();
setTitleColor(m_channelMarker.getColor());
ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());
ui->sampleRate->setText(QString("%1").arg(outputSampleRate, 0));
ui->rfBandwidth->setText(QString("%1").arg(rfBandwidth, 0));
ui->tcpPort->setText(QString("%1").arg(tcpPort));
ui->boost->setValue(boost);
m_channelMarker.disconnect(this, SLOT(channelMarkerChanged()));
m_channelMarker.setBandwidth((int)rfBandwidth);
connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(channelMarkerChanged()));
ui->glSpectrum->setSampleRate(outputSampleRate);
m_channelizer->configure(m_channelizer->getInputMessageQueue(), m_channelizer->configure(m_channelizer->getInputMessageQueue(),
outputSampleRate, m_settings.m_outputSampleRate,
m_channelMarker.getCenterFrequency()); m_channelMarker.getCenterFrequency());
TCPSrc::SampleFormat sampleFormat;
switch(ui->sampleFormat->currentIndex())
{
case 0:
sampleFormat = TCPSrc::FormatSSB;
break;
case 1:
sampleFormat = TCPSrc::FormatNFM;
break;
case 2:
sampleFormat = TCPSrc::FormatS16LE;
break;
default:
sampleFormat = TCPSrc::FormatSSB;
break;
}
m_sampleFormat = sampleFormat;
m_outputSampleRate = outputSampleRate;
m_rfBandwidth = rfBandwidth;
m_tcpPort = tcpPort;
m_boost = boost;
m_tcpSrc->configure(m_tcpSrc->getInputMessageQueue(), m_tcpSrc->configure(m_tcpSrc->getInputMessageQueue(),
sampleFormat, m_settings.m_sampleFormat,
outputSampleRate, m_settings.m_outputSampleRate,
rfBandwidth, m_settings.m_rfBandwidth,
tcpPort, m_settings.m_tcpPort,
boost); m_settings.m_volume);
ui->applyBtn->setEnabled(false);
} }
} }
void TCPSrcGUI::on_deltaFrequency_changed(qint64 value) void TCPSrcGUI::on_deltaFrequency_changed(qint64 value)
{ {
m_channelMarker.setCenterFrequency(value); m_channelMarker.setCenterFrequency(value);
m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency();
applySettings();
} }
void TCPSrcGUI::on_sampleFormat_currentIndexChanged(int index __attribute__((unused))) void TCPSrcGUI::on_sampleFormat_currentIndexChanged(int index)
{ {
setSampleFormat(index);
ui->applyBtn->setEnabled(true); ui->applyBtn->setEnabled(true);
ui->applyBtn->setStyleSheet("QPushButton { background-color : green; }");
} }
void TCPSrcGUI::on_sampleRate_textEdited(const QString& arg1 __attribute__((unused))) void TCPSrcGUI::on_sampleRate_textEdited(const QString& arg1 __attribute__((unused)))
{ {
bool ok;
Real outputSampleRate = ui->sampleRate->text().toDouble(&ok);
if((!ok) || (outputSampleRate < 1000))
{
m_settings.m_outputSampleRate = 48000;
ui->sampleRate->setText(QString("%1").arg(outputSampleRate, 0));
}
else
{
m_settings.m_outputSampleRate = outputSampleRate;
}
ui->applyBtn->setEnabled(true); ui->applyBtn->setEnabled(true);
ui->applyBtn->setStyleSheet("QPushButton { background-color : green; }");
} }
void TCPSrcGUI::on_rfBandwidth_textEdited(const QString& arg1 __attribute__((unused))) void TCPSrcGUI::on_rfBandwidth_textEdited(const QString& arg1 __attribute__((unused)))
{ {
bool ok;
Real rfBandwidth = ui->rfBandwidth->text().toDouble(&ok);
if((!ok) || (rfBandwidth > m_settings.m_outputSampleRate))
{
m_settings.m_rfBandwidth = m_settings.m_outputSampleRate;
ui->rfBandwidth->setText(QString("%1").arg(m_settings.m_rfBandwidth, 0));
}
else
{
m_settings.m_rfBandwidth = rfBandwidth;
}
m_rfBandwidthChanged = true;
ui->applyBtn->setEnabled(true); ui->applyBtn->setEnabled(true);
ui->applyBtn->setStyleSheet("QPushButton { background-color : green; }");
} }
void TCPSrcGUI::on_tcpPort_textEdited(const QString& arg1 __attribute__((unused))) void TCPSrcGUI::on_tcpPort_textEdited(const QString& arg1 __attribute__((unused)))
{ {
bool ok;
int tcpPort = ui->tcpPort->text().toInt(&ok);
if((!ok) || (tcpPort < 1) || (tcpPort > 65535))
{
m_settings.m_tcpPort = 9999;
ui->tcpPort->setText(QString("%1").arg(m_settings.m_tcpPort, 0));
}
else
{
m_settings.m_tcpPort = tcpPort;
}
ui->applyBtn->setEnabled(true); ui->applyBtn->setEnabled(true);
ui->applyBtn->setStyleSheet("QPushButton { background-color : green; }");
} }
void TCPSrcGUI::on_applyBtn_clicked() void TCPSrcGUI::on_applyBtn_clicked()
{ {
if (m_rfBandwidthChanged)
{
blockApplySettings(true);
m_channelMarker.setBandwidth((int) m_settings.m_rfBandwidth);
m_rfBandwidthChanged = false;
blockApplySettings(false);
}
ui->glSpectrum->setSampleRate(m_settings.m_outputSampleRate);
ui->applyBtn->setEnabled(false);
ui->applyBtn->setStyleSheet("QPushButton { background:rgb(79,79,79); }");
applySettings(); applySettings();
} }
void TCPSrcGUI::on_boost_valueChanged(int value) void TCPSrcGUI::displaySettings()
{ {
ui->boost->setValue(value); m_channelMarker.blockSignals(true);
ui->boostText->setText(QString("%1").arg(value)); m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset);
m_channelMarker.setUDPAddress(m_settings.m_udpAddress);
m_channelMarker.setUDPSendPort(m_settings.m_udpPort);
m_channelMarker.setColor(m_settings.m_rgbColor);
setTitleColor(m_settings.m_rgbColor);
m_channelMarker.blockSignals(false);
ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());
ui->sampleRate->setText(QString("%1").arg(m_settings.m_outputSampleRate, 0));
setSampleFormatIndex(m_settings.m_sampleFormat);
ui->rfBandwidth->setText(QString("%1").arg(m_settings.m_rfBandwidth, 0));
ui->volume->setValue(m_settings.m_volume);
ui->volumeText->setText(QString("%1").arg(ui->volume->value()));
ui->glSpectrum->setSampleRate(m_settings.m_outputSampleRate);
}
void TCPSrcGUI::setSampleFormatIndex(const TCPSrcSettings::SampleFormat& sampleFormat)
{
switch(sampleFormat)
{
case TCPSrcSettings::FormatS16LE:
ui->sampleFormat->setCurrentIndex(0);
break;
case TCPSrcSettings::FormatNFM:
ui->sampleFormat->setCurrentIndex(1);
break;
case TCPSrcSettings::FormatSSB:
ui->sampleFormat->setCurrentIndex(2);
break;
default:
ui->sampleFormat->setCurrentIndex(0);
break;
}
}
void TCPSrcGUI::setSampleFormat(int index)
{
switch(index)
{
case 0:
m_settings.m_sampleFormat = TCPSrcSettings::FormatS16LE;
break;
case 1:
m_settings.m_sampleFormat = TCPSrcSettings::FormatNFM;
break;
case 2:
m_settings.m_sampleFormat = TCPSrcSettings::FormatSSB;
break;
default:
m_settings.m_sampleFormat = TCPSrcSettings::FormatS16LE;
break;
}
}
void TCPSrcGUI::on_volume_valueChanged(int value)
{
ui->volume->setValue(value);
ui->volumeText->setText(QString("%1").arg(value));
ui->applyBtn->setEnabled(true); ui->applyBtn->setEnabled(true);
} }

View File

@ -10,6 +10,7 @@
#include "util/messagequeue.h" #include "util/messagequeue.h"
#include "tcpsrc.h" #include "tcpsrc.h"
#include "tcpsrcsettings.h"
class PluginAPI; class PluginAPI;
class DeviceSourceAPI; class DeviceSourceAPI;
@ -52,7 +53,7 @@ private slots:
void on_applyBtn_clicked(); void on_applyBtn_clicked();
void onWidgetRolled(QWidget* widget, bool rollDown); void onWidgetRolled(QWidget* widget, bool rollDown);
void onMenuDoubleClicked(); void onMenuDoubleClicked();
void on_boost_valueChanged(int value); void on_volume_valueChanged(int value);
void tick(); void tick();
private: private:
@ -64,12 +65,14 @@ private:
MovingAverage<double> m_channelPowerDbAvg; MovingAverage<double> m_channelPowerDbAvg;
// settings // settings
TCPSrc::SampleFormat m_sampleFormat; TCPSrcSettings m_settings;
TCPSrcSettings::SampleFormat m_sampleFormat;
Real m_outputSampleRate; Real m_outputSampleRate;
Real m_rfBandwidth; Real m_rfBandwidth;
int m_boost; int m_boost;
int m_tcpPort; int m_tcpPort;
bool m_basicSettingsShown; bool m_basicSettingsShown;
bool m_rfBandwidthChanged;
bool m_doApplySettings; bool m_doApplySettings;
// RF path // RF path
@ -83,6 +86,9 @@ private:
void blockApplySettings(bool block); void blockApplySettings(bool block);
void applySettings(); void applySettings();
void displaySettings();
void setSampleFormat(int index);
void setSampleFormatIndex(const TCPSrcSettings::SampleFormat& sampleFormat);
void addConnection(quint32 id, const QHostAddress& peerAddress, int peerPort); void addConnection(quint32 id, const QHostAddress& peerAddress, int peerPort);
void delConnection(quint32 id); void delConnection(quint32 id);

View File

@ -60,11 +60,11 @@
<string>Sample format</string> <string>Sample format</string>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>0</number>
</property> </property>
<item> <item>
<property name="text"> <property name="text">
<string>S16LE SSB</string> <string>S16LE I/Q</string>
</property> </property>
</item> </item>
<item> <item>
@ -74,7 +74,7 @@
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>S16LE I/Q</string> <string>S16LE SSB</string>
</property> </property>
</item> </item>
</widget> </widget>
@ -310,14 +310,14 @@
<item row="5" column="1"> <item row="5" column="1">
<layout class="QHBoxLayout" name="BoostLayout"> <layout class="QHBoxLayout" name="BoostLayout">
<item> <item>
<widget class="QLabel" name="boostLabel"> <widget class="QLabel" name="volumeLabel">
<property name="text"> <property name="text">
<string>Boost</string> <string>Vol</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSlider" name="boost"> <widget class="QSlider" name="volume">
<property name="toolTip"> <property name="toolTip">
<string>Amplitude boost</string> <string>Amplitude boost</string>
</property> </property>
@ -333,7 +333,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="boostText"> <widget class="QLabel" name="volumeText">
<property name="text"> <property name="text">
<string>0</string> <string>0</string>
</property> </property>

View File

@ -0,0 +1,145 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 <QColor>
#include "dsp/dspengine.h"
#include "util/simpleserializer.h"
#include "settings/serializable.h"
#include "tcpsrcsettings.h"
TCPSrcSettings::TCPSrcSettings() :
m_channelMarker(0),
m_spectrumGUI(0)
{
resetToDefaults();
}
void TCPSrcSettings::resetToDefaults()
{
m_outputSampleRate = 48000;
m_sampleFormat = FormatS16LE;
m_inputSampleRate = 48000;
m_inputFrequencyOffset = 0;
m_rfBandwidth = 12500;
m_tcpPort = 9999;
m_fmDeviation = 2500;
m_channelMute = false;
m_gain = 1.0;
m_squelchdB = -60;
m_squelchGate = 0.0;
m_squelchEnabled = true;
m_agc = false;
m_audioActive = false;
m_audioStereo = false;
m_volume = 20;
m_udpAddress = "127.0.0.1";
m_udpPort = 9999;
m_audioPort = 9998;
m_rgbColor = QColor(225, 25, 99).rgb();
}
QByteArray TCPSrcSettings::serialize() const
{
SimpleSerializer s(1);
s.writeS32(2, m_inputFrequencyOffset);
s.writeS32(3, (int) m_sampleFormat);
s.writeReal(4, m_outputSampleRate);
s.writeReal(5, m_rfBandwidth);
s.writeS32(6, m_tcpPort);
if (m_channelMarker) {
s.writeBlob(10, m_channelMarker->serialize());
}
if (m_spectrumGUI) {
s.writeBlob(7, m_spectrumGUI->serialize());
}
s.writeS32(8, m_gain*10.0);
s.writeU32(9, m_rgbColor);
s.writeBool(11, m_audioActive);
s.writeS32(12, m_volume);
s.writeBool(14, m_audioStereo);
s.writeS32(15, m_fmDeviation);
s.writeS32(16, m_squelchdB);
s.writeS32(17, m_squelchGate);
s.writeBool(18, m_agc);
return s.final();
}
bool TCPSrcSettings::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if (!d.isValid())
{
resetToDefaults();
return false;
}
if (d.getVersion() == 1)
{
QByteArray bytetmp;
QString strtmp;
int32_t s32tmp;
if (m_channelMarker) {
d.readBlob(10, &bytetmp);
m_channelMarker->deserialize(bytetmp);
}
d.readS32(2, &s32tmp, 0);
m_inputFrequencyOffset = s32tmp;
d.readS32(3, &s32tmp, FormatS16LE);
if ((s32tmp >= 0) && (s32tmp < (int) FormatNone)) {
m_sampleFormat = (SampleFormat) s32tmp;
} else {
m_sampleFormat = FormatS16LE;
}
d.readReal(4, &m_outputSampleRate, 48000.0);
d.readReal(5, &m_rfBandwidth, 32000.0);
d.readS32(6, &s32tmp, 10);
m_tcpPort = s32tmp < 1024 ? 9999 : s32tmp % (1<<16);
if (m_spectrumGUI) {
d.readBlob(7, &bytetmp);
m_spectrumGUI->deserialize(bytetmp);
}
d.readS32(8, &s32tmp, 10);
m_gain = s32tmp / 10.0;
d.readU32(9, &m_rgbColor);
d.readBool(11, &m_audioActive, false);
d.readS32(12, &m_volume, 0);
d.readBool(14, &m_audioStereo, false);
d.readS32(15, &m_fmDeviation, 2500);
d.readS32(16, &m_squelchdB, -60);
d.readS32(17, &m_squelchGate, 5);
d.readBool(18, &m_agc, false);
return true;
}
else
{
resetToDefaults();
return false;
}
}

View File

@ -0,0 +1,70 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 PLUGINS_CHANNELRX_TCPSRC_TCPSRCSETTINGS_H_
#define PLUGINS_CHANNELRX_TCPSRC_TCPSRCSETTINGS_H_
#include <QByteArray>
#include <QString>
#include <stdint.h>
struct Serializable;
struct TCPSrcSettings
{
enum SampleFormat {
FormatS16LE,
FormatNFM,
FormatSSB,
FormatNone
};
float m_outputSampleRate;
SampleFormat m_sampleFormat;
float m_inputSampleRate;
int64_t m_inputFrequencyOffset;
float m_rfBandwidth;
uint16_t m_tcpPort;
int m_fmDeviation;
bool m_channelMute;
float m_gain;
int m_squelchdB; //!< power dB
int m_squelchGate; //!< 100ths seconds
bool m_squelchEnabled;
bool m_agc;
bool m_audioActive;
bool m_audioStereo;
int m_volume;
quint32 m_rgbColor;
QString m_udpAddress;
uint16_t m_udpPort;
uint16_t m_audioPort;
Serializable *m_channelMarker;
Serializable *m_spectrumGUI;
TCPSrcSettings();
void resetToDefaults();
void setChannelMarker(Serializable *channelMarker) { m_channelMarker = channelMarker; }
void setSpectrumGUI(Serializable *spectrumGUI) { m_spectrumGUI = spectrumGUI; }
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
#endif /* PLUGINS_CHANNELRX_TCPSRC_TCPSRCSETTINGS_H_ */