2022-07-19 05:10:20 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2023-11-18 06:02:48 -05:00
|
|
|
// Copyright (C) 2018-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
|
|
|
// Copyright (C) 2020 Kacper Michajłow <kasper93@gmail.com> //
|
|
|
|
// Copyright (C) 2022-2023 Jon Beniston, M7RCE <jon@beniston.com> //
|
2022-07-19 05:10:20 -04:00
|
|
|
// //
|
|
|
|
// 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 INCLUDE_REMOTETCPSINK_H_
|
|
|
|
#define INCLUDE_REMOTETCPSINK_H_
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QNetworkRequest>
|
|
|
|
#include <QThread>
|
|
|
|
|
|
|
|
#include "dsp/basebandsamplesink.h"
|
|
|
|
#include "channel/channelapi.h"
|
|
|
|
#include "remotetcpsinkbaseband.h"
|
|
|
|
|
|
|
|
class QNetworkAccessManager;
|
|
|
|
class QNetworkReply;
|
|
|
|
class DeviceAPI;
|
|
|
|
class ObjectPipe;
|
|
|
|
|
|
|
|
class RemoteTCPSink : public BasebandSampleSink, public ChannelAPI {
|
|
|
|
public:
|
|
|
|
class MsgConfigureRemoteTCPSink : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
const RemoteTCPSinkSettings& getSettings() const { return m_settings; }
|
2023-09-15 04:30:49 -04:00
|
|
|
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
|
2022-07-19 05:10:20 -04:00
|
|
|
bool getForce() const { return m_force; }
|
2024-09-22 05:44:30 -04:00
|
|
|
bool getRestartRequired() const { return m_restartRequired; }
|
2022-07-19 05:10:20 -04:00
|
|
|
|
2024-09-22 05:44:30 -04:00
|
|
|
static MsgConfigureRemoteTCPSink* create(const RemoteTCPSinkSettings& settings, const QList<QString>& settingsKeys, bool force, bool restartRequired = false)
|
2022-07-19 05:10:20 -04:00
|
|
|
{
|
2024-09-22 05:44:30 -04:00
|
|
|
return new MsgConfigureRemoteTCPSink(settings, settingsKeys, force, restartRequired);
|
2022-07-19 05:10:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RemoteTCPSinkSettings m_settings;
|
2023-09-15 04:30:49 -04:00
|
|
|
QList<QString> m_settingsKeys;
|
2022-07-19 05:10:20 -04:00
|
|
|
bool m_force;
|
2024-09-22 05:44:30 -04:00
|
|
|
bool m_restartRequired;
|
2022-07-19 05:10:20 -04:00
|
|
|
|
2024-09-22 05:44:30 -04:00
|
|
|
MsgConfigureRemoteTCPSink(const RemoteTCPSinkSettings& settings, const QList<QString>& settingsKeys, bool force, bool restartRequired) :
|
2022-07-19 05:10:20 -04:00
|
|
|
Message(),
|
|
|
|
m_settings(settings),
|
2023-09-15 04:30:49 -04:00
|
|
|
m_settingsKeys(settingsKeys),
|
2022-07-19 05:10:20 -04:00
|
|
|
m_force(force),
|
2024-09-22 05:44:30 -04:00
|
|
|
m_restartRequired(restartRequired)
|
2022-07-19 05:10:20 -04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
class MsgReportConnection : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
int getClients() const { return m_clients; }
|
2024-09-22 05:44:30 -04:00
|
|
|
const QHostAddress& getAddress() const { return m_address; }
|
|
|
|
int getPort() const { return m_port; }
|
2022-07-19 05:10:20 -04:00
|
|
|
|
2024-09-22 05:44:30 -04:00
|
|
|
|
|
|
|
static MsgReportConnection* create(int clients, const QHostAddress& address, quint16 port)
|
2022-07-19 05:10:20 -04:00
|
|
|
{
|
2024-09-22 05:44:30 -04:00
|
|
|
return new MsgReportConnection(clients, address, port);
|
2022-07-19 05:10:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_clients;
|
2024-09-22 05:44:30 -04:00
|
|
|
QHostAddress m_address;
|
|
|
|
quint16 m_port;
|
2022-07-19 05:10:20 -04:00
|
|
|
|
2024-09-22 05:44:30 -04:00
|
|
|
MsgReportConnection(int clients, const QHostAddress& address, quint16 port) :
|
2022-07-19 05:10:20 -04:00
|
|
|
Message(),
|
2024-09-22 05:44:30 -04:00
|
|
|
m_clients(clients),
|
|
|
|
m_address(address),
|
|
|
|
m_port(port)
|
2022-07-19 05:10:20 -04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2024-09-22 05:44:30 -04:00
|
|
|
class MsgReportDisconnect : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
int getClients() const { return m_clients; }
|
|
|
|
const QHostAddress& getAddress() const { return m_address; }
|
|
|
|
quint16 getPort() const { return m_port; }
|
|
|
|
|
|
|
|
static MsgReportDisconnect* create(int clients, const QHostAddress& address, quint16 port)
|
|
|
|
{
|
|
|
|
return new MsgReportDisconnect(clients, address, port);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_clients;
|
|
|
|
QHostAddress m_address;
|
|
|
|
quint16 m_port;
|
|
|
|
|
|
|
|
MsgReportDisconnect(int clients, const QHostAddress& address, quint16 port) :
|
|
|
|
Message(),
|
|
|
|
m_clients(clients),
|
|
|
|
m_address(address),
|
|
|
|
m_port(port)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Message to report actual transmit bandwidth in bits per second and compression ratio
|
2022-07-19 05:10:20 -04:00
|
|
|
class MsgReportBW : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
float getBW() const { return m_bw; }
|
2024-09-22 05:44:30 -04:00
|
|
|
float getNetworkBW() const { return m_networkBW; }
|
|
|
|
qint64 getBytesUncompressed() const { return m_bytesUncompressed; }
|
|
|
|
qint64 getBytesCompressed() const { return m_bytesCompressed; }
|
|
|
|
qint64 getBytesTransmitted() const { return m_bytesTransmitted; }
|
2022-07-19 05:10:20 -04:00
|
|
|
|
2024-09-22 05:44:30 -04:00
|
|
|
static MsgReportBW* create(float bw, float networkBW, qint64 bytesUncompressed, qint64 bytesCompressed, qint64 bytesTransmitted)
|
2022-07-19 05:10:20 -04:00
|
|
|
{
|
2024-09-22 05:44:30 -04:00
|
|
|
return new MsgReportBW(bw, networkBW, bytesUncompressed, bytesCompressed, bytesTransmitted);
|
2022-07-19 05:10:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
float m_bw;
|
2024-09-22 05:44:30 -04:00
|
|
|
float m_networkBW;
|
|
|
|
qint64 m_bytesUncompressed;
|
|
|
|
qint64 m_bytesCompressed;
|
|
|
|
qint64 m_bytesTransmitted;
|
|
|
|
|
|
|
|
MsgReportBW(float bw, float networkBW, qint64 bytesUncompressed, qint64 bytesCompressed, qint64 bytesTransmitted) :
|
|
|
|
Message(),
|
|
|
|
m_bw(bw),
|
|
|
|
m_networkBW(networkBW),
|
|
|
|
m_bytesUncompressed(bytesUncompressed),
|
|
|
|
m_bytesCompressed(bytesCompressed),
|
|
|
|
m_bytesTransmitted(bytesTransmitted)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Send a text message to a client (or received message from client)
|
|
|
|
class MsgSendMessage : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
2022-07-19 05:10:20 -04:00
|
|
|
|
2024-09-22 05:44:30 -04:00
|
|
|
public:
|
|
|
|
QHostAddress getAddress() const { return m_address; }
|
|
|
|
quint16 getPort() const { return m_port; }
|
|
|
|
const QString& getCallsign() const { return m_callsign; }
|
|
|
|
const QString& getText() const { return m_text; }
|
|
|
|
bool getBroadcast() const { return m_broadcast; }
|
|
|
|
|
|
|
|
static MsgSendMessage* create(QHostAddress address, quint16 port, const QString& callsign, const QString& text, bool broadcast)
|
|
|
|
{
|
|
|
|
return new MsgSendMessage(address, port, callsign, text, broadcast);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QHostAddress m_address;
|
|
|
|
quint16 m_port;
|
|
|
|
QString m_callsign;
|
|
|
|
QString m_text;
|
|
|
|
bool m_broadcast;
|
|
|
|
|
|
|
|
MsgSendMessage(QHostAddress address, quint16 port, const QString& callsign, const QString& text, bool broadcast) :
|
2022-07-19 05:10:20 -04:00
|
|
|
Message(),
|
2024-09-22 05:44:30 -04:00
|
|
|
m_address(address),
|
|
|
|
m_port(port),
|
|
|
|
m_callsign(callsign),
|
|
|
|
m_text(text),
|
|
|
|
m_broadcast(broadcast)
|
2022-07-19 05:10:20 -04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2024-10-08 12:20:18 -04:00
|
|
|
class MsgError : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
const QString& getError() const { return m_error; }
|
|
|
|
|
|
|
|
static MsgError *create(const QString& error)
|
|
|
|
{
|
|
|
|
return new MsgError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_error;
|
|
|
|
|
2024-10-08 17:19:29 -04:00
|
|
|
explicit MsgError(const QString& error) :
|
2024-10-08 12:20:18 -04:00
|
|
|
Message(),
|
|
|
|
m_error(error)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2022-07-19 05:10:20 -04:00
|
|
|
RemoteTCPSink(DeviceAPI *deviceAPI);
|
|
|
|
virtual ~RemoteTCPSink();
|
|
|
|
virtual void destroy() { delete this; }
|
|
|
|
virtual void setDeviceAPI(DeviceAPI *deviceAPI);
|
|
|
|
virtual DeviceAPI *getDeviceAPI() { return m_deviceAPI; }
|
|
|
|
|
|
|
|
using BasebandSampleSink::feed;
|
|
|
|
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po);
|
|
|
|
virtual void start();
|
|
|
|
virtual void stop();
|
|
|
|
virtual void pushMessage(Message *msg) { m_inputMessageQueue.push(msg); }
|
|
|
|
virtual QString getSinkName() { return objectName(); }
|
|
|
|
|
|
|
|
virtual void getIdentifier(QString& id) { id = objectName(); }
|
|
|
|
virtual QString getIdentifier() const { return objectName(); }
|
|
|
|
virtual void getTitle(QString& title) { title = "Remote Sink"; }
|
|
|
|
virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; }
|
|
|
|
virtual void setCenterFrequency(qint64 frequency);
|
|
|
|
|
|
|
|
virtual QByteArray serialize() const;
|
|
|
|
virtual bool deserialize(const QByteArray& data);
|
|
|
|
|
|
|
|
virtual int getNbSinkStreams() const { return 1; }
|
|
|
|
virtual int getNbSourceStreams() const { return 0; }
|
2023-12-13 13:24:26 -05:00
|
|
|
virtual int getStreamIndex() const { return m_settings.m_streamIndex; }
|
2022-07-19 05:10:20 -04:00
|
|
|
|
|
|
|
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
|
|
|
|
{
|
|
|
|
(void) streamIndex;
|
|
|
|
(void) sinkElseSource;
|
|
|
|
return m_settings.m_inputFrequencyOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
|
|
|
QString& errorMessage);
|
|
|
|
|
|
|
|
virtual int webapiWorkspaceGet(
|
|
|
|
SWGSDRangel::SWGWorkspaceInfo& response,
|
|
|
|
QString& errorMessage);
|
|
|
|
|
|
|
|
virtual int webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
|
|
|
QString& errorMessage);
|
|
|
|
|
|
|
|
static void webapiFormatChannelSettings(
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
|
|
|
const RemoteTCPSinkSettings& settings);
|
|
|
|
|
|
|
|
static void webapiUpdateChannelSettings(
|
|
|
|
RemoteTCPSinkSettings& settings,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response);
|
|
|
|
|
|
|
|
uint32_t getNumberOfDeviceStreams() const;
|
|
|
|
int getBasebandSampleRate() const { return m_basebandSampleRate; }
|
|
|
|
|
2024-09-22 05:44:30 -04:00
|
|
|
bool getSquelchOpen() const { return m_basebandSink && m_basebandSink->getSquelchOpen(); }
|
|
|
|
|
|
|
|
void getMagSqLevels(double& avg, double& peak, int& nbSamples)
|
|
|
|
{
|
|
|
|
if (m_basebandSink) {
|
|
|
|
m_basebandSink->getMagSqLevels(avg, peak, nbSamples);
|
|
|
|
} else {
|
|
|
|
avg = 0.0; peak = 0.0; nbSamples = 1;
|
|
|
|
}
|
|
|
|
}
|
2024-08-25 17:36:46 -04:00
|
|
|
void setMessageQueueToGUI(MessageQueue* queue) final {
|
2022-07-19 05:10:20 -04:00
|
|
|
ChannelAPI::setMessageQueueToGUI(queue);
|
|
|
|
m_basebandSink->setMessageQueueToGUI(queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* const m_channelIdURI;
|
|
|
|
static const char* const m_channelId;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DeviceAPI *m_deviceAPI;
|
|
|
|
QThread m_thread;
|
|
|
|
RemoteTCPSinkBaseband *m_basebandSink;
|
|
|
|
RemoteTCPSinkSettings m_settings;
|
|
|
|
|
|
|
|
int m_basebandSampleRate;
|
|
|
|
|
|
|
|
QNetworkAccessManager *m_networkManager;
|
|
|
|
QNetworkRequest m_networkRequest;
|
|
|
|
|
2024-09-22 05:44:30 -04:00
|
|
|
int m_clients; // Number of clients currently connected
|
|
|
|
QNetworkReply *m_removeRequest;
|
|
|
|
|
2022-07-19 05:10:20 -04:00
|
|
|
virtual bool handleMessage(const Message& cmd);
|
2024-09-22 05:44:30 -04:00
|
|
|
void applySettings(const RemoteTCPSinkSettings& settings, const QStringList& settingsKeys, bool force = false, bool restartRequired = false);
|
2023-09-15 04:30:49 -04:00
|
|
|
void webapiReverseSendSettings(const QStringList& channelSettingsKeys, const RemoteTCPSinkSettings& settings, bool force);
|
2022-07-19 05:10:20 -04:00
|
|
|
void sendChannelSettings(
|
|
|
|
const QList<ObjectPipe*>& pipes,
|
2023-09-15 04:30:49 -04:00
|
|
|
const QStringList& channelSettingsKeys,
|
2022-07-19 05:10:20 -04:00
|
|
|
const RemoteTCPSinkSettings& settings,
|
|
|
|
bool force
|
|
|
|
);
|
|
|
|
void webapiFormatChannelSettings(
|
2023-09-15 04:30:49 -04:00
|
|
|
const QStringList& channelSettingsKeys,
|
2022-07-19 05:10:20 -04:00
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings,
|
|
|
|
const RemoteTCPSinkSettings& settings,
|
|
|
|
bool force
|
|
|
|
);
|
2024-09-22 05:44:30 -04:00
|
|
|
void removePublicListing(const QString& address, quint16 port);
|
|
|
|
void updatePublicListing();
|
2022-07-19 05:10:20 -04:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void networkManagerFinished(QNetworkReply *reply);
|
|
|
|
void handleIndexInDeviceSetChanged(int index);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* INCLUDE_REMOTETCPSINK_H_ */
|