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

Perseus: Make settings assignments atomic. Part of #1329

This commit is contained in:
f4exb 2022-10-23 23:59:48 +02:00
parent 4d8667e716
commit 112d0594b5
6 changed files with 175 additions and 81 deletions

View File

@ -84,6 +84,7 @@ void PerseusGui::resetToDefaults()
{
m_settings.resetToDefaults();
displaySettings();
m_forceSettings = true;
sendSettings();
}
@ -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);
@ -253,6 +260,7 @@ void PerseusGui::sendSettings()
void PerseusGui::on_centerFrequency_changed(quint64 value)
{
m_settings.m_centerFrequency = value * 1000;
m_settingsKeys.append("centerFrequency");
sendSettings();
}
@ -260,6 +268,7 @@ 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();
}
@ -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();
}
@ -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();
}
@ -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();
}

View File

@ -57,6 +57,7 @@ private:
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;

View File

@ -74,7 +74,7 @@ void PerseusInput::destroy()
void PerseusInput::init()
{
applySettings(m_settings, true);
applySettings(m_settings, QList<QString>(), true);
}
bool PerseusInput::start()
@ -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;
@ -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);
}
@ -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);
}
}
@ -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");
@ -208,8 +208,7 @@ bool PerseusInput::handleMessage(const Message& message)
if (cmd.getStartStop())
{
if (m_deviceAPI->initDeviceEngine())
{
if (m_deviceAPI->initDeviceEngine()) {
m_deviceAPI->startDeviceEngine();
}
}
@ -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()) {
@ -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)
@ -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;
@ -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) {
@ -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);
@ -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;
}
@ -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);
}
@ -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

View File

@ -42,20 +42,23 @@ public:
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)
{ }
};
@ -149,9 +152,9 @@ private:
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:

View File

@ -119,3 +119,104 @@ bool PerseusSettings::deserialize(const QByteArray& data)
}
}
void PerseusSettings::applySettings(const QStringList& settingsKeys, const PerseusSettings& settings)
{
if (settingsKeys.contains("centerFrequency")) {
m_centerFrequency = settings.m_centerFrequency;
}
if (settingsKeys.contains("LOppmTenths")) {
m_LOppmTenths = settings.m_LOppmTenths;
}
if (settingsKeys.contains("devSampleRateIndex")) {
m_devSampleRateIndex = settings.m_devSampleRateIndex;
}
if (settingsKeys.contains("log2Decim")) {
m_log2Decim = settings.m_log2Decim;
}
if (settingsKeys.contains("transverterMode")) {
m_transverterMode = settings.m_transverterMode;
}
if (settingsKeys.contains("transverterDeltaFrequency")) {
m_transverterDeltaFrequency = settings.m_transverterDeltaFrequency;
}
if (settingsKeys.contains("iqOrder")) {
m_iqOrder = settings.m_iqOrder;
}
if (settingsKeys.contains("adcDither")) {
m_adcDither = settings.m_adcDither;
}
if (settingsKeys.contains("adcPreamp")) {
m_adcPreamp = settings.m_adcPreamp;
}
if (settingsKeys.contains("wideBand")) {
m_wideBand = settings.m_wideBand;
}
if (settingsKeys.contains("attenuator")) {
m_attenuator = settings.m_attenuator;
}
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 PerseusSettings::getDebugString(const QStringList& settingsKeys, bool force) const
{
std::ostringstream ostr;
if (settingsKeys.contains("centerFrequency") || force) {
ostr << " m_centerFrequency: " << m_centerFrequency;
}
if (settingsKeys.contains("LOppmTenths") || force) {
ostr << " m_LOppmTenths: " << m_LOppmTenths;
}
if (settingsKeys.contains("devSampleRateIndex") || force) {
ostr << " m_devSampleRateIndex: " << m_devSampleRateIndex;
}
if (settingsKeys.contains("log2Decim") || force) {
ostr << " m_log2Decim: " << m_log2Decim;
}
if (settingsKeys.contains("transverterMode") || force) {
ostr << " m_transverterMode: " << m_transverterMode;
}
if (settingsKeys.contains("transverterDeltaFrequency") || force) {
ostr << " m_transverterDeltaFrequency: " << m_transverterDeltaFrequency;
}
if (settingsKeys.contains("iqOrder") || force) {
ostr << " m_iqOrder: " << m_iqOrder;
}
if (settingsKeys.contains("adcDither") || force) {
ostr << " m_adcDither: " << m_adcDither;
}
if (settingsKeys.contains("adcPreamp") || force) {
ostr << " m_adcPreamp: " << m_adcPreamp;
}
if (settingsKeys.contains("wideBand") || force) {
ostr << " m_wideBand: " << m_wideBand;
}
if (settingsKeys.contains("attenuator") || force) {
ostr << " m_attenuator: " << m_attenuator;
}
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

@ -52,6 +52,8 @@ struct PerseusSettings
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
void applySettings(const QStringList& settingsKeys, const PerseusSettings& settings);
QString getDebugString(const QStringList& settingsKeys, bool force=false) const;
};