1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 17:58:43 -05:00

TestMO source: Make settings assignments atomic. Part of #1329

This commit is contained in:
f4exb 2022-11-01 19:40:00 +01:00
parent 9576dd0f7b
commit da8f987ee9
6 changed files with 109 additions and 32 deletions

View File

@ -65,7 +65,7 @@ void TestMOSync::destroy()
void TestMOSync::init()
{
applySettings(m_settings, true);
applySettings(m_settings, QList<QString>(), true);
}
bool TestMOSync::startTx()
@ -143,12 +143,12 @@ bool TestMOSync::deserialize(const QByteArray& data)
success = false;
}
MsgConfigureTestMOSync* message = MsgConfigureTestMOSync::create(m_settings, true);
MsgConfigureTestMOSync* message = MsgConfigureTestMOSync::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(message);
if (m_guiMessageQueue)
{
MsgConfigureTestMOSync* messageToGUI = MsgConfigureTestMOSync::create(m_settings, true);
MsgConfigureTestMOSync* messageToGUI = MsgConfigureTestMOSync::create(m_settings, QList<QString>(), true);
m_guiMessageQueue->push(messageToGUI);
}
@ -197,12 +197,12 @@ void TestMOSync::setSinkCenterFrequency(qint64 centerFrequency, int index)
TestMOSyncSettings settings = m_settings;
settings.m_centerFrequency = centerFrequency;
MsgConfigureTestMOSync* message = MsgConfigureTestMOSync::create(settings, false);
MsgConfigureTestMOSync* message = MsgConfigureTestMOSync::create(settings, QList<QString>{"centerFrequency"}, false);
m_inputMessageQueue.push(message);
if (m_guiMessageQueue)
{
MsgConfigureTestMOSync* messageToGUI = MsgConfigureTestMOSync::create(settings, false);
MsgConfigureTestMOSync* messageToGUI = MsgConfigureTestMOSync::create(settings, QList<QString>{"centerFrequency"}, false);
m_guiMessageQueue->push(messageToGUI);
}
}
@ -214,7 +214,7 @@ bool TestMOSync::handleMessage(const Message& message)
MsgConfigureTestMOSync& conf = (MsgConfigureTestMOSync&) message;
qDebug() << "TestMOSync::handleMessage: MsgConfigureTestMOSync";
bool success = applySettings(conf.getSettings(), conf.getForce());
bool success = applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce());
if (!success) {
qDebug("TestMOSync::handleMessage: config error");
@ -259,30 +259,22 @@ void TestMOSync::setFeedSpectrumIndex(unsigned int feedSpectrumIndex)
}
}
bool TestMOSync::applySettings(const TestMOSyncSettings& settings, bool force)
bool TestMOSync::applySettings(const TestMOSyncSettings& settings, const QList<QString>& settingsKeys, bool force)
{
QList<QString> reverseAPIKeys;
qDebug() << "TestMOSync::applySettings: force:" << force << settings.getDebugString(settingsKeys, force);
bool forwardChangeTxDSP = false;
qDebug() << "TestMOSync::applySettings: common: "
<< " m_sampleRate: " << settings.m_sampleRate
<< " m_centerFrequency: " << settings.m_centerFrequency
<< " m_log2Interp: " << settings.m_log2Interp
<< " m_fcPosTx: " << settings.m_fcPosTx
<< " force: " << force;
if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force)
{
if (settingsKeys.contains("centerFrequency") || force) {
forwardChangeTxDSP = true;
}
if ((m_settings.m_sampleRate != settings.m_sampleRate)
|| (m_settings.m_log2Interp != settings.m_log2Interp) || force)
if (settingsKeys.contains("sampleRate")
|| settingsKeys.contains("log2Interp") || force)
{
m_sampleMOFifo.resize(SampleMOFifo::getSizePolicy(m_settings.m_sampleRate));
}
if ((m_settings.m_sampleRate != settings.m_sampleRate) || force)
if (settingsKeys.contains("sampleRate") || force)
{
if (m_sinkWorker) {
m_sinkWorker->setSamplerate(settings.m_sampleRate);
@ -291,7 +283,7 @@ bool TestMOSync::applySettings(const TestMOSyncSettings& settings, bool force)
forwardChangeTxDSP = true;
}
if ((m_settings.m_fcPosTx != settings.m_fcPosTx) || force)
if (settingsKeys.contains("fcPosTx") || force)
{
if (m_sinkWorker) {
m_sinkWorker->setFcPos((int) settings.m_fcPosTx);
@ -300,7 +292,7 @@ bool TestMOSync::applySettings(const TestMOSyncSettings& settings, bool force)
forwardChangeTxDSP = true;
}
if ((m_settings.m_log2Interp != settings.m_log2Interp) || force)
if (settingsKeys.contains("log2Interp") || force)
{
if (m_sinkWorker)
{
@ -319,7 +311,12 @@ bool TestMOSync::applySettings(const TestMOSyncSettings& settings, bool force)
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif1);
}
if (force) {
m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
return true;
}
@ -392,12 +389,12 @@ int TestMOSync::webapiSettingsPutPatch(
TestMOSyncSettings settings = m_settings;
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
MsgConfigureTestMOSync *msg = MsgConfigureTestMOSync::create(settings, force);
MsgConfigureTestMOSync *msg = MsgConfigureTestMOSync::create(settings, deviceSettingsKeys, force);
m_inputMessageQueue.push(msg);
if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureTestMOSync *msgToGUI = MsgConfigureTestMOSync::create(settings, force);
MsgConfigureTestMOSync *msgToGUI = MsgConfigureTestMOSync::create(settings, deviceSettingsKeys, force);
m_guiMessageQueue->push(msgToGUI);
}

View File

@ -42,20 +42,22 @@ public:
public:
const TestMOSyncSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
static MsgConfigureTestMOSync* create(const TestMOSyncSettings& settings, bool force)
{
return new MsgConfigureTestMOSync(settings, force);
static MsgConfigureTestMOSync* create(const TestMOSyncSettings& settings, const QList<QString>& settingsKeys, bool force) {
return new MsgConfigureTestMOSync(settings, settingsKeys, force);
}
private:
TestMOSyncSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
MsgConfigureTestMOSync(const TestMOSyncSettings& settings, bool force) :
MsgConfigureTestMOSync(const TestMOSyncSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
@ -162,7 +164,7 @@ private:
void startWorker();
void stopWorker();
bool applySettings(const TestMOSyncSettings& settings, bool force);
bool applySettings(const TestMOSyncSettings& settings, const QList<QString>& settingsKeys, bool force);
};
#endif // PLUGINS_SAMPLEMIMO_TESTMOSYNC_TESTMOSYNC_H_

View File

@ -103,6 +103,7 @@ void TestMOSyncGui::resetToDefaults()
{
m_settings.resetToDefaults();
displaySettings();
m_forceSettings = true;
sendSettings();
}
@ -154,7 +155,13 @@ bool TestMOSyncGui::handleMessage(const Message& message)
{
qDebug("TestMOSyncGui::handleMessage: message: MsgConfigureTestMOSync");
const TestMOSync::MsgConfigureTestMOSync& cfg = (TestMOSync::MsgConfigureTestMOSync&) message;
if (cfg.getForce()) {
m_settings = cfg.getSettings();
} else {
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
}
blockApplySettings(true);
displaySettings();
blockApplySettings(false);
@ -212,9 +219,10 @@ void TestMOSyncGui::updateHardware()
if (m_doApplySettings)
{
qDebug() << "TestMOSyncGui::updateHardware";
TestMOSync::MsgConfigureTestMOSync* message = TestMOSync::MsgConfigureTestMOSync::create(m_settings, m_forceSettings);
TestMOSync::MsgConfigureTestMOSync* message = TestMOSync::MsgConfigureTestMOSync::create(m_settings, m_settingsKeys, m_forceSettings);
m_sampleMIMO->getInputMessageQueue()->push(message);
m_forceSettings = false;
m_settingsKeys.clear();
m_updateTimer.stop();
}
}
@ -252,6 +260,7 @@ void TestMOSyncGui::on_centerFrequency_changed(quint64 value)
{
m_settings.m_centerFrequency = value * 1000;
ui->glSpectrum->setCenterFrequency(m_settings.m_centerFrequency);
m_settingsKeys.append("centerFrequency");
sendSettings();
}
@ -259,6 +268,7 @@ void TestMOSyncGui::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();
}
@ -270,6 +280,7 @@ void TestMOSyncGui::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();
}
@ -310,6 +321,10 @@ void TestMOSyncGui::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

@ -54,6 +54,7 @@ private:
bool m_doApplySettings;
bool m_forceSettings;
TestMOSyncSettings m_settings;
QList<QString> m_settingsKeys;
QTimer m_updateTimer;
QTimer m_statusTimer;
TestMOSync* m_sampleMIMO;

View File

@ -92,3 +92,63 @@ bool TestMOSyncSettings::deserialize(const QByteArray& data)
return false;
}
}
void TestMOSyncSettings::applySettings(const QStringList& settingsKeys, const TestMOSyncSettings& 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("fcPosTx")) {
m_fcPosTx = settings.m_fcPosTx;
}
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 TestMOSyncSettings::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("fcPosTx") || force) {
ostr << " m_fcPosTx: " << m_fcPosTx;
}
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

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