Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote TCP improvements #1830

Merged
merged 7 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions plugins/channelrx/demodm17/m17demod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,13 @@ void M17Demod::applySettings(const M17DemodSettings& settings, const QList<QStri
m_basebandSink->getInputMessageQueue()->push(msg);
}

if (settingsKeys.contains("m_useReverseAPI"))
if (settingsKeys.contains("useReverseAPI"))
{
bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
(m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
(m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
(m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex) ||
(m_settings.m_reverseAPIChannelIndex != settings.m_reverseAPIChannelIndex);
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
settingsKeys.contains("reverseAPIAddress") ||
settingsKeys.contains("reverseAPIPort") ||
settingsKeys.contains("reverseAPIDeviceIndex") ||
settingsKeys.contains("reverseAPIChannelIndex");
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
}

Expand Down
1 change: 1 addition & 0 deletions plugins/channelrx/demodm17/m17demodgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ void M17DemodGUI::onWidgetRolled(QWidget* widget, bool rollDown)
(void) rollDown;

getRollupContents()->saveState(m_rollupState);
applySettings({"rollupState"});
}

void M17DemodGUI::onMenuDialogCalled(const QPoint &p)
Expand Down
6 changes: 5 additions & 1 deletion plugins/channelrx/localsink/localsinkbaseband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ void LocalSinkBaseband::applySettings(const LocalSinkSettings& settings, const Q
}

m_sink.applySettings(settings, settingsKeys, force);
m_settings = settings;
if (force) {
m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
}

int LocalSinkBaseband::getChannelSampleRate() const
Expand Down
2 changes: 1 addition & 1 deletion plugins/channelrx/remotetcpsink/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Specifies number of bits per I/Q sample transmitted via TCP/IP.

<h3>5: IP address</h3>

IP address of the local network interface on which the server will listen for TCP/IP connections from network clients.
IP address of the local network interface on which the server will listen for TCP/IP connections from network clients. Use 0.0.0.0 for any interface.

<h3>6: Port</h3>

Expand Down
83 changes: 28 additions & 55 deletions plugins/channelrx/remotetcpsink/remotetcpsink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ RemoteTCPSink::RemoteTCPSink(DeviceAPI *deviceAPI) :
m_basebandSink->setMessageQueueToChannel(&m_inputMessageQueue);
m_basebandSink->moveToThread(&m_thread);

applySettings(m_settings, true);
applySettings(m_settings, QStringList(), true);

m_deviceAPI->addChannelSink(this);
m_deviceAPI->addChannelSinkAPI(this);
Expand Down Expand Up @@ -147,7 +147,7 @@ bool RemoteTCPSink::handleMessage(const Message& cmd)
{
MsgConfigureRemoteTCPSink& cfg = (MsgConfigureRemoteTCPSink&) cmd;
qDebug() << "RemoteTCPSink::handleMessage: MsgConfigureRemoteTCPSink";
applySettings(cfg.getSettings(), cfg.getForce(), cfg.getRemoteChange());
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce(), cfg.getRemoteChange());

return true;
}
Expand Down Expand Up @@ -183,14 +183,14 @@ bool RemoteTCPSink::deserialize(const QByteArray& data)
(void) data;
if (m_settings.deserialize(data))
{
MsgConfigureRemoteTCPSink *msg = MsgConfigureRemoteTCPSink::create(m_settings, true);
MsgConfigureRemoteTCPSink *msg = MsgConfigureRemoteTCPSink::create(m_settings, QStringList(), true);
m_inputMessageQueue.push(msg);
return true;
}
else
{
m_settings.resetToDefaults();
MsgConfigureRemoteTCPSink *msg = MsgConfigureRemoteTCPSink::create(m_settings, true);
MsgConfigureRemoteTCPSink *msg = MsgConfigureRemoteTCPSink::create(m_settings, QStringList(), true);
m_inputMessageQueue.push(msg);
return false;
}
Expand All @@ -200,18 +200,19 @@ void RemoteTCPSink::setCenterFrequency(qint64 frequency)
{
RemoteTCPSinkSettings settings = m_settings;
settings.m_inputFrequencyOffset = frequency;
applySettings(settings, false);
applySettings(settings, {"inputFrequencyOffset"}, false);

if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureRemoteTCPSink *msgToGUI = MsgConfigureRemoteTCPSink::create(settings, false);
MsgConfigureRemoteTCPSink *msgToGUI = MsgConfigureRemoteTCPSink::create(settings, {"inputFrequencyOffset"}, false);
m_guiMessageQueue->push(msgToGUI);
}
}

void RemoteTCPSink::applySettings(const RemoteTCPSinkSettings& settings, bool force, bool remoteChange)
void RemoteTCPSink::applySettings(const RemoteTCPSinkSettings& settings, const QStringList& settingsKeys, bool force, bool remoteChange)
{
qDebug() << "RemoteTCPSink::applySettings:"
<< " settingsKeys: " << settingsKeys
<< " m_channelSampleRate: " << settings.m_channelSampleRate
<< " m_inputFrequencyOffset: " << settings.m_inputFrequencyOffset
<< " m_gain: " << settings.m_gain
Expand All @@ -223,37 +224,7 @@ void RemoteTCPSink::applySettings(const RemoteTCPSinkSettings& settings, bool fo
<< " force: " << force
<< " remoteChange: " << remoteChange;

QList<QString> reverseAPIKeys;

if ((m_settings.m_channelSampleRate != settings.m_channelSampleRate) || force) {
reverseAPIKeys.append("m_channelSampleRate");
}
if ((m_settings.m_inputFrequencyOffset != settings.m_inputFrequencyOffset) || force) {
reverseAPIKeys.append("inputFrequencyOffset");
}
if ((m_settings.m_gain != settings.m_gain) || force) {
reverseAPIKeys.append("gain");
}
if ((m_settings.m_sampleBits != settings.m_sampleBits) || force) {
reverseAPIKeys.append("sampleBits");
}
if ((m_settings.m_dataAddress != settings.m_dataAddress) || force) {
reverseAPIKeys.append("dataAddress");
}
if ((m_settings.m_dataPort != settings.m_dataPort) || force) {
reverseAPIKeys.append("dataPort");
}
if ((m_settings.m_protocol != settings.m_protocol) || force) {
reverseAPIKeys.append("protocol");
}
if ((m_settings.m_rgbColor != settings.m_rgbColor) || force) {
reverseAPIKeys.append("rgbColor");
}
if ((m_settings.m_title != settings.m_title) || force) {
reverseAPIKeys.append("title");
}

if (m_settings.m_streamIndex != settings.m_streamIndex)
if (settingsKeys.contains("streamIndex"))
{
if (m_deviceAPI->getSampleMIMO()) // change of stream is possible for MIMO devices only
{
Expand All @@ -262,31 +233,33 @@ void RemoteTCPSink::applySettings(const RemoteTCPSinkSettings& settings, bool fo
m_deviceAPI->addChannelSink(this, settings.m_streamIndex);
m_deviceAPI->addChannelSinkAPI(this);
}

reverseAPIKeys.append("streamIndex");
}

MsgConfigureRemoteTCPSink *msg = MsgConfigureRemoteTCPSink::create(settings, force, remoteChange);
MsgConfigureRemoteTCPSink *msg = MsgConfigureRemoteTCPSink::create(settings, settingsKeys, force, remoteChange);
m_basebandSink->getInputMessageQueue()->push(msg);

if ((settings.m_useReverseAPI) && (reverseAPIKeys.size() != 0))
if (settingsKeys.contains("useReverseAPI"))
{
bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
(m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
(m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
(m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex) ||
(m_settings.m_reverseAPIChannelIndex != settings.m_reverseAPIChannelIndex);
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
settingsKeys.contains("reverseAPIAddress") ||
settingsKeys.contains("reverseAPIPort") ||
settingsKeys.contains("reverseAPIDeviceIndex") ||
settingsKeys.contains("reverseAPIChannelIndex");
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
}

QList<ObjectPipe*> pipes;
MainCore::instance()->getMessagePipes().getMessagePipes(this, "settings", pipes);

if (pipes.size() > 0) {
sendChannelSettings(pipes, reverseAPIKeys, settings, force);
sendChannelSettings(pipes, settingsKeys, settings, force);
}

m_settings = settings;
if (force) {
m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
}

int RemoteTCPSink::webapiSettingsGet(
Expand Down Expand Up @@ -319,14 +292,14 @@ int RemoteTCPSink::webapiSettingsPutPatch(
RemoteTCPSinkSettings settings = m_settings;
webapiUpdateChannelSettings(settings, channelSettingsKeys, response);

MsgConfigureRemoteTCPSink *msg = MsgConfigureRemoteTCPSink::create(settings, force);
MsgConfigureRemoteTCPSink *msg = MsgConfigureRemoteTCPSink::create(settings, channelSettingsKeys, force);
m_inputMessageQueue.push(msg);

qDebug("RemoteTCPSink::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);

if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureRemoteTCPSink *msgToGUI = MsgConfigureRemoteTCPSink::create(settings, force);
MsgConfigureRemoteTCPSink *msgToGUI = MsgConfigureRemoteTCPSink::create(settings, channelSettingsKeys, force);
m_guiMessageQueue->push(msgToGUI);
}

Expand Down Expand Up @@ -467,7 +440,7 @@ void RemoteTCPSink::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings&
}
}

void RemoteTCPSink::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const RemoteTCPSinkSettings& settings, bool force)
void RemoteTCPSink::webapiReverseSendSettings(const QStringList& channelSettingsKeys, const RemoteTCPSinkSettings& settings, bool force)
{
SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings();
webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force);
Expand All @@ -494,7 +467,7 @@ void RemoteTCPSink::webapiReverseSendSettings(QList<QString>& channelSettingsKey

void RemoteTCPSink::sendChannelSettings(
const QList<ObjectPipe*>& pipes,
QList<QString>& channelSettingsKeys,
const QStringList& channelSettingsKeys,
const RemoteTCPSinkSettings& settings,
bool force)
{
Expand All @@ -518,7 +491,7 @@ void RemoteTCPSink::sendChannelSettings(
}

void RemoteTCPSink::webapiFormatChannelSettings(
QList<QString>& channelSettingsKeys,
const QStringList& channelSettingsKeys,
SWGSDRangel::SWGChannelSettings *swgChannelSettings,
const RemoteTCPSinkSettings& settings,
bool force
Expand Down
17 changes: 10 additions & 7 deletions plugins/channelrx/remotetcpsink/remotetcpsink.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,25 @@ class RemoteTCPSink : public BasebandSampleSink, public ChannelAPI {

public:
const RemoteTCPSinkSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
bool getRemoteChange() const { return m_remoteChange; }

static MsgConfigureRemoteTCPSink* create(const RemoteTCPSinkSettings& settings, bool force, bool remoteChange = false)
static MsgConfigureRemoteTCPSink* create(const RemoteTCPSinkSettings& settings, const QList<QString>& settingsKeys, bool force, bool remoteChange = false)
{
return new MsgConfigureRemoteTCPSink(settings, force, remoteChange);
return new MsgConfigureRemoteTCPSink(settings, settingsKeys, force, remoteChange);
}

private:
RemoteTCPSinkSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
bool m_remoteChange; // This change of settings was requested by a remote client, so no need to restart server

MsgConfigureRemoteTCPSink(const RemoteTCPSinkSettings& settings, bool force, bool remoteChange) :
MsgConfigureRemoteTCPSink(const RemoteTCPSinkSettings& settings, const QList<QString>& settingsKeys, bool force, bool remoteChange) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force),
m_remoteChange(remoteChange)
{ }
Expand Down Expand Up @@ -180,16 +183,16 @@ class RemoteTCPSink : public BasebandSampleSink, public ChannelAPI {
QNetworkRequest m_networkRequest;

virtual bool handleMessage(const Message& cmd);
void applySettings(const RemoteTCPSinkSettings& settings, bool force = false, bool remoteChange = false);
void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const RemoteTCPSinkSettings& settings, bool force);
void applySettings(const RemoteTCPSinkSettings& settings, const QStringList& settingsKeys, bool force = false, bool remoteChange = false);
void webapiReverseSendSettings(const QStringList& channelSettingsKeys, const RemoteTCPSinkSettings& settings, bool force);
void sendChannelSettings(
const QList<ObjectPipe*>& pipes,
QList<QString>& channelSettingsKeys,
const QStringList& channelSettingsKeys,
const RemoteTCPSinkSettings& settings,
bool force
);
void webapiFormatChannelSettings(
QList<QString>& channelSettingsKeys,
const QStringList& channelSettingsKeys,
SWGSDRangel::SWGChannelSettings *swgChannelSettings,
const RemoteTCPSinkSettings& settings,
bool force
Expand Down
15 changes: 9 additions & 6 deletions plugins/channelrx/remotetcpsink/remotetcpsinkbaseband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ bool RemoteTCPSinkBaseband::handleMessage(const Message& cmd)
RemoteTCPSink::MsgConfigureRemoteTCPSink& cfg = (RemoteTCPSink::MsgConfigureRemoteTCPSink&) cmd;
qDebug() << "RemoteTCPSinkBaseband::handleMessage: MsgConfigureRemoteTCPSink";

applySettings(cfg.getSettings(), cfg.getForce(), cfg.getRemoteChange());
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce(), cfg.getRemoteChange());

return true;
}
Expand All @@ -147,22 +147,25 @@ bool RemoteTCPSinkBaseband::handleMessage(const Message& cmd)
}
}

void RemoteTCPSinkBaseband::applySettings(const RemoteTCPSinkSettings& settings, bool force, bool remoteChange)
void RemoteTCPSinkBaseband::applySettings(const RemoteTCPSinkSettings& settings, const QStringList& settingsKeys, bool force, bool remoteChange)
{
qDebug() << "RemoteTCPSinkBaseband::applySettings:"
<< "m_channelSampleRate:" << settings.m_channelSampleRate
<< "m_inputFrequencyOffset:" << settings.m_inputFrequencyOffset
<< " force: " << force;

if ((settings.m_channelSampleRate != m_settings.m_channelSampleRate)
|| (settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force)
if (settingsKeys.contains("channelSampleRate") || settingsKeys.contains("inputFrequencyOffset") || force)
{
m_channelizer->setChannelization(settings.m_channelSampleRate, settings.m_inputFrequencyOffset);
m_sink.applyChannelSettings(m_channelizer->getChannelSampleRate(), m_channelizer->getChannelFrequencyOffset());
}

m_sink.applySettings(settings, force, remoteChange);
m_settings = settings;
m_sink.applySettings(settings, settingsKeys, force, remoteChange);
if (force) {
m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
}

int RemoteTCPSinkBaseband::getChannelSampleRate() const
Expand Down
2 changes: 1 addition & 1 deletion plugins/channelrx/remotetcpsink/remotetcpsinkbaseband.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class RemoteTCPSinkBaseband : public QObject
QRecursiveMutex m_mutex;

bool handleMessage(const Message& cmd);
void applySettings(const RemoteTCPSinkSettings& settings, bool force = false, bool remoteChange = false);
void applySettings(const RemoteTCPSinkSettings& settings, const QStringList& settingsKeys, bool force = false, bool remoteChange = false);

private slots:
void handleInputMessages();
Expand Down
Loading
Loading