1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-01 13:47:01 -04:00

RemoteTCPSink: Report server init errors via GUI. Send protocol to public list.

RemoteTCPInput: Add wss protocol support.
This commit is contained in:
srcejon
2024-10-08 17:20:18 +01:00
parent 04524505dd
commit 96422ff19f
21 changed files with 356 additions and 191 deletions
@@ -57,6 +57,7 @@ endif()
target_link_libraries(${TARGET_NAME} PRIVATE
Qt::Core
Qt::WebSockets
${TARGET_LIB}
sdrbase
${TARGET_LIB_GUI}
@@ -93,7 +93,7 @@ When unchecked, the channel sample rate can be set to any value.
Specifies number of bits per I/Q sample transmitted via TCP/IP.
When the protocol is RTL0, only 8-bits are supported. SDRA and Spy Server protocol supports 8, 16, 24 and 32-bit samples.
When the protocol is RTL0, only 8-bits are supported. SDRangel and Spy Server protocol supports 8, 16, 24 and 32-bit samples.
<h3>19: Server IP address</h3>
@@ -105,14 +105,16 @@ TCP port on the server to connect to.
<h3>21: Protocol</h3>
Selects protocol to use. Set to SDRangel for rtl_tcp, rsp_tcp or SDRangel's own protocol. Alternative, Spy Server can be selected to connect to Spy Servers.
Selects protocol to use. Set to SDRangel for rtl_tcp, rsp_tcp or SDRangel's own protocol.
Set to SDRangel wss to use SDRangel's protocol over WebSocket Secure.
Alternatively, Spy Server can be selected to connect to Spy Servers.
<h3>23: Connection settings</h3>
Determines which settings are used when connecting.
When checked, settings in the RemoteTCPInput GUI are written to the remote device upon connection.
When unchecked, if the remote server is using the SDRA protocol, the RemoteTCPInput GUI will be updated with the current settings from the remote device.
When unchecked, if the remote server is using the SDRangel protocol, the RemoteTCPInput GUI will be updated with the current settings from the remote device.
If the remote server is using the RTL0 protocol, the GUI will not be updated, which may mean the two are inconsistent.
<h3>24: Pre-fill</h3>
@@ -96,7 +96,7 @@ void RemoteTCPInput::destroy()
void RemoteTCPInput::init()
{
qDebug() << "*************** RemoteTCPInput::init";
qDebug() << "RemoteTCPInput::init";
applySettings(m_settings, QList<QString>(), true);
}
@@ -109,7 +109,6 @@ bool RemoteTCPInput::start()
}
m_remoteInputTCPPHandler->reset();
m_remoteInputTCPPHandler->start();
qDebug() << "************ RemoteTCPInput::start" << m_settings.m_dataAddress;
m_remoteInputTCPPHandler->getInputMessageQueue()->push(RemoteTCPInputTCPHandler::MsgConfigureTcpHandler::create(m_settings, QList<QString>(), true));
m_thread.start();
m_running = true;
@@ -122,19 +121,14 @@ void RemoteTCPInput::stop()
if (!m_running) {
// For wasm, important not to call m_remoteInputTCPPHandler->stop() twice
// as mutex can deadlock when this object is being deleted
qDebug() << "RemoteTCPInput::stop - Not running";
return;
}
m_remoteInputTCPPHandler->stop();
qDebug() << "RemoteTCPInput::stop1";
m_thread.quit();
qDebug() << "RemoteTCPInput::stop2";
#ifndef __EMSCRIPTEN__
qDebug() << "RemoteTCPInput::stop3";
m_thread.wait();
#endif
m_running = false;
qDebug() << "RemoteTCPInput::stopped";
}
QByteArray RemoteTCPInput::serialize() const
@@ -151,9 +145,6 @@ bool RemoteTCPInput::deserialize(const QByteArray& data)
m_settings.resetToDefaults();
success = false;
}
qDebug() << "************** RemoteTCPInput::deserialize" << m_settings.m_dataAddress;
MsgConfigureRemoteTCPInput* message = MsgConfigureRemoteTCPInput::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(message);
@@ -230,7 +221,6 @@ bool RemoteTCPInput::handleMessage(const Message& message)
{
qDebug() << "RemoteTCPInput::handleMessage:" << message.getIdentifier();
MsgConfigureRemoteTCPInput& conf = (MsgConfigureRemoteTCPInput&) message;
qDebug() << "*********** RemoteTCPInput::handleMessage MsgConfigureRemoteTCPInput" << m_settings.m_dataAddress;
applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce());
return true;
}
@@ -117,7 +117,7 @@ void RemoteTCPInputGui::destroy()
void RemoteTCPInputGui::resetToDefaults()
{
qDebug() << "*************** RemoteTCPInputGui::resetToDefaults";
qDebug() << "RemoteTCPInputGui::resetToDefaults";
m_settings.resetToDefaults();
displaySettings();
m_forceSettings = true;
@@ -158,7 +158,6 @@ bool RemoteTCPInputGui::handleMessage(const Message& message)
} else {
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
}
qDebug() << "********* RemoteTCPInputGui::handleMessage MsgConfigureRemoteTCPInput" << m_settings.m_dataAddress;
blockApplySettings(true);
displaySettings();
@@ -304,16 +303,7 @@ bool RemoteTCPInputGui::handleMessage(const Message& message)
{
const RemoteTCPInputTCPHandler::MsgReportConnection& report = (RemoteTCPInputTCPHandler::MsgReportConnection&) message;
qDebug() << "RemoteTCPInputGui::handleMessage: MsgReportConnection connected: " << report.getConnected();
if (report.getConnected())
{
m_connectionError = false;
//ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
}
else
{
m_connectionError = true;
//ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
}
m_connectionError = !report.getConnected();
updateStatus();
return true;
}
@@ -921,14 +911,18 @@ void RemoteTCPInputGui::on_squelchGate_valueChanged(double value)
void RemoteTCPInputGui::on_dataAddress_editingFinished()
{
m_settings.m_dataAddress = ui->dataAddress->currentText();
m_settingsKeys.append("dataAddress");
m_settings.m_addressList.clear();
for (int i = 0; i < ui->dataAddress->count(); i++) {
m_settings.m_addressList.append(ui->dataAddress->itemText(i));
QString text = ui->dataAddress->currentText();
if (text != m_settings.m_dataAddress)
{
m_settings.m_dataAddress = text;
m_settingsKeys.append("dataAddress");
m_settings.m_addressList.clear();
for (int i = 0; i < ui->dataAddress->count(); i++) {
m_settings.m_addressList.append(ui->dataAddress->itemText(i));
}
m_settingsKeys.append("addressList");
sendSettings();
}
m_settingsKeys.append("addressList");
sendSettings();
}
void RemoteTCPInputGui::on_dataAddress_currentIndexChanged(int index)
@@ -89,7 +89,7 @@
<string>00000k</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
@@ -100,7 +100,7 @@
<item>
<spacer name="freqLeftSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -134,7 +134,7 @@
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
<enum>Qt::FocusPolicy::StrongFocus</enum>
</property>
<property name="toolTip">
<string>Center frequency in kHz</string>
@@ -153,14 +153,14 @@
<string> kHz</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -199,7 +199,7 @@
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -215,7 +215,7 @@
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
@@ -224,7 +224,7 @@
<item>
<widget class="Line" name="line_rateTime">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -253,7 +253,7 @@
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -288,7 +288,7 @@
<item>
<widget class="Line" name="line_address">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -342,7 +342,7 @@
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -415,7 +415,7 @@
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -459,14 +459,14 @@
<string>40.0dB</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="Line" name="gainLine1">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
</widget>
</item>
@@ -500,7 +500,7 @@
<item>
<widget class="Line" name="gainLine2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
</widget>
</item>
@@ -534,7 +534,7 @@
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -559,7 +559,7 @@
<item>
<widget class="Line" name="line_rfBW">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -609,7 +609,7 @@
<item>
<spacer name="rfBWSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -624,7 +624,7 @@
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -669,7 +669,7 @@
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
<enum>Qt::FocusPolicy::StrongFocus</enum>
</property>
<property name="toolTip">
<string>Channel shift frequency from center in Hz</string>
@@ -686,7 +686,7 @@
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -804,7 +804,7 @@ Use to ensure full dynamic range of 8-bit data is used.</string>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -866,7 +866,7 @@ Use to ensure full dynamic range of 8-bit data is used.</string>
<item>
<widget class="Line" name="line_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -921,7 +921,7 @@ Use to ensure full dynamic range of 8-bit data is used.</string>
<item>
<widget class="Line" name="line_12">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
</widget>
</item>
@@ -959,7 +959,7 @@ Use to ensure full dynamic range of 8-bit data is used.</string>
<string>-150</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
@@ -973,7 +973,7 @@ Use to ensure full dynamic range of 8-bit data is used.</string>
<item>
<widget class="Line" name="line_13">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
</widget>
</item>
@@ -993,14 +993,14 @@ Use to ensure full dynamic range of 8-bit data is used.</string>
<item>
<widget class="Line" name="line_14">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -1022,13 +1022,13 @@ Use to ensure full dynamic range of 8-bit data is used.</string>
<string>Channel power</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
<enum>Qt::LayoutDirection::RightToLeft</enum>
</property>
<property name="text">
<string>0.0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
@@ -1044,7 +1044,7 @@ Use to ensure full dynamic range of 8-bit data is used.</string>
<item>
<widget class="Line" name="line_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -1065,6 +1065,12 @@ Use to ensure full dynamic range of 8-bit data is used.</string>
</item>
<item>
<widget class="QComboBox" name="dataAddress">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
@@ -1110,7 +1116,7 @@ Use to ensure full dynamic range of 8-bit data is used.</string>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -1124,7 +1130,7 @@ Use to ensure full dynamic range of 8-bit data is used.</string>
<widget class="QComboBox" name="protocol">
<property name="minimumSize">
<size>
<width>92</width>
<width>110</width>
<height>0</height>
</size>
</property>
@@ -1136,6 +1142,11 @@ Use to ensure full dynamic range of 8-bit data is used.</string>
<string>SDRangel</string>
</property>
</item>
<item>
<property name="text">
<string>SDRangel wss</string>
</property>
</item>
<item>
<property name="text">
<string>Spy Server</string>
@@ -1200,7 +1211,7 @@ When unchecked, if remote device is using SDRA protocol, local settings are upda
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
</widget>
</item>
@@ -1263,14 +1274,14 @@ When unchecked, if remote device is using SDRA protocol, local settings are upda
<string>10.00s</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="Line" name="buferLine">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
</widget>
</item>
@@ -1328,7 +1339,7 @@ This should typically be empty. If full, your CPU cannot keep up and data will b
<item>
<widget class="Line" name="line_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -1390,7 +1401,7 @@ This should typically be empty. If full, your CPU cannot keep up and data will b
<string>Messages</string>
</property>
<property name="movement">
<enum>QListView::Static</enum>
<enum>QListView::Movement::Static</enum>
</property>
</widget>
</item>
@@ -1399,7 +1410,7 @@ This should typically be empty. If full, your CPU cannot keep up and data will b
<item>
<widget class="Line" name="line_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -1427,7 +1438,7 @@ This should typically be empty. If full, your CPU cannot keep up and data will b
<number>500</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -1504,7 +1515,7 @@ This should typically be empty. If full, your CPU cannot keep up and data will b
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
@@ -1520,7 +1531,7 @@ This should typically be empty. If full, your CPU cannot keep up and data will b
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
</widget>
</item>
@@ -1547,18 +1558,18 @@ This should typically be empty. If full, your CPU cannot keep up and data will b
<header>gui/valuedialz.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ValueDial</class>
<extends>QWidget</extends>
<header>gui/valuedial.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LevelMeterSignalDB</class>
<extends>QWidget</extends>
<header>gui/levelmeter.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ValueDial</class>
<extends>QWidget</extends>
<header>gui/valuedial.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>PeriodDial</class>
<extends>QWidget</extends>
@@ -1583,10 +1594,23 @@ This should typically be empty. If full, your CPU cannot keep up and data will b
<tabstop>channelGain</tabstop>
<tabstop>decimation</tabstop>
<tabstop>sampleBits</tabstop>
<tabstop>squelchEnabled</tabstop>
<tabstop>squelch</tabstop>
<tabstop>dataAddress</tabstop>
<tabstop>dataPort</tabstop>
<tabstop>protocol</tabstop>
<tabstop>overrideRemoteSettings</tabstop>
<tabstop>preFill</tabstop>
<tabstop>sendMessage</tabstop>
<tabstop>txAddress</tabstop>
<tabstop>txMessage</tabstop>
<tabstop>messages</tabstop>
<tabstop>replayOffset</tabstop>
<tabstop>replayNow</tabstop>
<tabstop>replayPlus</tabstop>
<tabstop>replayMinus</tabstop>
<tabstop>replayLoop</tabstop>
<tabstop>replaySave</tabstop>
</tabstops>
<resources>
<include location="../../../sdrgui/resources/res.qrc"/>
@@ -53,7 +53,7 @@ struct RemoteTCPInputSettings
uint16_t m_reverseAPIPort;
uint16_t m_reverseAPIDeviceIndex;
QStringList m_addressList; // List of dataAddresses that have been used in the past
QString m_protocol; // "SDRangel" or "Spy Server"
QString m_protocol; // "SDRangel", "SDRangel wss" or "Spy Server"
float m_replayOffset; //!< Replay offset in seconds
float m_replayLength; //!< Replay buffer size in seconds
float m_replayStep; //!< Replay forward/back step size in seconds
@@ -18,6 +18,7 @@
///////////////////////////////////////////////////////////////////////////////////
#include <QDebug>
#include <QMessageBox>
#include <cstring>
#include "device/deviceapi.h"
@@ -36,6 +37,8 @@ RemoteTCPInputTCPHandler::RemoteTCPInputTCPHandler(SampleSinkFifo *sampleFifo, D
m_deviceAPI(deviceAPI),
m_running(false),
m_dataSocket(nullptr),
m_tcpSocket(nullptr),
m_webSocket(nullptr),
m_tcpBuf(nullptr),
m_sampleFifo(sampleFifo),
m_replayBuffer(replayBuffer),
@@ -82,9 +85,7 @@ RemoteTCPInputTCPHandler::~RemoteTCPInputTCPHandler()
if (m_converterBuffer) {
delete[] m_converterBuffer;
}
qDebug() << "RemoteTCPInputTCPHandler::~RemoteTCPInputTCPHandler cleanup";
cleanup();
qDebug() << "RemoteTCPInputTCPHandler::~RemoteTCPInputTCPHandler done";
}
void RemoteTCPInputTCPHandler::reset()
@@ -114,7 +115,6 @@ void RemoteTCPInputTCPHandler::start()
void RemoteTCPInputTCPHandler::stop()
{
qDebug("RemoteTCPInputTCPHandler::stop locking");
QMutexLocker mutexLocker(&m_mutex);
qDebug("RemoteTCPInputTCPHandler::stop");
@@ -142,24 +142,40 @@ void RemoteTCPInputTCPHandler::finished()
cleanup();
disconnect(thread(), SIGNAL(finished()), this, SLOT(finished()));
m_running = false;
qDebug("RemoteTCPInputTCPHandler::finished done");
}
void RemoteTCPInputTCPHandler::connectToHost(const QString& address, quint16 port)
void RemoteTCPInputTCPHandler::connectToHost(const QString& address, quint16 port, const QString& protocol)
{
qDebug("RemoteTCPInputTCPHandler::connectToHost: connect to %s:%d", address.toStdString().c_str(), port);
m_dataSocket = new QTcpSocket(this);
qDebug("RemoteTCPInputTCPHandler::connectToHost: connect to %s %s:%d", protocol.toStdString().c_str(), address.toStdString().c_str(), port);
m_fillBuffer = true;
m_readMetaData = false;
connect(m_dataSocket, SIGNAL(readyRead()), this, SLOT(dataReadyRead()));
connect(m_dataSocket, SIGNAL(connected()), this, SLOT(connected()));
connect(m_dataSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
connect(m_dataSocket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), this, &RemoteTCPInputTCPHandler::errorOccurred);
#else
connect(m_dataSocket, &QAbstractSocket::errorOccurred, this, &RemoteTCPInputTCPHandler::errorOccurred);
if (protocol == "SDRangel wss")
{
m_webSocket = new QWebSocket(QString(), QWebSocketProtocol::VersionLatest, this);
connect(m_webSocket, &QWebSocket::binaryFrameReceived, this, &RemoteTCPInputTCPHandler::dataReadyRead);
connect(m_webSocket, &QWebSocket::connected, this, &RemoteTCPInputTCPHandler::connected);
connect(m_webSocket, &QWebSocket::disconnected, this, &RemoteTCPInputTCPHandler::disconnected);
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
connect(m_webSocket, &QWebSocket::errorOccurred, this, &RemoteTCPInputTCPHandler::errorOccurred);
#endif
m_dataSocket->connectToHost(address, port);
connect(m_webSocket, &QWebSocket::sslErrors, this, &RemoteTCPInputTCPHandler::sslErrors);
m_webSocket->open(QUrl(QString("wss://%1:%2").arg(address).arg(port)));
m_dataSocket = new WebSocket(m_webSocket);
}
else
{
m_tcpSocket = new QTcpSocket(this);
connect(m_tcpSocket, SIGNAL(readyRead()), this, SLOT(dataReadyRead()));
connect(m_tcpSocket, SIGNAL(connected()), this, SLOT(connected()));
connect(m_tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
connect(m_tcpSocket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), this, &RemoteTCPInputTCPHandler::errorOccurred);
#else
connect(m_tcpSocket, &QAbstractSocket::errorOccurred, this, &RemoteTCPInputTCPHandler::errorOccurred);
#endif
m_tcpSocket->connectToHost(address, port);
m_dataSocket = new TCPSocket(m_tcpSocket);
}
}
/*void RemoteTCPInputTCPHandler::disconnectFromHost()
@@ -187,22 +203,45 @@ void RemoteTCPInputTCPHandler::cleanup()
FLAC__stream_decoder_delete(m_decoder);
m_decoder = nullptr;
}
if (m_webSocket)
{
qDebug() << "RemoteTCPInputTCPHandler::cleanup: Closing and deleting web socket";
disconnect(m_webSocket, &QWebSocket::binaryFrameReceived, this, &RemoteTCPInputTCPHandler::dataReadyRead);
disconnect(m_webSocket, &QWebSocket::connected, this, &RemoteTCPInputTCPHandler::connected);
disconnect(m_webSocket, &QWebSocket::disconnected, this, &RemoteTCPInputTCPHandler::disconnected);
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
disconnect(m_webSocket, &QWebSocket::errorOccurred, this, &RemoteTCPInputTCPHandler::errorOccurred);
#endif
}
if (m_tcpSocket)
{
qDebug() << "RemoteTCPInputTCPHandler::cleanup: Closing and deleting TCP socket";
// Disconnect disconnected, so don't get called recursively
disconnect(m_tcpSocket, SIGNAL(readyRead()), this, SLOT(dataReadyRead()));
disconnect(m_tcpSocket, SIGNAL(connected()), this, SLOT(connected()));
disconnect(m_tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
disconnect(m_tcpSocket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), this, &RemoteTCPInputTCPHandler::errorOccurred);
#else
disconnect(m_tcpSocket, &QAbstractSocket::errorOccurred, this, &RemoteTCPInputTCPHandler::errorOccurred);
#endif
}
if (m_dataSocket)
{
qDebug() << "RemoteTCPInputTCPHandler::cleanup: Closing and deleting socket";
// Disconnect disconnected, so don't get called recursively
disconnect(m_dataSocket, SIGNAL(readyRead()), this, SLOT(dataReadyRead()));
disconnect(m_dataSocket, SIGNAL(connected()), this, SLOT(connected()));
disconnect(m_dataSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
disconnect(m_dataSocket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), this, &RemoteTCPInputTCPHandler::errorOccurred);
#else
disconnect(m_dataSocket, &QAbstractSocket::errorOccurred, this, &RemoteTCPInputTCPHandler::errorOccurred);
#endif
m_dataSocket->close();
m_dataSocket->deleteLater();
m_dataSocket = nullptr;
}
if (m_webSocket)
{
m_webSocket->deleteLater();
m_webSocket = nullptr;
}
if (m_tcpSocket)
{
m_tcpSocket->deleteLater();
m_tcpSocket = nullptr;
}
}
// Clear input buffer when settings change that invalidate the data in it
@@ -620,7 +659,7 @@ void RemoteTCPInputTCPHandler::applySettings(const RemoteTCPInputSettings& setti
{
//disconnectFromHost();
cleanup();
connectToHost(settings.m_dataAddress, settings.m_dataPort);
connectToHost(settings.m_dataAddress, settings.m_dataPort, settings.m_protocol);
}
if (force) {
@@ -651,35 +690,6 @@ static void flacErrorCallback(const FLAC__StreamDecoder *decoder, FLAC__StreamDe
return handler->flacError(decoder, status);
}
/*FLAC__StreamDecoderReadStatus RemoteTCPInputTCPHandler::flacRead(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
{
if (m_dataSocket)
{
qint64 bytesRequested = *bytes;
qint64 bytesRead = std::min(bytesRequested, m_compressedData.size());
//bytesRead = m_dataSocket->read((char *) buffer, bytesRequested);
memcpy(buffer, m_compressedData.constData(), bytesRead);
qDebug() << "flacRead" << bytesRequested << bytesRead;
if (bytesRead != -1)
{
*bytes = (size_t) bytesRead;
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
else
{
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
}
}
else
{
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
}
}*/
FLAC__StreamDecoderReadStatus RemoteTCPInputTCPHandler::flacRead(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
{
(void) decoder;
@@ -690,7 +700,6 @@ FLAC__StreamDecoderReadStatus RemoteTCPInputTCPHandler::flacRead(const FLAC__Str
memcpy(buffer, m_compressedData.constData(), bytesRead);
m_compressedData.remove(0, bytesRead);
//qDebug() << "RemoteTCPInputTCPHandler::flacRead bytesRequested" << bytesRequested << "bytesRead" << bytesRead;
if (bytesRead == 0)
{
qDebug() << "RemoteTCPInputTCPHandler::flacRead: Decoder will hang if we can't return data";
@@ -821,7 +830,6 @@ FLAC__StreamDecoderWriteStatus RemoteTCPInputTCPHandler::flacWrite(const FLAC__S
m_uncompressedFrames++;
int nbSamples = frame->header.blocksize;
//qDebug() << "RemoteTCPInputTCPHandler::flacWrite m_uncompressedFrames" << m_uncompressedFrames << "nbSamples" << nbSamples;
if (nbSamples > (int) m_converterBufferNbSamples)
{
if (m_converterBuffer) {
@@ -1011,20 +1019,13 @@ void RemoteTCPInputTCPHandler::connected()
}
// Start calls to processData
m_timer.start();
/*if (m_dataSocket->bytesAvailable()) {
qDebug() << "Data is already available";
dataReadyRead();
} else {
qDebug() << "No data available";
}*/
}
void RemoteTCPInputTCPHandler::reconnect()
{
QMutexLocker mutexLocker(&m_mutex);
if (!m_dataSocket) {
connectToHost(m_settings.m_dataAddress, m_settings.m_dataPort);
connectToHost(m_settings.m_dataAddress, m_settings.m_dataPort, m_settings.m_protocol);
}
}
@@ -1071,6 +1072,12 @@ void RemoteTCPInputTCPHandler::errorOccurred(QAbstractSocket::SocketError socket
}
}
void RemoteTCPInputTCPHandler::sslErrors(const QList<QSslError> &errors)
{
qDebug() << "RemoteTCPInputTCPHandler::sslErrors: " << errors;
m_webSocket->ignoreSslErrors(); // FIXME: Add a setting whether to do this?
}
void RemoteTCPInputTCPHandler::dataReadyRead()
{
QMutexLocker mutexLocker(&m_mutex);
@@ -1753,7 +1760,6 @@ void RemoteTCPInputTCPHandler::processCommands()
m_compressedData.resize(s + m_commandLength);
qint64 bytesRead = m_dataSocket->read(&m_compressedData.data()[s], m_commandLength);
m_compressedFrames++;
//qDebug() << "*************************** RemoteTCPProtocol::dataIQFLAC m_compressedData.size()" << m_compressedData.size() << "m_compressedFrames" << m_compressedFrames << "m_uncompressedFrames" << m_uncompressedFrames;
if (bytesRead == m_commandLength)
{
// FLAC encoder writes out 4 (fLaC), 38 (STREAMINFO), 51 (?) byte headers, that are transmitted as one command block,
@@ -1940,7 +1946,7 @@ void RemoteTCPInputTCPHandler::processData()
{
QMutexLocker mutexLocker(&m_mutex);
if (m_dataSocket && (m_dataSocket->state() == QAbstractSocket::ConnectedState))
if (m_dataSocket && m_dataSocket->isConnected())
{
int sampleRate = m_settings.m_channelSampleRate;
int bytesPerIQPair = m_iqOnly ? (2 * m_settings.m_sampleBits / 8) : (2 * sizeof(Sample));
@@ -22,6 +22,7 @@
#include <QObject>
#include <QTcpSocket>
#include <QWebSocket>
#include <QHostAddress>
#include <QRecursiveMutex>
#include <QDateTime>
@@ -31,6 +32,7 @@
#include "util/messagequeue.h"
#include "util/movingaverage.h"
#include "util/socket.h"
#include "dsp/replaybuffer.h"
#include "remotetcpinputsettings.h"
#include "../../channelrx/remotetcpsink/remotetcpprotocol.h"
@@ -185,6 +187,7 @@ public slots:
void connected();
void disconnected();
void errorOccurred(QAbstractSocket::SocketError socketError);
void sslErrors(const QList<QSslError> &errors);
private:
@@ -200,7 +203,9 @@ private:
DeviceAPI *m_deviceAPI;
bool m_running;
QTcpSocket *m_dataSocket;
Socket *m_dataSocket;
QTcpSocket *m_tcpSocket;
QWebSocket *m_webSocket;
char *m_tcpBuf;
SampleSinkFifo *m_sampleFifo;
ReplayBuffer<FixReal> *m_replayBuffer;
@@ -253,7 +258,7 @@ private:
MovingAverageUtil<Real, double, 16> m_movingAverage;
bool handleMessage(const Message& message);
void connectToHost(const QString& address, quint16 port);
void connectToHost(const QString& address, quint16 port, const QString& protocol);
//void disconnectFromHost();
void cleanup();
void clearBuffer();