1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 16:08:39 -05:00

Remote TCP Input: Make settings assignments atomic. Part of #1329

This commit is contained in:
f4exb 2022-10-26 00:40:33 +02:00
parent 68c534f848
commit b58d5b0a82
8 changed files with 304 additions and 143 deletions

View File

@ -85,7 +85,7 @@ void RemoteTCPInput::destroy()
void RemoteTCPInput::init()
{
applySettings(m_settings, true);
applySettings(m_settings, QList<QString>(), true);
}
bool RemoteTCPInput::start()
@ -93,7 +93,7 @@ bool RemoteTCPInput::start()
qDebug() << "RemoteTCPInput::start";
m_remoteInputTCPPHandler->reset();
m_remoteInputTCPPHandler->start();
m_remoteInputTCPPHandler->getInputMessageQueue()->push(RemoteTCPInputTCPHandler::MsgConfigureTcpHandler::create(m_settings, true));
m_remoteInputTCPPHandler->getInputMessageQueue()->push(RemoteTCPInputTCPHandler::MsgConfigureTcpHandler::create(m_settings, QList<QString>(), true));
m_thread.start();
return true;
}
@ -121,12 +121,12 @@ bool RemoteTCPInput::deserialize(const QByteArray& data)
success = false;
}
MsgConfigureRemoteTCPInput* message = MsgConfigureRemoteTCPInput::create(m_settings, true);
MsgConfigureRemoteTCPInput* message = MsgConfigureRemoteTCPInput::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(message);
if (m_guiMessageQueue)
{
MsgConfigureRemoteTCPInput* messageToGUI = MsgConfigureRemoteTCPInput::create(m_settings, true);
MsgConfigureRemoteTCPInput* messageToGUI = MsgConfigureRemoteTCPInput::create(m_settings, QList<QString>(), true);
m_guiMessageQueue->push(messageToGUI);
}
@ -159,12 +159,12 @@ void RemoteTCPInput::setCenterFrequency(qint64 centerFrequency)
RemoteTCPInputSettings settings = m_settings;
settings.m_centerFrequency = centerFrequency;
MsgConfigureRemoteTCPInput* message = MsgConfigureRemoteTCPInput::create(settings, false);
MsgConfigureRemoteTCPInput* message = MsgConfigureRemoteTCPInput::create(settings, QList<QString>{"centerFrequency"}, false);
m_inputMessageQueue.push(message);
if (m_guiMessageQueue)
{
MsgConfigureRemoteTCPInput* messageToGUI = MsgConfigureRemoteTCPInput::create(settings, false);
MsgConfigureRemoteTCPInput* messageToGUI = MsgConfigureRemoteTCPInput::create(settings, QList<QString>{"centerFrequency"}, false);
m_guiMessageQueue->push(messageToGUI);
}
}
@ -178,8 +178,7 @@ bool RemoteTCPInput::handleMessage(const Message& message)
if (cmd.getStartStop())
{
if (m_deviceAPI->initDeviceEngine())
{
if (m_deviceAPI->initDeviceEngine()) {
m_deviceAPI->startDeviceEngine();
}
}
@ -198,7 +197,7 @@ bool RemoteTCPInput::handleMessage(const Message& message)
{
qDebug() << "RemoteTCPInput::handleMessage:" << message.getIdentifier();
MsgConfigureRemoteTCPInput& conf = (MsgConfigureRemoteTCPInput&) message;
applySettings(conf.getSettings(), conf.getForce());
applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce());
return true;
}
else if (RemoteTCPInputTCPHandler::MsgReportConnection::match(message))
@ -218,89 +217,32 @@ bool RemoteTCPInput::handleMessage(const Message& message)
}
}
void RemoteTCPInput::applySettings(const RemoteTCPInputSettings& settings, bool force)
void RemoteTCPInput::applySettings(const RemoteTCPInputSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "RemoteTCPInput::applySettings: force: " << force << settings.getDebugString(settingsKeys, force);
QMutexLocker mutexLocker(&m_mutex);
std::ostringstream os;
QList<QString> reverseAPIKeys;
bool forwardChange = false;
if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force)
{
reverseAPIKeys.append("centerFrequency");
if (settingsKeys.contains("centerFrequency") || force) {
forwardChange = true;
}
if ((m_settings.m_loPpmCorrection != settings.m_loPpmCorrection) || force) {
reverseAPIKeys.append("loPpmCorrection");
}
if ((m_settings.m_dcBlock != settings.m_dcBlock) || force) {
reverseAPIKeys.append("dcBlock");
}
if ((m_settings.m_iqCorrection != settings.m_iqCorrection) || force) {
reverseAPIKeys.append("iqCorrection");
}
if ((m_settings.m_biasTee != settings.m_biasTee) || force) {
reverseAPIKeys.append("biasTee");
}
if ((m_settings.m_directSampling != settings.m_directSampling) || force) {
reverseAPIKeys.append("noModMode"); // Use same name as rtlsdrinput.cpp
}
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force) {
reverseAPIKeys.append("devSampleRate");
}
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force) {
reverseAPIKeys.append("log2Decim");
}
if ((m_settings.m_gain != settings.m_gain) || force) {
reverseAPIKeys.append("gain");
}
if ((m_settings.m_agc != settings.m_agc) || force) {
reverseAPIKeys.append("agc");
}
if ((m_settings.m_rfBW != settings.m_rfBW) || force) {
reverseAPIKeys.append("rfBW");
}
if ((m_settings.m_rfBW != settings.m_rfBW) || force) {
reverseAPIKeys.append("rfBW");
}
if ((m_settings.m_inputFrequencyOffset != settings.m_inputFrequencyOffset) || force)
{
reverseAPIKeys.append("inputFrequencyOffset");
if (settingsKeys.contains("inputFrequencyOffset") || force) {
forwardChange = true;
}
if ((m_settings.m_channelGain != settings.m_channelGain) || force) {
reverseAPIKeys.append("channelGain");
}
if ((m_settings.m_channelSampleRate != settings.m_channelSampleRate) || force)
{
reverseAPIKeys.append("channelSampleRate");
if (settingsKeys.contains("channelSampleRate") || force) {
forwardChange = true;
}
if ((m_settings.m_inputFrequencyOffset != settings.m_inputFrequencyOffset) || force) {
reverseAPIKeys.append("inputFrequencyOffset");
}
if ((m_settings.m_sampleBits != settings.m_sampleBits) || force) {
reverseAPIKeys.append("m_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_preFill != settings.m_preFill) || force) {
reverseAPIKeys.append("preFill");
}
mutexLocker.unlock();
if (settings.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);
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
settingsKeys.contains("reverseAPIAddress") ||
settingsKeys.contains("reverseAPIPort") ||
settingsKeys.contains("reverseAPIDeviceIndex");
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
}
if (forwardChange && (settings.m_channelSampleRate != 0))
@ -309,28 +251,13 @@ void RemoteTCPInput::applySettings(const RemoteTCPInputSettings& settings, bool
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
}
if (force) {
m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
m_remoteInputTCPPHandler->getInputMessageQueue()->push(RemoteTCPInputTCPHandler::MsgConfigureTcpHandler::create(m_settings, force));
qDebug() << "RemoteTCPInput::applySettings: "
<< " force: " << force
<< " m_centerFrequency: " << m_settings.m_centerFrequency
<< " m_loPpmCorrection: " << m_settings.m_loPpmCorrection
<< " m_biasTee: " << m_settings.m_biasTee
<< " m_devSampleRate: " << m_settings.m_devSampleRate
<< " m_log2Decim: " << m_settings.m_log2Decim
<< " m_gain: " << m_settings.m_gain
<< " m_agc: " << m_settings.m_agc
<< " m_rfBW: " << m_settings.m_rfBW
<< " m_inputFrequencyOffset: " << m_settings.m_inputFrequencyOffset
<< " m_channelGain: " << m_settings.m_channelGain
<< " m_channelSampleRate: " << m_settings.m_channelSampleRate
<< " m_sampleBits: " << m_settings.m_sampleBits
<< " m_dataAddress: " << m_settings.m_dataAddress
<< " m_dataPort: " << m_settings.m_dataPort
<< " m_preFill: " << m_settings.m_preFill
;
m_remoteInputTCPPHandler->getInputMessageQueue()->push(RemoteTCPInputTCPHandler::MsgConfigureTcpHandler::create(m_settings, settingsKeys, force));
}
int RemoteTCPInput::webapiRunGet(
@ -382,12 +309,12 @@ int RemoteTCPInput::webapiSettingsPutPatch(
RemoteTCPInputSettings settings = m_settings;
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
MsgConfigureRemoteTCPInput *msg = MsgConfigureRemoteTCPInput::create(settings, force);
MsgConfigureRemoteTCPInput *msg = MsgConfigureRemoteTCPInput::create(settings, deviceSettingsKeys, force);
m_inputMessageQueue.push(msg);
if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureRemoteTCPInput *msgToGUI = MsgConfigureRemoteTCPInput::create(settings, force);
MsgConfigureRemoteTCPInput *msgToGUI = MsgConfigureRemoteTCPInput::create(settings, deviceSettingsKeys, force);
m_guiMessageQueue->push(msgToGUI);
}
@ -522,7 +449,7 @@ void RemoteTCPInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& resp
response.getRemoteTcpInputReport()->setSampleRate(m_settings.m_channelSampleRate);
}
void RemoteTCPInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const RemoteTCPInputSettings& settings, bool force)
void RemoteTCPInput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const RemoteTCPInputSettings& settings, bool force)
{
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
swgDeviceSettings->setDirection(0); // single Rx

View File

@ -48,20 +48,22 @@ public:
public:
const RemoteTCPInputSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
static MsgConfigureRemoteTCPInput* create(const RemoteTCPInputSettings& settings, bool force = false)
{
return new MsgConfigureRemoteTCPInput(settings, force);
static MsgConfigureRemoteTCPInput* create(const RemoteTCPInputSettings& settings, const QList<QString>& settingsKeys, bool force = false) {
return new MsgConfigureRemoteTCPInput(settings, settingsKeys, force);
}
private:
RemoteTCPInputSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
MsgConfigureRemoteTCPInput(const RemoteTCPInputSettings& settings, bool force) :
MsgConfigureRemoteTCPInput(const RemoteTCPInputSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
@ -185,9 +187,9 @@ private:
QNetworkRequest m_networkRequest;
QThread m_thread;
void applySettings(const RemoteTCPInputSettings& settings, bool force = false);
void applySettings(const RemoteTCPInputSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const RemoteTCPInputSettings& settings, bool force);
void webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const RemoteTCPInputSettings& settings, bool force);
void webapiReverseSendStartStop(bool start);
private slots:

View File

@ -149,7 +149,13 @@ bool RemoteTCPInputGui::handleMessage(const Message& message)
if (RemoteTCPInput::MsgConfigureRemoteTCPInput::match(message))
{
const RemoteTCPInput::MsgConfigureRemoteTCPInput& cfg = (RemoteTCPInput::MsgConfigureRemoteTCPInput&) message;
if (cfg.getForce()) {
m_settings = cfg.getSettings();
} else {
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
}
blockApplySettings(true);
displaySettings();
blockApplySettings(false);
@ -522,17 +528,22 @@ void RemoteTCPInputGui::on_startStop_toggled(bool checked)
void RemoteTCPInputGui::on_centerFrequency_changed(quint64 value)
{
m_settings.m_centerFrequency = value * 1000;
m_settingsKeys.append("centerFrequency");
sendSettings();
}
void RemoteTCPInputGui::on_devSampleRate_changed(quint64 value)
{
m_settings.m_devSampleRate = value;
m_settingsKeys.append("devSampleRate");
if (!m_settings.m_channelDecimation)
{
m_settings.m_channelSampleRate = m_settings.m_devSampleRate >> m_settings.m_log2Decim;
m_settingsKeys.append("channelSampleRate");
ui->channelSampleRate->setValue(m_settings.m_channelSampleRate);
}
sendSettings();
}
@ -540,47 +551,57 @@ void RemoteTCPInputGui::on_ppm_valueChanged(int value)
{
m_settings.m_loPpmCorrection = value;
ui->ppmText->setText(tr("%1").arg(value));
m_settingsKeys.append("loPpmCorrection");
sendSettings();
}
void RemoteTCPInputGui::on_dcOffset_toggled(bool checked)
{
m_settings.m_dcBlock = checked;
m_settingsKeys.append("dcBlock");
sendSettings();
}
void RemoteTCPInputGui::on_iqImbalance_toggled(bool checked)
{
m_settings.m_iqCorrection = checked;
m_settingsKeys.append("iqCorrection");
sendSettings();
}
void RemoteTCPInputGui::on_biasTee_toggled(bool checked)
{
m_settings.m_biasTee = checked;
m_settingsKeys.append("biasTee");
sendSettings();
}
void RemoteTCPInputGui::on_directSampling_toggled(bool checked)
{
m_settings.m_directSampling = checked;
m_settingsKeys.append("directSampling");
sendSettings();
}
void RemoteTCPInputGui::on_agc_toggled(bool checked)
{
m_settings.m_agc = checked;
m_settingsKeys.append("agc");
sendSettings();
}
void RemoteTCPInputGui::on_decim_currentIndexChanged(int index)
{
m_settings.m_log2Decim = index;
m_settingsKeys.append("log2Decim");
if (!m_settings.m_channelDecimation)
{
m_settings.m_channelSampleRate = m_settings.m_devSampleRate >> m_settings.m_log2Decim;
m_settingsKeys.append("channelSampleRate");
ui->channelSampleRate->setValue(m_settings.m_channelSampleRate);
}
sendSettings();
}
@ -591,7 +612,9 @@ void RemoteTCPInputGui::on_gain1_valueChanged(int value)
} else {
m_settings.m_gain[0] = value * 10;
}
ui->gain1Text->setText(gainText(0));
m_settingsKeys.append("gain[0]");
sendSettings();
}
@ -602,7 +625,9 @@ void RemoteTCPInputGui::on_gain2_valueChanged(int value)
} else {
m_settings.m_gain[1] = value * 10;
}
ui->gain2Text->setText(gainText(1));
m_settingsKeys.append("gain[1]");
sendSettings();
}
@ -613,19 +638,23 @@ void RemoteTCPInputGui::on_gain3_valueChanged(int value)
} else {
m_settings.m_gain[2] = value * 10;
}
ui->gain3Text->setText(gainText(2));
m_settingsKeys.append("gain[2]");
sendSettings();
}
void RemoteTCPInputGui::on_rfBW_changed(int value)
{
m_settings.m_rfBW = value * 1000;
m_settingsKeys.append("rfBW");
sendSettings();
}
void RemoteTCPInputGui::on_deltaFrequency_changed(int value)
{
m_settings.m_inputFrequencyOffset = value;
m_settingsKeys.append("inputFrequencyOffset");
sendSettings();
}
@ -633,21 +662,26 @@ void RemoteTCPInputGui::on_channelGain_valueChanged(int value)
{
m_settings.m_channelGain = value;
ui->channelGainText->setText(tr("%1dB").arg(m_settings.m_channelGain));
m_settingsKeys.append("channelGain");
sendSettings();
}
void RemoteTCPInputGui::on_channelSampleRate_changed(quint64 value)
{
m_settings.m_channelSampleRate = value;
m_settingsKeys.append("channelSampleRate");
sendSettings();
}
void RemoteTCPInputGui::on_decimation_toggled(bool checked)
{
m_settings.m_channelDecimation = !checked;
m_settingsKeys.append("channelDecimation");
if (!m_settings.m_channelDecimation)
{
m_settings.m_channelSampleRate = m_settings.m_devSampleRate >> m_settings.m_log2Decim;
m_settingsKeys.append("channelSampleRate");
ui->channelSampleRate->setValue(m_settings.m_channelSampleRate);
}
ui->channelSampleRate->setEnabled(!checked);
@ -657,12 +691,14 @@ void RemoteTCPInputGui::on_decimation_toggled(bool checked)
void RemoteTCPInputGui::on_sampleBits_currentIndexChanged(int index)
{
m_settings.m_sampleBits = 8 * (index + 1);
m_settingsKeys.append("sampleBits");
sendSettings();
}
void RemoteTCPInputGui::on_dataAddress_editingFinished()
{
m_settings.m_dataAddress = ui->dataAddress->text();
m_settingsKeys.append("dataAddress");
sendSettings();
}
@ -677,6 +713,7 @@ void RemoteTCPInputGui::on_dataPort_editingFinished()
m_settings.m_dataPort = udpPort;
ui->dataPort->setText(tr("%1").arg(m_settings.m_dataPort));
m_settingsKeys.append("dataPort");
sendSettings();
}
@ -684,6 +721,7 @@ void RemoteTCPInputGui::on_dataPort_editingFinished()
void RemoteTCPInputGui::on_overrideRemoteSettings_toggled(bool checked)
{
m_settings.m_overrideRemoteSettings = checked;
m_settingsKeys.append("overrideRemoteSettings");
sendSettings();
}
@ -691,6 +729,7 @@ void RemoteTCPInputGui::on_preFill_valueChanged(int value)
{
m_settings.m_preFill = value/10.0f;
ui->preFillText->setText(QString("%1s").arg(m_settings.m_preFill, 0, 'f', 2));
m_settingsKeys.append("preFill");
sendSettings();
}
@ -700,9 +739,10 @@ void RemoteTCPInputGui::updateHardware()
{
qDebug() << "RemoteTCPInputGui::updateHardware";
RemoteTCPInput::MsgConfigureRemoteTCPInput* message =
RemoteTCPInput::MsgConfigureRemoteTCPInput::create(m_settings, m_forceSettings);
RemoteTCPInput::MsgConfigureRemoteTCPInput::create(m_settings, m_settingsKeys, m_forceSettings);
m_sampleSource->getInputMessageQueue()->push(message);
m_forceSettings = false;
m_settingsKeys.clear();
m_updateTimer.stop();
}
}

View File

@ -103,6 +103,7 @@ private:
Ui::RemoteTCPInputGui* ui;
RemoteTCPInputSettings m_settings; //!< current settings
QList<QString> m_settingsKeys;
RemoteTCPInput* m_sampleSource;
QTimer m_updateTimer;
QTimer m_statusTimer;

View File

@ -146,3 +146,167 @@ bool RemoteTCPInputSettings::deserialize(const QByteArray& data)
return false;
}
}
void RemoteTCPInputSettings::applySettings(const QStringList& settingsKeys, const RemoteTCPInputSettings& settings)
{
if (settingsKeys.contains("centerFrequency")) {
m_centerFrequency = settings.m_centerFrequency;
}
if (settingsKeys.contains("loPpmCorrection")) {
m_loPpmCorrection = settings.m_loPpmCorrection;
}
if (settingsKeys.contains("dcBlock")) {
m_dcBlock = settings.m_dcBlock;
}
if (settingsKeys.contains("iqCorrection")) {
m_iqCorrection = settings.m_iqCorrection;
}
if (settingsKeys.contains("biasTee")) {
m_biasTee = settings.m_biasTee;
}
if (settingsKeys.contains("directSampling")) {
m_directSampling = settings.m_directSampling;
}
if (settingsKeys.contains("devSampleRate")) {
m_devSampleRate = settings.m_devSampleRate;
}
if (settingsKeys.contains("log2Decim")) {
m_log2Decim = settings.m_log2Decim;
}
if (settingsKeys.contains("agc")) {
m_agc = settings.m_agc;
}
if (settingsKeys.contains("rfBW")) {
m_rfBW = settings.m_rfBW;
}
if (settingsKeys.contains("inputFrequencyOffset")) {
m_inputFrequencyOffset = settings.m_inputFrequencyOffset;
}
if (settingsKeys.contains("channelGain")) {
m_channelGain = settings.m_channelGain;
}
if (settingsKeys.contains("channelSampleRate")) {
m_channelSampleRate = settings.m_channelSampleRate;
}
if (settingsKeys.contains("channelDecimation")) {
m_channelDecimation = settings.m_channelDecimation;
}
if (settingsKeys.contains("sampleBits")) {
m_sampleBits = settings.m_sampleBits;
}
if (settingsKeys.contains("dataAddress")) {
m_dataAddress = settings.m_dataAddress;
}
if (settingsKeys.contains("dataPort")) {
m_dataPort = settings.m_dataPort;
}
if (settingsKeys.contains("overrideRemoteSettings")) {
m_overrideRemoteSettings = settings.m_overrideRemoteSettings;
}
if (settingsKeys.contains("preFill")) {
m_preFill = settings.m_preFill;
}
if (settingsKeys.contains("_useReverseAPI")) {
m_useReverseAPI = settings.m_useReverseAPI;
}
if (settingsKeys.contains("reverseAPIAddress")) {
m_reverseAPIAddress = settings.m_reverseAPIAddress;
}
if (settingsKeys.contains("reverseAPIPort")) {
m_reverseAPIPort = settings.m_reverseAPIPort;
}
if (settingsKeys.contains("reverseAPIDeviceIndex")) {
m_reverseAPIDeviceIndex = settings.m_reverseAPIDeviceIndex;
}
for (int i = 0; i < m_maxGains; i++)
{
if (settingsKeys.contains(QString("gain[%1]").arg(i))) {
m_gain[i] = settings.m_gain[i];
}
}
}
QString RemoteTCPInputSettings::getDebugString(const QStringList& settingsKeys, bool force) const
{
std::ostringstream ostr;
if (settingsKeys.contains("centerFrequency") || force) {
ostr << " m_centerFrequency: " << m_centerFrequency;
}
if (settingsKeys.contains("loPpmCorrection") || force) {
ostr << " m_loPpmCorrection: " << m_loPpmCorrection;
}
if (settingsKeys.contains("dcBlock") || force) {
ostr << " m_dcBlock: " << m_dcBlock;
}
if (settingsKeys.contains("iqCorrection") || force) {
ostr << " m_iqCorrection: " << m_iqCorrection;
}
if (settingsKeys.contains("biasTee") || force) {
ostr << " m_biasTee: " << m_biasTee;
}
if (settingsKeys.contains("directSampling") || force) {
ostr << " m_directSampling: " << m_directSampling;
}
if (settingsKeys.contains("devSampleRate") || force) {
ostr << " m_devSampleRate: " << m_devSampleRate;
}
if (settingsKeys.contains("log2Decim") || force) {
ostr << " m_log2Decim: " << m_log2Decim;
}
if (settingsKeys.contains("agc") || force) {
ostr << " m_agc: " << m_agc;
}
if (settingsKeys.contains("rfBW") || force) {
ostr << " m_rfBW: " << m_rfBW;
}
if (settingsKeys.contains("inputFrequencyOffset") || force) {
ostr << " m_inputFrequencyOffset: " << m_inputFrequencyOffset;
}
if (settingsKeys.contains("channelGain") || force) {
ostr << " m_channelGain: " << m_channelGain;
}
if (settingsKeys.contains("channelSampleRate") || force) {
ostr << " m_channelSampleRate: " << m_channelSampleRate;
}
if (settingsKeys.contains("channelDecimation") || force) {
ostr << " m_channelDecimation: " << m_channelDecimation;
}
if (settingsKeys.contains("sampleBits") || force) {
ostr << " m_sampleBits: " << m_sampleBits;
}
if (settingsKeys.contains("dataAddress") || force) {
ostr << " m_dataAddress: " << m_dataAddress.toStdString();
}
if (settingsKeys.contains("dataPort") || force) {
ostr << " m_dataPort: " << m_dataPort;
}
if (settingsKeys.contains("overrideRemoteSettings") || force) {
ostr << " m_overrideRemoteSettings: " << m_overrideRemoteSettings;
}
if (settingsKeys.contains("preFill") || force) {
ostr << " m_preFill: " << m_preFill;
}
if (settingsKeys.contains("useReverseAPI") || force) {
ostr << " m_useReverseAPI: " << m_useReverseAPI;
}
if (settingsKeys.contains("reverseAPIAddress") || force) {
ostr << " m_reverseAPIAddress: " << m_reverseAPIAddress.toStdString();
}
if (settingsKeys.contains("reverseAPIPort") || force) {
ostr << " m_reverseAPIPort: " << m_reverseAPIPort;
}
if (settingsKeys.contains("reverseAPIDeviceIndex") || force) {
ostr << " m_reverseAPIDeviceIndex: " << m_reverseAPIDeviceIndex;
}
for (int i = 0; i < m_maxGains; i++)
{
if (settingsKeys.contains(QString("gain[%1]").arg(i))) {
ostr << QString(" gain[%1]: ").arg(i).toStdString() << m_gain[i];
}
}
return QString(ostr.str().c_str());
}

View File

@ -55,6 +55,8 @@ struct RemoteTCPInputSettings
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
void applySettings(const QStringList& settingsKeys, const RemoteTCPInputSettings& settings);
QString getDebugString(const QStringList& settingsKeys, bool force=false) const;
};
#endif /* PLUGINS_SAMPLESOURCE_REMOTETCPINPUT_REMOTETCPINPUTSETTINGS_H_ */

View File

@ -374,69 +374,66 @@ void RemoteTCPInputTCPHandler::setSampleBitDepth(int sampleBits)
}
}
void RemoteTCPInputTCPHandler::applySettings(const RemoteTCPInputSettings& settings, bool force)
void RemoteTCPInputTCPHandler::applySettings(const RemoteTCPInputSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "RemoteTCPInputTCPHandler::applySettings: "
<< "force: " << force
<< "m_dataAddress: " << settings.m_dataAddress
<< "m_dataPort: " << settings.m_dataPort
<< "m_devSampleRate: " << settings.m_devSampleRate
<< "m_channelSampleRate: " << settings.m_channelSampleRate;
<< settings.getDebugString(settingsKeys, force);
QMutexLocker mutexLocker(&m_mutex);
if ((settings.m_centerFrequency != m_settings.m_centerFrequency) || force) {
if (settingsKeys.contains("centerFrequency") || force) {
setCenterFrequency(settings.m_centerFrequency);
}
if ((settings.m_loPpmCorrection != m_settings.m_loPpmCorrection) || force) {
if (settingsKeys.contains("loPpmCorrection") || force) {
setFreqCorrection(settings.m_loPpmCorrection);
}
if ((settings.m_dcBlock != m_settings.m_dcBlock) || force) {
if (settingsKeys.contains("dcBlock") || force) {
setDCOffsetRemoval(settings.m_dcBlock);
}
if ((settings.m_iqCorrection != m_settings.m_iqCorrection) || force) {
if (settingsKeys.contains("iqCorrection") || force) {
setIQCorrection(settings.m_iqCorrection);
}
if ((settings.m_biasTee != m_settings.m_biasTee) || force) {
if (settingsKeys.contains("biasTee") || force) {
setBiasTee(settings.m_biasTee);
}
if ((settings.m_directSampling != m_settings.m_directSampling) || force) {
if (settingsKeys.contains("directSampling") || force) {
setDirectSampling(settings.m_directSampling);
}
if ((settings.m_log2Decim != m_settings.m_log2Decim) || force) {
if (settingsKeys.contains("log2Decim") || force) {
setDecimation(settings.m_log2Decim);
}
if ((settings.m_devSampleRate != m_settings.m_devSampleRate) || force) {
if (settingsKeys.contains("devSampleRate") || force) {
setSampleRate(settings.m_devSampleRate);
}
if ((settings.m_agc != m_settings.m_agc) || force) {
if (settingsKeys.contains("agc") || force) {
setAGC(settings.m_agc);
}
if (force) {
setTunerAGC(1); // The SDRangel RTLSDR driver always has tuner gain as manual
}
if ((settings.m_gain[0] != m_settings.m_gain[0]) || force) {
if (settingsKeys.contains("gain[0]") || force) {
setTunerGain(settings.m_gain[0]);
}
for (int i = 1; i < 3; i++)
{
if ((settings.m_gain[i] != m_settings.m_gain[i]) || force) {
if (settingsKeys.contains(QString("gain[%1]").arg(i)) || force) {
//setIFGain(i, 20 + settings.m_gain[i]);
}
}
if ((settings.m_rfBW != m_settings.m_rfBW) || force) {
if (settingsKeys.contains("rfBW") || force) {
setBandwidth(settings.m_rfBW);
}
if ((settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force) {
if (settingsKeys.contains("inputFrequencyOffset") || force) {
setChannelFreqOffset(settings.m_inputFrequencyOffset);
}
if ((settings.m_channelGain != m_settings.m_channelGain) || force) {
if (settingsKeys.contains("channelGain") || force) {
setChannelGain(settings.m_channelGain);
}
if ((settings.m_channelSampleRate != m_settings.m_channelSampleRate) || force)
{
// Resize FIFO to give us 1 second
// Can't do this while running
if (!m_running && settings.m_channelSampleRate > (qint32)m_sampleFifo->size())
if (!m_running && settingsKeys.contains("channelSampleRate") && settings.m_channelSampleRate > (qint32)m_sampleFifo->size())
{
qDebug() << "RemoteTCPInputTCPHandler::applySettings: Resizing sample FIFO from " << m_sampleFifo->size() << "to" << settings.m_channelSampleRate;
m_sampleFifo->setSize(settings.m_channelSampleRate);
@ -447,20 +444,24 @@ void RemoteTCPInputTCPHandler::applySettings(const RemoteTCPInputSettings& setti
setChannelSampleRate(settings.m_channelSampleRate);
clearBuffer();
}
if ((settings.m_sampleBits != m_settings.m_sampleBits) || force)
if (settingsKeys.contains("sampleBits") || force)
{
setSampleBitDepth(settings.m_sampleBits);
clearBuffer();
}
// Don't use force, as disconnect can cause rtl_tcp to quit
if ((settings.m_dataPort != m_settings.m_dataPort) || (settings.m_dataAddress != m_settings.m_dataAddress) || (m_dataSocket == nullptr))
if (settingsKeys.contains("dataAddress") || settingsKeys.contains("dataPort") || (m_dataSocket == nullptr))
{
disconnectFromHost();
connectToHost(settings.m_dataAddress, settings.m_dataPort);
}
if (force) {
m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
}
void RemoteTCPInputTCPHandler::connected()
@ -470,7 +471,7 @@ void RemoteTCPInputTCPHandler::connected()
if (m_settings.m_overrideRemoteSettings)
{
// Force settings to be sent to remote device
applySettings(m_settings, true);
applySettings(m_settings, QList<QString>(), true);
}
if (m_messageQueueToGUI)
{
@ -545,11 +546,12 @@ void RemoteTCPInputTCPHandler::dataReadyRead()
{
RemoteTCPInputSettings& settings = m_settings;
settings.m_sampleBits = 8;
QList<QString> settingsKeys{"sampleBits"};
if (m_messageQueueToInput) {
m_messageQueueToInput->push(RemoteTCPInput::MsgConfigureRemoteTCPInput::create(settings));
m_messageQueueToInput->push(RemoteTCPInput::MsgConfigureRemoteTCPInput::create(settings, settingsKeys));
}
if (m_messageQueueToGUI) {
m_messageQueueToGUI->push(RemoteTCPInput::MsgConfigureRemoteTCPInput::create(settings));
m_messageQueueToGUI->push(RemoteTCPInput::MsgConfigureRemoteTCPInput::create(settings, settingsKeys));
}
}
}
@ -565,32 +567,52 @@ void RemoteTCPInputTCPHandler::dataReadyRead()
{
// Update local settings to match remote
RemoteTCPInputSettings& settings = m_settings;
QList<QString> settingsKeys;
settings.m_centerFrequency = RemoteTCPProtocol::extractUInt64(&metaData[8]);
settingsKeys.append("centerFrequency");
settings.m_loPpmCorrection = RemoteTCPProtocol::extractUInt32(&metaData[16]);
settingsKeys.append("loPpmCorrection");
quint32 flags = RemoteTCPProtocol::extractUInt32(&metaData[20]);
settings.m_biasTee = flags & 1;
settingsKeys.append("biasTee");
settings.m_directSampling = (flags >> 1) & 1;
settingsKeys.append("directSampling");
settings.m_agc = (flags >> 2) & 1;
settingsKeys.append("agc");
settings.m_dcBlock = (flags >> 3) & 1;
settingsKeys.append("dcBlock");
settings.m_iqCorrection = (flags >> 4) & 1;
settingsKeys.append("iqCorrection");
settings.m_devSampleRate = RemoteTCPProtocol::extractUInt32(&metaData[24]);
settingsKeys.append("devSampleRate");
settings.m_log2Decim = RemoteTCPProtocol::extractUInt32(&metaData[28]);
settingsKeys.append("log2Decim");
settings.m_gain[0] = RemoteTCPProtocol::extractInt16(&metaData[32]);
settings.m_gain[1] = RemoteTCPProtocol::extractInt16(&metaData[34]);
settings.m_gain[2] = RemoteTCPProtocol::extractInt16(&metaData[36]);
settingsKeys.append("gain[0]");
settingsKeys.append("gain[1]");
settingsKeys.append("gain[2]");
settings.m_rfBW = RemoteTCPProtocol::extractUInt32(&metaData[40]);
settingsKeys.append("rfBW");
settings.m_inputFrequencyOffset = RemoteTCPProtocol::extractUInt32(&metaData[44]);
settingsKeys.append("inputFrequencyOffset");
settings.m_channelGain = RemoteTCPProtocol::extractUInt32(&metaData[48]);
settingsKeys.append("channelGain");
settings.m_channelSampleRate = RemoteTCPProtocol::extractUInt32(&metaData[52]);
settingsKeys.append("channelSampleRate");
settings.m_sampleBits = RemoteTCPProtocol::extractUInt32(&metaData[56]);
if (settings.m_channelSampleRate != (settings.m_devSampleRate >> settings.m_log2Decim)) {
settingsKeys.append("sampleBits");
if (settings.m_channelSampleRate != (settings.m_devSampleRate >> settings.m_log2Decim))
{
settings.m_channelDecimation = true;
settingsKeys.append("channelDecimation");
}
if (m_messageQueueToInput) {
m_messageQueueToInput->push(RemoteTCPInput::MsgConfigureRemoteTCPInput::create(settings));
m_messageQueueToInput->push(RemoteTCPInput::MsgConfigureRemoteTCPInput::create(settings, settingsKeys));
}
if (m_messageQueueToGUI) {
m_messageQueueToGUI->push(RemoteTCPInput::MsgConfigureRemoteTCPInput::create(settings));
m_messageQueueToGUI->push(RemoteTCPInput::MsgConfigureRemoteTCPInput::create(settings, settingsKeys));
}
}
}
@ -770,7 +792,7 @@ bool RemoteTCPInputTCPHandler::handleMessage(const Message& cmd)
{
qDebug() << "RemoteTCPInputTCPHandler::handleMessage: MsgConfigureTcpHandler";
MsgConfigureTcpHandler& notif = (MsgConfigureTcpHandler&) cmd;
applySettings(notif.getSettings(), notif.getForce());
applySettings(notif.getSettings(), notif.getSettingsKeys(), notif.getForce());
return true;
}
else

View File

@ -42,20 +42,23 @@ public:
public:
const RemoteTCPInputSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
static MsgConfigureTcpHandler* create(const RemoteTCPInputSettings& settings, bool force)
static MsgConfigureTcpHandler* create(const RemoteTCPInputSettings& settings, const QList<QString>& settingsKeys, bool force)
{
return new MsgConfigureTcpHandler(settings, force);
return new MsgConfigureTcpHandler(settings, settingsKeys, force);
}
private:
RemoteTCPInputSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
MsgConfigureTcpHandler(const RemoteTCPInputSettings& settings, bool force) :
MsgConfigureTcpHandler(const RemoteTCPInputSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
@ -165,7 +168,7 @@ private:
void setChannelFreqOffset(int offset);
void setChannelGain(int gain);
void setSampleBitDepth(int sampleBits);
void applySettings(const RemoteTCPInputSettings& settings, bool force = false);
void applySettings(const RemoteTCPInputSettings& settings, const QList<QString>& settingsKeys, bool force = false);
private slots:
void started();