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

Test output: Make settings assignments atomic. Part of #1329

This commit is contained in:
f4exb 2022-10-31 11:47:51 +01:00
parent caf60d2ea6
commit 1060c4839e
6 changed files with 97 additions and 20 deletions

View File

@ -69,6 +69,7 @@ TestSinkGui::TestSinkGui(DeviceUISet *deviceUISet, QWidget* parent) :
ui->glSpectrum->setCenterFrequency(m_settings.m_centerFrequency);
ui->glSpectrum->setSampleRate(m_settings.m_sampleRate*(1<<m_settings.m_log2Interp));
ui->spectrumGUI->setBuddies(m_spectrumVis, ui->glSpectrum);
m_sampleSink->setSpectrumGUI(ui->spectrumGUI);
connect(&(m_deviceUISet->m_deviceAPI->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick()));
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
@ -98,6 +99,7 @@ void TestSinkGui::resetToDefaults()
{
m_settings.resetToDefaults();
displaySettings();
m_forceSettings = true;
sendSettings();
}
@ -125,7 +127,13 @@ bool TestSinkGui::handleMessage(const Message& message)
{
qDebug("TestSinkGui::handleMessage: message: MsgConfigureTestSink");
const TestSinkOutput::MsgConfigureTestSink& cfg = (TestSinkOutput::MsgConfigureTestSink&) message;
m_settings = cfg.getSettings();
if (cfg.getForce()) {
m_settings = cfg.getSettings();
} else {
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
}
blockApplySettings(true);
displaySettings();
blockApplySettings(false);
@ -165,8 +173,7 @@ void TestSinkGui::handleInputMessages()
}
else
{
if (handleMessage(*message))
{
if (handleMessage(*message)) {
delete message;
}
}
@ -196,9 +203,10 @@ void TestSinkGui::sendSettings()
void TestSinkGui::updateHardware()
{
qDebug() << "TestSinkGui::updateHardware";
TestSinkOutput::MsgConfigureTestSink* message = TestSinkOutput::MsgConfigureTestSink::create(m_settings, m_forceSettings);
TestSinkOutput::MsgConfigureTestSink* message = TestSinkOutput::MsgConfigureTestSink::create(m_settings, m_settingsKeys, m_forceSettings);
m_sampleSink->getInputMessageQueue()->push(message);
m_forceSettings = false;
m_settingsKeys.clear();
m_updateTimer.stop();
}
@ -206,7 +214,7 @@ void TestSinkGui::updateStatus()
{
int state = m_deviceUISet->m_deviceAPI->state();
if(m_lastEngineState != state)
if (m_lastEngineState != state)
{
switch(state)
{
@ -235,6 +243,7 @@ void TestSinkGui::on_centerFrequency_changed(quint64 value)
{
m_settings.m_centerFrequency = value * 1000;
ui->glSpectrum->setCenterFrequency(m_settings.m_centerFrequency);
m_settingsKeys.append("centerFrequency");
sendSettings();
}
@ -242,6 +251,7 @@ void TestSinkGui::on_sampleRate_changed(quint64 value)
{
m_settings.m_sampleRate = value;
ui->glSpectrum->setSampleRate(m_settings.m_sampleRate*(1<<m_settings.m_log2Interp));
m_settingsKeys.append("sampleRate");
sendSettings();
}
@ -253,6 +263,7 @@ void TestSinkGui::on_interp_currentIndexChanged(int index)
m_settings.m_log2Interp = index;
ui->glSpectrum->setSampleRate(m_settings.m_sampleRate*(1<<m_settings.m_log2Interp));
m_settingsKeys.append("log2Interp");
sendSettings();
}
@ -286,6 +297,10 @@ void TestSinkGui::openDeviceSettingsDialog(const QPoint& p)
m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress();
m_settings.m_reverseAPIPort = dialog.getReverseAPIPort();
m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex();
m_settingsKeys.append("useReverseAPI");
m_settingsKeys.append("reverseAPIAddress");
m_settingsKeys.append("reverseAPIPort");
m_settingsKeys.append("reverseAPIDeviceIndex");
sendSettings();
}

View File

@ -55,6 +55,7 @@ private:
bool m_doApplySettings;
bool m_forceSettings;
TestSinkSettings m_settings;
QList<QString> m_settingsKeys;
QTimer m_updateTimer;
QTimer m_statusTimer;
TestSinkOutput* m_sampleSink;

View File

@ -62,7 +62,7 @@ void TestSinkOutput::destroy()
void TestSinkOutput::init()
{
applySettings(m_settings, true);
applySettings(m_settings, QList<QString>(), true);
}
bool TestSinkOutput::start()
@ -130,12 +130,12 @@ bool TestSinkOutput::deserialize(const QByteArray& data)
success = false;
}
MsgConfigureTestSink* message = MsgConfigureTestSink::create(m_settings, true);
MsgConfigureTestSink* message = MsgConfigureTestSink::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(message);
if (m_guiMessageQueue)
{
MsgConfigureTestSink* messageToGUI = MsgConfigureTestSink::create(m_settings, true);
MsgConfigureTestSink* messageToGUI = MsgConfigureTestSink::create(m_settings, QList<QString>(), true);
m_guiMessageQueue->push(messageToGUI);
}
@ -162,12 +162,12 @@ void TestSinkOutput::setCenterFrequency(qint64 centerFrequency)
TestSinkSettings settings = m_settings;
settings.m_centerFrequency = centerFrequency;
MsgConfigureTestSink* message = MsgConfigureTestSink::create(settings, false);
MsgConfigureTestSink* message = MsgConfigureTestSink::create(settings, QList<QString>{"centerFrequency"}, false);
m_inputMessageQueue.push(message);
if (m_guiMessageQueue)
{
MsgConfigureTestSink* messageToGUI = MsgConfigureTestSink::create(settings, false);
MsgConfigureTestSink* messageToGUI = MsgConfigureTestSink::create(settings, QList<QString>{"centerFrequency"}, false);
m_guiMessageQueue->push(messageToGUI);
}
}
@ -196,7 +196,7 @@ bool TestSinkOutput::handleMessage(const Message& message)
{
qDebug() << "TestSinkOutput::handleMessage: MsgConfigureTestSink";
MsgConfigureTestSink& conf = (MsgConfigureTestSink&) message;
applySettings(conf.getSettings(), conf.getForce());
applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce());
return true;
}
else
@ -205,18 +205,19 @@ bool TestSinkOutput::handleMessage(const Message& message)
}
}
void TestSinkOutput::applySettings(const TestSinkSettings& settings, bool force)
void TestSinkOutput::applySettings(const TestSinkSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "TestSinkOutput::applySettings: force:" << force << settings.getDebugString(settingsKeys, force);
QMutexLocker mutexLocker(&m_mutex);
bool forwardChange = false;
if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency))
if (force || settingsKeys.contains("centerFrequency"))
{
m_settings.m_centerFrequency = settings.m_centerFrequency;
forwardChange = true;
}
if (force || (m_settings.m_sampleRate != settings.m_sampleRate))
if (force || settingsKeys.contains("sampleRate"))
{
m_settings.m_sampleRate = settings.m_sampleRate;
@ -227,7 +228,7 @@ void TestSinkOutput::applySettings(const TestSinkSettings& settings, bool force)
forwardChange = true;
}
if (force || (m_settings.m_log2Interp != settings.m_log2Interp))
if (force || settingsKeys.contains("log2Interp"))
{
m_settings.m_log2Interp = settings.m_log2Interp;

View File

@ -32,6 +32,7 @@ class QThread;
class TestSinkWorker;
class DeviceAPI;
class BasebandSampleSink;
class Serializable;
class TestSinkOutput : public DeviceSampleSink {
public:
@ -40,20 +41,22 @@ public:
public:
const TestSinkSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
static MsgConfigureTestSink* create(const TestSinkSettings& settings, bool force)
{
return new MsgConfigureTestSink(settings, force);
static MsgConfigureTestSink* create(const TestSinkSettings& settings, const QList<QString>& settingsKeys, bool force) {
return new MsgConfigureTestSink(settings, settingsKeys, force);
}
private:
TestSinkSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
MsgConfigureTestSink(const TestSinkSettings& settings, bool force) :
MsgConfigureTestSink(const TestSinkSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
@ -107,6 +110,7 @@ public:
QString& errorMessage);
SpectrumVis *getSpectrumVis() { return &m_spectrumVis; }
void setSpectrumGUI(Serializable *spectrumGUI) { m_settings.setSpectrumGUI(spectrumGUI); }
private:
DeviceAPI *m_deviceAPI;
@ -120,7 +124,7 @@ private:
QString m_deviceDescription;
const QTimer& m_masterTimer;
void applySettings(const TestSinkSettings& settings, bool force = false);
void applySettings(const TestSinkSettings& settings, const QList<QString>& settingsKeys, bool force = false);
};
#endif // INCLUDE_TESTSINKOUTPUT_H

View File

@ -101,3 +101,57 @@ bool TestSinkSettings::deserialize(const QByteArray& data)
return false;
}
}
void TestSinkSettings::applySettings(const QStringList& settingsKeys, const TestSinkSettings& settings)
{
if (settingsKeys.contains("centerFrequency")) {
m_centerFrequency = settings.m_centerFrequency;
}
if (settingsKeys.contains("sampleRate")) {
m_sampleRate = settings.m_sampleRate;
}
if (settingsKeys.contains("log2Interp")) {
m_log2Interp = settings.m_log2Interp;
}
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;
}
}
QString TestSinkSettings::getDebugString(const QStringList& settingsKeys, bool force) const
{
std::ostringstream ostr;
if (settingsKeys.contains("centerFrequency") || force) {
ostr << " m_centerFrequency: " << m_centerFrequency;
}
if (settingsKeys.contains("sampleRate") || force) {
ostr << " m_sampleRate: " << m_sampleRate;
}
if (settingsKeys.contains("log2Interp") || force) {
ostr << " m_log2Interp: " << m_log2Interp;
}
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;
}
return QString(ostr.str().c_str());
}

View File

@ -37,6 +37,8 @@ struct TestSinkSettings {
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
void setSpectrumGUI(Serializable *spectrumGUI) { m_spectrumGUI = spectrumGUI; }
void applySettings(const QStringList& settingsKeys, const TestSinkSettings& settings);
QString getDebugString(const QStringList& settingsKeys, bool force=false) const;
};
#endif /* PLUGINS_SAMPLESINK_TESTSINK_TESTSINKSETTINGS_H_ */