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

Demod Analyzer feature: Make settings assignments atomic. Part of #1329

This commit is contained in:
f4exb 2022-11-23 23:08:41 +01:00
parent 5f3052ef70
commit c4b33d87be
8 changed files with 159 additions and 65 deletions

View File

@ -119,7 +119,7 @@ void DemodAnalyzer::start()
m_thread->start();
DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker *msg
= DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker::create(m_settings, true);
= DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker::create(m_settings, QList<QString>(), true);
m_worker->getInputMessageQueue()->push(msg);
if (m_dataPipe)
@ -175,7 +175,7 @@ bool DemodAnalyzer::handleMessage(const Message& cmd)
{
MsgConfigureDemodAnalyzer& cfg = (MsgConfigureDemodAnalyzer&) cmd;
qDebug() << "DemodAnalyzer::handleMessage: MsgConfigureDemodAnalyzer";
applySettings(cfg.getSettings(), cfg.getForce());
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce());
return true;
}
@ -260,64 +260,47 @@ bool DemodAnalyzer::deserialize(const QByteArray& data)
{
if (m_settings.deserialize(data))
{
MsgConfigureDemodAnalyzer *msg = MsgConfigureDemodAnalyzer::create(m_settings, true);
MsgConfigureDemodAnalyzer *msg = MsgConfigureDemodAnalyzer::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(msg);
return true;
}
else
{
m_settings.resetToDefaults();
MsgConfigureDemodAnalyzer *msg = MsgConfigureDemodAnalyzer::create(m_settings, true);
MsgConfigureDemodAnalyzer *msg = MsgConfigureDemodAnalyzer::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(msg);
return false;
}
}
void DemodAnalyzer::applySettings(const DemodAnalyzerSettings& settings, bool force)
void DemodAnalyzer::applySettings(const DemodAnalyzerSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "DemodAnalyzer::applySettings:"
<< " m_log2Decim: " << settings.m_log2Decim
<< " m_title: " << settings.m_title
<< " m_rgbColor: " << settings.m_rgbColor
<< " m_useReverseAPI: " << settings.m_useReverseAPI
<< " m_reverseAPIAddress: " << settings.m_reverseAPIAddress
<< " m_reverseAPIPort: " << settings.m_reverseAPIPort
<< " m_reverseAPIFeatureSetIndex: " << settings.m_reverseAPIFeatureSetIndex
<< " m_reverseAPIFeatureIndex: " << settings.m_reverseAPIFeatureIndex
<< " force: " << force;
QList<QString> reverseAPIKeys;
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force) {
reverseAPIKeys.append("log2Decim");
}
if ((m_settings.m_title != settings.m_title) || force) {
reverseAPIKeys.append("title");
}
if ((m_settings.m_rgbColor != settings.m_rgbColor) || force) {
reverseAPIKeys.append("rgbColor");
}
qDebug() << "DemodAnalyzer::applySettings:" << settings.getDebugString(settingsKeys, force) << " force: " << force;
if (m_running)
{
DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker *msg = DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker::create(
settings, force
settings, settingsKeys, force
);
m_worker->getInputMessageQueue()->push(msg);
}
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_reverseAPIFeatureSetIndex != settings.m_reverseAPIFeatureSetIndex) ||
(m_settings.m_reverseAPIFeatureIndex != settings.m_reverseAPIFeatureIndex);
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
settingsKeys.contains("reverseAPIAddress") ||
settingsKeys.contains("reverseAPIPort") ||
settingsKeys.contains("reverseAPIFeatureSetIndex") ||
settingsKeys.contains("m_reverseAPIFeatureIndex");
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
}
m_settings = settings;
if (force) {
m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
}
void DemodAnalyzer::updateChannels()
@ -470,13 +453,13 @@ int DemodAnalyzer::webapiSettingsPutPatch(
DemodAnalyzerSettings settings = m_settings;
webapiUpdateFeatureSettings(settings, featureSettingsKeys, response);
MsgConfigureDemodAnalyzer *msg = MsgConfigureDemodAnalyzer::create(settings, force);
MsgConfigureDemodAnalyzer *msg = MsgConfigureDemodAnalyzer::create(settings, featureSettingsKeys, force);
m_inputMessageQueue.push(msg);
qDebug("DemodAnalyzer::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureDemodAnalyzer *msgToGUI = MsgConfigureDemodAnalyzer::create(settings, force);
MsgConfigureDemodAnalyzer *msgToGUI = MsgConfigureDemodAnalyzer::create(settings, featureSettingsKeys, force);
m_guiMessageQueue->push(msgToGUI);
}
@ -610,7 +593,7 @@ void DemodAnalyzer::webapiUpdateFeatureSettings(
}
}
void DemodAnalyzer::webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const DemodAnalyzerSettings& settings, bool force)
void DemodAnalyzer::webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const DemodAnalyzerSettings& settings, bool force)
{
SWGSDRangel::SWGFeatureSettings *swgFeatureSettings = new SWGSDRangel::SWGFeatureSettings();
// swgFeatureSettings->setOriginatorFeatureIndex(getIndexInDeviceSet());

View File

@ -49,19 +49,22 @@ public:
public:
const DemodAnalyzerSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
static MsgConfigureDemodAnalyzer* create(const DemodAnalyzerSettings& settings, bool force) {
return new MsgConfigureDemodAnalyzer(settings, force);
static MsgConfigureDemodAnalyzer* create(const DemodAnalyzerSettings& settings, const QList<QString>& settingsKeys, bool force) {
return new MsgConfigureDemodAnalyzer(settings, settingsKeys, force);
}
private:
DemodAnalyzerSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
MsgConfigureDemodAnalyzer(const DemodAnalyzerSettings& settings, bool force) :
MsgConfigureDemodAnalyzer(const DemodAnalyzerSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
@ -213,10 +216,10 @@ private:
void start();
void stop();
void applySettings(const DemodAnalyzerSettings& settings, bool force = false);
void applySettings(const DemodAnalyzerSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void updateChannels();
void setChannel(ChannelAPI *selectedChannel);
void webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const DemodAnalyzerSettings& settings, bool force);
void webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const DemodAnalyzerSettings& settings, bool force);
private slots:
void networkManagerFinished(QNetworkReply *reply);

View File

@ -76,7 +76,13 @@ bool DemodAnalyzerGUI::handleMessage(const Message& message)
{
qDebug("DemodAnalyzerGUI::handleMessage: DemodAnalyzer::MsgConfigureDemodAnalyzer");
const DemodAnalyzer::MsgConfigureDemodAnalyzer& cfg = (DemodAnalyzer::MsgConfigureDemodAnalyzer&) message;
m_settings = cfg.getSettings();
if (cfg.getForce()) {
m_settings = cfg.getSettings();
} else {
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
}
blockApplySettings(true);
ui->spectrumGUI->updateSettings();
ui->scopeGUI->updateSettings();
@ -282,6 +288,14 @@ void DemodAnalyzerGUI::onMenuDialogCalled(const QPoint &p)
setTitle(m_settings.m_title);
setTitleColor(m_settings.m_rgbColor);
m_settingsKeys.append("title");
m_settingsKeys.append("rgbColor");
m_settingsKeys.append("useReverseAPI");
m_settingsKeys.append("reverseAPIAddress");
m_settingsKeys.append("reverseAPIPort");
m_settingsKeys.append("reverseAPIFeatureSetIndex");
m_settingsKeys.append("reverseAPIFeatureIndex");
applySettings();
}
@ -330,6 +344,7 @@ void DemodAnalyzerGUI::on_log2Decim_currentIndexChanged(int index)
ui->glSpectrum->setSampleRate(m_sampleRate/(1<<m_settings.m_log2Decim));
m_scopeVis->setLiveRate(m_sampleRate/(1<<m_settings.m_log2Decim));
displaySampleRate(m_sampleRate/(1<<m_settings.m_log2Decim));
m_settingsKeys.append("log2Decim");
applySettings();
}
@ -337,6 +352,7 @@ void DemodAnalyzerGUI::on_record_toggled(bool checked)
{
ui->showFileDialog->setEnabled(!checked);
m_settings.m_recordToFile = checked;
m_settingsKeys.append("recordToFile");
applySettings();
}
@ -362,6 +378,7 @@ void DemodAnalyzerGUI::on_showFileDialog_clicked(bool checked)
{
m_settings.m_fileRecordName = fileNames.at(0);
ui->fileNameText->setText(m_settings.m_fileRecordName);
m_settingsKeys.append("fileRecordName");
applySettings();
}
}
@ -371,6 +388,7 @@ void DemodAnalyzerGUI::on_recordSilenceTime_valueChanged(int value)
{
m_settings.m_recordSilenceTime = value;
ui->recordSilenceText->setText(tr("%1").arg(value / 10.0, 0, 'f', 1));
m_settingsKeys.append("recordSilenceTime");
applySettings();
}
@ -414,9 +432,11 @@ void DemodAnalyzerGUI::applySettings(bool force)
{
if (m_doApplySettings)
{
DemodAnalyzer::MsgConfigureDemodAnalyzer* message = DemodAnalyzer::MsgConfigureDemodAnalyzer::create( m_settings, force);
DemodAnalyzer::MsgConfigureDemodAnalyzer* message = DemodAnalyzer::MsgConfigureDemodAnalyzer::create( m_settings, m_settingsKeys, force);
m_demodAnalyzer->getInputMessageQueue()->push(message);
}
m_settingsKeys.clear();
}
void DemodAnalyzerGUI::makeUIConnections()

View File

@ -59,6 +59,7 @@ private:
PluginAPI* m_pluginAPI;
FeatureUISet* m_featureUISet;
DemodAnalyzerSettings m_settings;
QList<QString> m_settingsKeys;
RollupState m_rollupState;
int m_sampleRate;
bool m_doApplySettings;

View File

@ -188,3 +188,87 @@ bool DemodAnalyzerSettings::deserialize(const QByteArray& data)
return false;
}
}
void DemodAnalyzerSettings::applySettings(const QStringList& settingsKeys, const DemodAnalyzerSettings& settings)
{
if (settingsKeys.contains("log2Decim")) {
m_log2Decim = settings.m_log2Decim;
}
if (settingsKeys.contains("title")) {
m_title = settings.m_title;
}
if (settingsKeys.contains("rgbColor")) {
m_rgbColor = settings.m_rgbColor;
}
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("reverseAPIFeatureSetIndex")) {
m_reverseAPIFeatureSetIndex = settings.m_reverseAPIFeatureSetIndex;
}
if (settingsKeys.contains("reverseAPIFeatureIndex")) {
m_reverseAPIFeatureIndex = settings.m_reverseAPIFeatureIndex;
}
if (settingsKeys.contains("workspaceIndex")) {
m_workspaceIndex = settings.m_workspaceIndex;
}
if (settingsKeys.contains("fileRecordName")) {
m_fileRecordName = settings.m_fileRecordName;
}
if (settingsKeys.contains("recordToFile")) {
m_recordToFile = settings.m_recordToFile;
}
if (settingsKeys.contains("recordSilenceTime")) {
m_recordSilenceTime = settings.m_recordSilenceTime;
}
}
QString DemodAnalyzerSettings::getDebugString(const QStringList& settingsKeys, bool force) const
{
std::ostringstream ostr;
if (settingsKeys.contains("log2Decim") || force) {
ostr << " m_log2Decim: " << m_log2Decim;
}
if (settingsKeys.contains("title") || force) {
ostr << " m_title: " << m_title.toStdString();
}
if (settingsKeys.contains("rgbColor") || force) {
ostr << " m_rgbColor: " << m_rgbColor;
}
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("reverseAPIFeatureSetIndex") || force) {
ostr << " m_reverseAPIFeatureSetIndex: " << m_reverseAPIFeatureSetIndex;
}
if (settingsKeys.contains("reverseAPIFeatureIndex") || force) {
ostr << " m_reverseAPIFeatureIndex: " << m_reverseAPIFeatureIndex;
}
if (settingsKeys.contains("workspaceIndex") || force) {
ostr << " m_workspaceIndex: " << m_workspaceIndex;
}
if (settingsKeys.contains("fileRecordName") || force) {
ostr << " m_fileRecordName: " << m_fileRecordName.toStdString();
}
if (settingsKeys.contains("recordToFile") || force) {
ostr << " m_recordToFile: " << m_recordToFile;
}
if (settingsKeys.contains("recordSilenceTime") || force) {
ostr << " m_recordSilenceTime: " << m_recordSilenceTime;
}
return QString(ostr.str().c_str());
}

View File

@ -65,6 +65,8 @@ struct DemodAnalyzerSettings
void setSpectrumGUI(Serializable *spectrumGUI) { m_spectrumGUI = spectrumGUI; }
void setScopeGUI(Serializable *scopeGUI) { m_scopeGUI = scopeGUI; }
void setRollupState(Serializable *rollupState) { m_rollupState = rollupState; }
void applySettings(const QStringList& settingsKeys, const DemodAnalyzerSettings& settings);
QString getDebugString(const QStringList& settingsKeys, bool force=false) const;
static const QStringList m_channelTypes;
static const QStringList m_channelURIs;

View File

@ -216,7 +216,7 @@ bool DemodAnalyzerWorker::handleMessage(const Message& cmd)
MsgConfigureDemodAnalyzerWorker& cfg = (MsgConfigureDemodAnalyzerWorker&) cmd;
qDebug("DemodAnalyzerWorker::handleMessage: MsgConfigureDemodAnalyzerWorker");
applySettings(cfg.getSettings(), cfg.getForce());
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce());
return true;
}
@ -255,18 +255,11 @@ bool DemodAnalyzerWorker::handleMessage(const Message& cmd)
}
}
void DemodAnalyzerWorker::applySettings(const DemodAnalyzerSettings& settings, bool force)
void DemodAnalyzerWorker::applySettings(const DemodAnalyzerSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "DemodAnalyzerWorker::applySettings:"
<< " m_title: " << settings.m_title
<< " m_rgbColor: " << settings.m_rgbColor
<< " m_log2Decim: " << settings.m_log2Decim
<< " m_fileRecordName: " << settings.m_fileRecordName
<< " m_recordToFile: " << settings.m_recordToFile
<< " m_recordSilenceTime: " << settings.m_recordSilenceTime
<< " force: " << force;
qDebug() << "DemodAnalyzerWorker::applySettings:" << settings.getDebugString(settingsKeys, force) << force;
if ((m_settings.m_fileRecordName != settings.m_fileRecordName) || force)
if (settingsKeys.contains("fileRecordName") || force)
{
if (m_wavFileRecord)
{
@ -293,7 +286,7 @@ void DemodAnalyzerWorker::applySettings(const DemodAnalyzerSettings& settings, b
}
}
if ((m_settings.m_recordToFile != settings.m_recordToFile) || force)
if (settingsKeys.contains("recordToFile") || force)
{
if (m_wavFileRecord)
{
@ -314,8 +307,8 @@ void DemodAnalyzerWorker::applySettings(const DemodAnalyzerSettings& settings, b
}
}
if ((m_settings.m_recordSilenceTime != settings.m_recordSilenceTime)
|| (m_settings.m_log2Decim != settings.m_log2Decim) || force)
if (settingsKeys.contains("recordSilenceTime")
|| settingsKeys.contains("log2Decim") || force)
{
m_recordSilenceNbSamples = (settings.m_recordSilenceTime * (m_sinkSampleRate / (1<<settings.m_log2Decim))) / 10; // time in 100'ś ms
m_recordSilenceCount = 0;
@ -330,7 +323,12 @@ void DemodAnalyzerWorker::applySettings(const DemodAnalyzerSettings& settings, b
}
}
m_settings = settings;
if (force) {
m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
}
void DemodAnalyzerWorker::applySampleRate(int sampleRate)

View File

@ -47,20 +47,23 @@ public:
public:
const DemodAnalyzerSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
static MsgConfigureDemodAnalyzerWorker* create(const DemodAnalyzerSettings& settings, bool force)
static MsgConfigureDemodAnalyzerWorker* create(const DemodAnalyzerSettings& settings, const QList<QString>& settingsKeys, bool force)
{
return new MsgConfigureDemodAnalyzerWorker(settings, force);
return new MsgConfigureDemodAnalyzerWorker(settings, settingsKeys, force);
}
private:
DemodAnalyzerSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
MsgConfigureDemodAnalyzerWorker(const DemodAnalyzerSettings& settings, bool force) :
MsgConfigureDemodAnalyzerWorker(const DemodAnalyzerSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
@ -94,7 +97,7 @@ public:
void setMessageQueueToFeature(MessageQueue *messageQueue) { m_msgQueueToFeature = messageQueue; }
void applySampleRate(int sampleRate);
void applySettings(const DemodAnalyzerSettings& settings, bool force = false);
void applySettings(const DemodAnalyzerSettings& settings, const QList<QString>& settingsKeys, bool force = false);
double getMagSq() const { return m_magsq; }
double getMagSqAvg() const { return (double) m_channelPowerAvg; }