Skip to content

Commit

Permalink
Perseus: Make settings assignments atomic. Part of #1329
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Oct 23, 2022
1 parent 4d8667e commit 112d059
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 81 deletions.
29 changes: 26 additions & 3 deletions plugins/samplesource/perseus/perseusgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void PerseusGui::resetToDefaults()
{
m_settings.resetToDefaults();
displaySettings();
m_forceSettings = true;
sendSettings();
}

Expand Down Expand Up @@ -118,7 +119,13 @@ bool PerseusGui::handleMessage(const Message& message)
if (PerseusInput::MsgConfigurePerseus::match(message))
{
const PerseusInput::MsgConfigurePerseus& cfg = (PerseusInput::MsgConfigurePerseus&) 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);
Expand Down Expand Up @@ -253,13 +260,15 @@ void PerseusGui::sendSettings()
void PerseusGui::on_centerFrequency_changed(quint64 value)
{
m_settings.m_centerFrequency = value * 1000;
m_settingsKeys.append("centerFrequency");
sendSettings();
}

void PerseusGui::on_LOppm_valueChanged(int value)
{
m_settings.m_LOppmTenths = value;
ui->LOppmText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
m_settingsKeys.append("LOppmTenths");
sendSettings();
}

Expand All @@ -271,20 +280,25 @@ void PerseusGui::on_resetLOppm_clicked()
void PerseusGui::on_sampleRate_currentIndexChanged(int index)
{
m_settings.m_devSampleRateIndex = index;
m_settingsKeys.append("devSampleRateIndex");
sendSettings();
}

void PerseusGui::on_wideband_toggled(bool checked)
{
m_settings.m_wideBand = checked;
m_settingsKeys.append("wideBand");
sendSettings();
}

void PerseusGui::on_decim_currentIndexChanged(int index)
{
if ((index < 0) || (index > 5))
if ((index < 0) || (index > 5)) {
return;
}

m_settings.m_log2Decim = index;
m_settingsKeys.append("log2Decim");
sendSettings();
}

Expand All @@ -305,6 +319,10 @@ void PerseusGui::on_transverter_clicked()
qDebug("PerseusGui::on_transverter_clicked: %lld Hz %s", m_settings.m_transverterDeltaFrequency, m_settings.m_transverterMode ? "on" : "off");
updateFrequencyLimits();
m_settings.m_centerFrequency = ui->centerFrequency->getValueNew()*1000;
m_settingsKeys.append("transverterMode");
m_settingsKeys.append("transverterDeltaFrequency");
m_settingsKeys.append("iqOrder");
m_settingsKeys.append("centerFrequency");
sendSettings();
}

Expand All @@ -313,28 +331,33 @@ void PerseusGui::on_attenuator_currentIndexChanged(int index)
if ((index < 0) || (index >= (int) PerseusSettings::Attenuator_last)) {
return;
}

m_settings.m_attenuator = (PerseusSettings::Attenuator) index;
m_settingsKeys.append("attenuator");
sendSettings();
}

void PerseusGui::on_adcDither_toggled(bool checked)
{
m_settings.m_adcDither = checked;
m_settingsKeys.append("adcDither");
sendSettings();
}

void PerseusGui::on_adcPreamp_toggled(bool checked)
{
m_settings.m_adcPreamp = checked;
m_settingsKeys.append("adcPreamp");
sendSettings();
}

void PerseusGui::updateHardware()
{
qDebug() << "PerseusGui::updateHardware";
PerseusInput::MsgConfigurePerseus* message = PerseusInput::MsgConfigurePerseus::create(m_settings, m_forceSettings);
PerseusInput::MsgConfigurePerseus* message = PerseusInput::MsgConfigurePerseus::create(m_settings, m_settingsKeys, m_forceSettings);
m_sampleSource->getInputMessageQueue()->push(message);
m_forceSettings = false;
m_settingsKeys.clear();
m_updateTimer.stop();
}

Expand Down
1 change: 1 addition & 0 deletions plugins/samplesource/perseus/perseusgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PerseusGui : public DeviceGUI {
bool m_doApplySettings;
bool m_forceSettings;
PerseusSettings m_settings;
QList<QString> m_settingsKeys;
QTimer m_updateTimer;
QTimer m_statusTimer;
std::vector<uint32_t> m_rates;
Expand Down
110 changes: 37 additions & 73 deletions plugins/samplesource/perseus/perseusinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void PerseusInput::destroy()

void PerseusInput::init()
{
applySettings(m_settings, true);
applySettings(m_settings, QList<QString>(), true);
}

bool PerseusInput::start()
Expand All @@ -100,7 +100,7 @@ bool PerseusInput::start()
m_perseusWorker->setLog2Decimation(m_settings.m_log2Decim);
m_perseusWorkerThread->start();

applySettings(m_settings, true);
applySettings(m_settings, QList<QString>(), true);
m_running = true;

return true;
Expand Down Expand Up @@ -141,12 +141,12 @@ bool PerseusInput::deserialize(const QByteArray& data)
success = false;
}

MsgConfigurePerseus* message = MsgConfigurePerseus::create(m_settings, true);
MsgConfigurePerseus* message = MsgConfigurePerseus::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(message);

if (m_guiMessageQueue)
{
MsgConfigurePerseus* messageToGUI = MsgConfigurePerseus::create(m_settings, true);
MsgConfigurePerseus* messageToGUI = MsgConfigurePerseus::create(m_settings, QList<QString>(), true);
m_guiMessageQueue->push(messageToGUI);
}

Expand Down Expand Up @@ -176,12 +176,12 @@ void PerseusInput::setCenterFrequency(qint64 centerFrequency)
PerseusSettings settings = m_settings;
settings.m_centerFrequency = centerFrequency;

MsgConfigurePerseus* message = MsgConfigurePerseus::create(settings, false);
MsgConfigurePerseus* message = MsgConfigurePerseus::create(settings, QList<QString>{"centerFrequency"}, false);
m_inputMessageQueue.push(message);

if (m_guiMessageQueue)
{
MsgConfigurePerseus* messageToGUI = MsgConfigurePerseus::create(settings, false);
MsgConfigurePerseus* messageToGUI = MsgConfigurePerseus::create(settings, QList<QString>{"centerFrequency"}, false);
m_guiMessageQueue->push(messageToGUI);
}
}
Expand All @@ -193,7 +193,7 @@ bool PerseusInput::handleMessage(const Message& message)
MsgConfigurePerseus& conf = (MsgConfigurePerseus&) message;
qDebug() << "PerseusInput::handleMessage: MsgConfigurePerseus";

bool success = applySettings(conf.getSettings(), conf.getForce());
bool success = applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce());

if (!success) {
qDebug("MsgConfigurePerseus::handleMessage: Perseus config error");
Expand All @@ -208,8 +208,7 @@ bool PerseusInput::handleMessage(const Message& message)

if (cmd.getStartStop())
{
if (m_deviceAPI->initDeviceEngine())
{
if (m_deviceAPI->initDeviceEngine()) {
m_deviceAPI->startDeviceEngine();
}
}
Expand Down Expand Up @@ -296,15 +295,14 @@ void PerseusInput::setDeviceCenterFrequency(quint64 freq_hz, const PerseusSettin
}
}

bool PerseusInput::applySettings(const PerseusSettings& settings, bool force)
bool PerseusInput::applySettings(const PerseusSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "PerseusInput::applySettings: force: " << force << settings.getDebugString(settingsKeys, force);
bool forwardChange = false;
int sampleRateIndex = settings.m_devSampleRateIndex;
QList<QString> reverseAPIKeys;

if ((m_settings.m_devSampleRateIndex != settings.m_devSampleRateIndex) || force)
if (settingsKeys.contains("devSampleRateIndex") || force)
{
reverseAPIKeys.append("devSampleRateIndex");
forwardChange = true;

if (settings.m_devSampleRateIndex >= m_sampleRates.size()) {
Expand Down Expand Up @@ -334,9 +332,8 @@ bool PerseusInput::applySettings(const PerseusSettings& settings, bool force)
}
}

if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
if (settingsKeys.contains("log2Decim") || force)
{
reverseAPIKeys.append("log2Decim");
forwardChange = true;

if (m_running)
Expand All @@ -346,37 +343,19 @@ bool PerseusInput::applySettings(const PerseusSettings& settings, bool force)
}
}

if ((m_settings.m_iqOrder != settings.m_iqOrder) || force)
if (settingsKeys.contains("iqOrder") || force)
{
reverseAPIKeys.append("iqOrder");

if (m_running) {
m_perseusWorker->setIQOrder(settings.m_iqOrder);
}
}

if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency)) {
reverseAPIKeys.append("centerFrequency");
}
if (force || (m_settings.m_LOppmTenths != settings.m_LOppmTenths)) {
reverseAPIKeys.append("LOppmTenths");
}
if (force || (m_settings.m_wideBand != settings.m_wideBand)) {
reverseAPIKeys.append("wideBand");
}
if (force || (m_settings.m_transverterMode != settings.m_transverterMode)) {
reverseAPIKeys.append("transverterMode");
}
if (force || (m_settings.m_transverterDeltaFrequency != settings.m_transverterDeltaFrequency)) {
reverseAPIKeys.append("transverterDeltaFrequency");
}

if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency)
|| (m_settings.m_LOppmTenths != settings.m_LOppmTenths)
|| (m_settings.m_wideBand != settings.m_wideBand)
|| (m_settings.m_transverterMode != settings.m_transverterMode)
|| (m_settings.m_transverterDeltaFrequency != settings.m_transverterDeltaFrequency)
|| (m_settings.m_devSampleRateIndex != settings.m_devSampleRateIndex))
if (force || settingsKeys.contains("centerFrequency")
|| settingsKeys.contains("LOppmTenths")
|| settingsKeys.contains("wideBand")
|| settingsKeys.contains("transverterMode")
|| settingsKeys.contains("transverterDeltaFrequency")
|| settingsKeys.contains("devSampleRateIndex"))
{
qint64 deviceCenterFrequency = settings.m_centerFrequency;
deviceCenterFrequency -= settings.m_transverterMode ? settings.m_transverterDeltaFrequency : 0;
Expand All @@ -391,9 +370,8 @@ bool PerseusInput::applySettings(const PerseusSettings& settings, bool force)
forwardChange = true;
}

if ((m_settings.m_attenuator != settings.m_attenuator) || force)
if (settingsKeys.contains("attenuator") || force)
{
reverseAPIKeys.append("attenuator");
int rc = perseus_set_attenuator_n(m_perseusDescriptor, (int) settings.m_attenuator);

if (rc < 0) {
Expand All @@ -403,15 +381,8 @@ bool PerseusInput::applySettings(const PerseusSettings& settings, bool force)
}
}

if (force || (m_settings.m_adcDither != settings.m_adcDither)) {
reverseAPIKeys.append("adcDither");
}
if (force || (m_settings.m_adcPreamp != settings.m_adcPreamp)) {
reverseAPIKeys.append("adcPreamp");
}

if ((m_settings.m_adcDither != settings.m_adcDither)
|| (m_settings.m_adcPreamp != settings.m_adcPreamp) || force)
if (settingsKeys.contains("adcDither")
|| settingsKeys.contains("adcPreamp") || force)
{
int rc = perseus_set_adc(m_perseusDescriptor, settings.m_adcDither ? 1 : 0, settings.m_adcPreamp ? 1 : 0);

Expand All @@ -431,29 +402,22 @@ bool PerseusInput::applySettings(const PerseusSettings& settings, bool force)
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
}

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);
}

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

qDebug() << "PerseusInput::applySettings: "
<< " m_LOppmTenths: " << m_settings.m_LOppmTenths
<< " m_devSampleRateIndex: " << m_settings.m_devSampleRateIndex
<< " m_log2Decim: " << m_settings.m_log2Decim
<< " m_iqOrder: " << m_settings.m_iqOrder
<< " m_transverterMode: " << m_settings.m_transverterMode
<< " m_transverterDeltaFrequency: " << m_settings.m_transverterDeltaFrequency
<< " m_adcDither: " << m_settings.m_adcDither
<< " m_adcPreamp: " << m_settings.m_adcPreamp
<< " m_wideBand: " << m_settings.m_wideBand
<< " m_attenuator: " << m_settings.m_attenuator;
m_settings.m_devSampleRateIndex = sampleRateIndex;

return true;
}
Expand Down Expand Up @@ -507,12 +471,12 @@ int PerseusInput::webapiSettingsPutPatch(
PerseusSettings settings = m_settings;
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);

MsgConfigurePerseus *msg = MsgConfigurePerseus::create(settings, force);
MsgConfigurePerseus *msg = MsgConfigurePerseus::create(settings, deviceSettingsKeys, force);
m_inputMessageQueue.push(msg);

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

Expand Down Expand Up @@ -622,7 +586,7 @@ void PerseusInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& respon
}
}

void PerseusInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const PerseusSettings& settings, bool force)
void PerseusInput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const PerseusSettings& settings, bool force)
{
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
swgDeviceSettings->setDirection(0); // single Rx
Expand Down
13 changes: 8 additions & 5 deletions plugins/samplesource/perseus/perseusinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ class PerseusInput : public DeviceSampleSource {

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

static MsgConfigurePerseus* create(const PerseusSettings& settings, bool force)
static MsgConfigurePerseus* create(const PerseusSettings& settings, const QList<QString>& settingsKeys, bool force)
{
return new MsgConfigurePerseus(settings, force);
return new MsgConfigurePerseus(settings, settingsKeys, force);
}

private:
PerseusSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;

MsgConfigurePerseus(const PerseusSettings& settings, bool force) :
MsgConfigurePerseus(const PerseusSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
Expand Down Expand Up @@ -149,9 +152,9 @@ class PerseusInput : public DeviceSampleSource {
bool openDevice();
void closeDevice();
void setDeviceCenterFrequency(quint64 freq, const PerseusSettings& settings);
bool applySettings(const PerseusSettings& settings, bool force = false);
bool applySettings(const PerseusSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const PerseusSettings& settings, bool force);
void webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const PerseusSettings& settings, bool force);
void webapiReverseSendStartStop(bool start);

private slots:
Expand Down
Loading

0 comments on commit 112d059

Please sign in to comment.