1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

Websocket spectrum: Websocket spectrum settings dialog implementation taking settings into account

This commit is contained in:
f4exb 2020-05-01 11:06:56 +02:00
parent c193f4b880
commit 3730cbf865
10 changed files with 345 additions and 20 deletions

View File

@ -52,6 +52,8 @@ void GLSpectrumSettings::resetToDefaults()
m_linear = false;
m_ssb = false;
m_usb = true;
m_wsSpectrumAddress = "127.0.0.1";
m_wsSpectrumPort = 8887;
}
QByteArray GLSpectrumSettings::serialize() const
@ -78,6 +80,8 @@ QByteArray GLSpectrumSettings::serialize() const
s.writeS32(19, (int) m_averagingMode);
s.writeS32(20, (qint32) getAveragingValue(m_averagingIndex, m_averagingMode));
s.writeBool(21, m_linear);
s.writeString(22, m_wsSpectrumAddress);
s.writeU32(23, m_wsSpectrumPort);
s.writeBool(24, m_ssb);
s.writeBool(25, m_usb);
@ -94,6 +98,7 @@ bool GLSpectrumSettings::deserialize(const QByteArray& data)
}
int tmp;
uint32_t utmp;
if (d.getVersion() == 1)
{
@ -121,6 +126,9 @@ bool GLSpectrumSettings::deserialize(const QByteArray& data)
m_averagingIndex = getAveragingIndex(tmp, m_averagingMode);
m_averagingValue = getAveragingValue(m_averagingIndex, m_averagingMode);
d.readBool(21, &m_linear, false);
d.readString(22, &m_wsSpectrumAddress, "127.0.0.1");
d.readU32(23, &utmp, 8887);
m_wsSpectrumPort = utmp < 1024 ? 1024 : utmp > 65535 ? 65535 : utmp;
d.readBool(24, &m_ssb, false);
d.readBool(25, &m_usb, true);

View File

@ -59,6 +59,8 @@ public:
bool m_linear; //!< linear else logarithmic scale
bool m_ssb; //!< SSB display with spectrum center at start of array or display - else spectrum center is on center
bool m_usb; //!< USB display with increasing frequencies towads the right - else decreasing frequencies
QString m_wsSpectrumAddress;
uint16_t m_wsSpectrumPort;
GLSpectrumSettings();
virtual ~GLSpectrumSettings();

View File

@ -745,6 +745,8 @@ void SpectrumVis::applySettings(const GLSpectrumSettings& settings, bool force)
<< " m_refLevel: " << settings.m_refLevel
<< " m_powerRange: " << settings.m_powerRange
<< " m_linear: " << settings.m_linear
<< " m_wsSpectrumAddress: " << settings.m_wsSpectrumAddress
<< " m_wsSpectrumPort: " << settings.m_wsSpectrumPort
<< " force: " << force;
if ((fftSize != m_settings.m_fftSize) || force)
@ -785,6 +787,11 @@ void SpectrumVis::applySettings(const GLSpectrumSettings& settings, bool force)
m_max.resize(fftSize, averagingValue);
}
if ((settings.m_wsSpectrumAddress != m_settings.m_wsSpectrumAddress)
|| (settings.m_wsSpectrumPort != m_settings.m_wsSpectrumPort) || force) {
handleConfigureWSSpectrum(settings.m_wsSpectrumAddress, settings.m_wsSpectrumPort);
}
m_settings = settings;
m_settings.m_fftSize = fftSize;
m_settings.m_fftOverlap = overlapPercent;
@ -816,19 +823,11 @@ void SpectrumVis::handleWSOpenClose(bool openClose)
void SpectrumVis::handleConfigureWSSpectrum(const QString& address, uint16_t port)
{
QMutexLocker mutexLocker(&m_mutex);
bool wsSpectrumWasOpen = false;
if (m_wsSpectrum.socketOpened())
{
m_wsSpectrum.closeSocket();
wsSpectrumWasOpen = true;
}
m_wsSpectrum.setListeningAddress(address);
m_wsSpectrum.setPort(port);
if (wsSpectrumWasOpen) {
m_wsSpectrum.setListeningAddress(address);
m_wsSpectrum.setPort(port);
m_wsSpectrum.openSocket();
}
}

View File

@ -63,6 +63,7 @@ set(sdrgui_SOURCES
gui/tvscreenanalog.cpp
gui/valuedial.cpp
gui/valuedialz.cpp
gui/wsspectrumsettingsdialog.cpp
dsp/scopevis.cpp
dsp/scopevisxy.cpp
@ -148,6 +149,7 @@ set(sdrgui_HEADERS
gui/tvscreenanalog.h
gui/valuedial.h
gui/valuedialz.h
gui/wsspectrumsettingsdialog.h
dsp/scopevis.h
dsp/scopevisxy.h
@ -196,10 +198,12 @@ set(sdrgui_FORMS
gui/pluginsdialog.ui
gui/audiodialog.ui
gui/audioselectdialog.ui
gui/samplingdevicecontrol.ui
gui/samplingdevicedialog.ui
gui/myposdialog.ui
gui/transverterdialog.ui
gui/loggingdialog.ui
gui/wsspectrumsettingsdialog.ui
soapygui/discreterangegui.ui
soapygui/intervalrangegui.ui
soapygui/intervalslidergui.ui

View File

@ -26,6 +26,8 @@
#include "dsp/fftwindow.h"
#include "dsp/spectrumvis.h"
#include "gui/glspectrum.h"
#include "gui/crightclickenabler.h"
#include "gui/wsspectrumsettingsdialog.h"
#include "util/simpleserializer.h"
#include "ui_glspectrumgui.h"
@ -53,6 +55,10 @@ GLSpectrumGUI::GLSpectrumGUI(QWidget* parent) :
// ui->levelRange->setStyleSheet("background-color: rgb(79, 79, 79);");
connect(&m_messageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
CRightClickEnabler *wsSpectrumRightClickEnabler = new CRightClickEnabler(ui->wsSpectrum);
connect(wsSpectrumRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openWebsocketSpectrumSettingsDialog(const QPoint &)));
displaySettings();
setAveragingCombo();
applySettings();
@ -193,16 +199,18 @@ void GLSpectrumGUI::applySettings()
if (m_spectrumVis)
{
m_spectrumVis->configure(
m_settings.m_fftSize,
m_settings.m_refLevel,
m_settings.m_powerRange,
m_settings.m_fftOverlap,
getAveragingValue(m_settings.m_averagingIndex, m_settings.m_averagingMode),
(SpectrumVis::AvgMode) m_settings.m_averagingMode,
(FFTWindow::Function) m_settings.m_fftWindow,
m_settings.m_linear
);
SpectrumVis::MsgConfigureSpectrumVis *msg = SpectrumVis::MsgConfigureSpectrumVis::create(m_settings, false);
m_spectrumVis->getInputMessageQueue()->push(msg);
// m_spectrumVis->configure(
// m_settings.m_fftSize,
// m_settings.m_refLevel,
// m_settings.m_powerRange,
// m_settings.m_fftOverlap,
// getAveragingValue(m_settings.m_averagingIndex, m_settings.m_averagingMode),
// (SpectrumVis::AvgMode) m_settings.m_averagingMode,
// (FFTWindow::Function) m_settings.m_fftWindow,
// m_settings.m_linear
// );
}
}
@ -529,3 +537,21 @@ void GLSpectrumGUI::handleInputMessages()
}
}
}
void GLSpectrumGUI::openWebsocketSpectrumSettingsDialog(const QPoint& p)
{
WebsocketSpectrumSettingsDialog dialog(this);
dialog.setAddress(m_settings.m_wsSpectrumAddress);
dialog.setPort(m_settings.m_wsSpectrumPort);
dialog.move(p);
dialog.exec();
if (dialog.hasChanged())
{
m_settings.m_wsSpectrumAddress = dialog.getAddress();
m_settings.m_wsSpectrumPort = dialog.getPort();
applySettings();
}
}

View File

@ -104,6 +104,7 @@ private slots:
void on_freeze_toggled(bool checked);
void handleInputMessages();
void openWebsocketSpectrumSettingsDialog(const QPoint& p);
};
#endif // INCLUDE_GLSPECTRUMGUI_H

View File

@ -694,6 +694,18 @@
</property>
</widget>
</item>
<item>
<widget class="ButtonSwitch" name="wsSpectrum">
<property name="toolTip">
<string>Left: toggle websocket spectrum - Right: websocket spectrum parameters</string>
</property>
<property name="icon">
<iconset>
<normalon>:/stream.png</normalon>
</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">

View File

@ -0,0 +1,74 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 //
// (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 "wsspectrumsettingsdialog.h"
#include "ui_wsspectrumsettingsdialog.h"
WebsocketSpectrumSettingsDialog::WebsocketSpectrumSettingsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::WebsocketSpectrumSettingsDialog),
m_hasChanged(false)
{
ui->setupUi(this);
setAddress("127.0.0.1");
setPort(8887);
}
WebsocketSpectrumSettingsDialog::~WebsocketSpectrumSettingsDialog()
{
delete ui;
}
void WebsocketSpectrumSettingsDialog::setAddress(const QString& address)
{
m_address = address;
ui->address->setText(m_address);
}
void WebsocketSpectrumSettingsDialog::setPort(uint16_t port)
{
if (port < 1024) {
return;
} else {
m_port = port;
}
ui->port->setText(tr("%1").arg(m_port));
}
void WebsocketSpectrumSettingsDialog::on_address_editingFinished()
{
m_address = ui->address->text();
}
void WebsocketSpectrumSettingsDialog::on_port_editingFinished()
{
bool dataOk;
int port = ui->port->text().toInt(&dataOk);
if ((!dataOk) || (port < 1024) || (port > 65535)) {
return;
} else {
m_port = port;
}
}
void WebsocketSpectrumSettingsDialog::accept()
{
m_hasChanged = true;
QDialog::accept();
}

View File

@ -0,0 +1,54 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 //
// (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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef WSSPECTRUMSETTINGSDIALOG_H
#define WSSPECTRUMSETTINGSDIALOG_H
#include <QDialog>
#include "../../exports/export.h"
namespace Ui {
class WebsocketSpectrumSettingsDialog;
}
class SDRGUI_API WebsocketSpectrumSettingsDialog : public QDialog
{
Q_OBJECT
public:
explicit WebsocketSpectrumSettingsDialog(QWidget *parent = nullptr);
~WebsocketSpectrumSettingsDialog();
bool hasChanged() const { return m_hasChanged; }
const QString& getAddress() const { return m_address; }
uint16_t getPort() const { return m_port; }
void setAddress(const QString& address);
void setPort(uint16_t port);
private slots:
void on_address_editingFinished();
void on_port_editingFinished();
void accept();
private:
Ui::WebsocketSpectrumSettingsDialog *ui;
QString m_address;
uint16_t m_port;
bool m_hasChanged;
};
#endif // BASICDEVICESETTINGSDIALOG_H

View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WebsocketSpectrumSettingsDialog</class>
<widget class="QDialog" name="WebsocketSpectrumSettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>394</width>
<height>77</height>
</rect>
</property>
<property name="font">
<font>
<family>Liberation Sans</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="windowTitle">
<string>Websocket spectrum settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="wsServerLayout">
<item>
<widget class="QLabel" name="addressLabel">
<property name="text">
<string>Addr</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="address">
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Reverse API address</string>
</property>
<property name="inputMask">
<string>000.000.000.000</string>
</property>
<property name="text">
<string>127.0.0.1</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="portLabel">
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="port">
<property name="minimumSize">
<size>
<width>45</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>45</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Reverse API port</string>
</property>
<property name="inputMask">
<string>00000</string>
</property>
<property name="text">
<string>8887</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>WebsocketSpectrumSettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>WebsocketSpectrumSettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>