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

KiwiSDR: Make settings assignments atomic. Part of #1329

This commit is contained in:
f4exb 2022-10-23 22:02:47 +02:00
parent 203a50d224
commit 30d08b2911
6 changed files with 123 additions and 61 deletions

View File

@ -101,6 +101,7 @@ void KiwiSDRGui::resetToDefaults()
{
m_settings.resetToDefaults();
displaySettings();
m_forceSettings = true;
sendSettings();
}
@ -140,6 +141,7 @@ void KiwiSDRGui::on_startStop_toggled(bool checked)
void KiwiSDRGui::on_centerFrequency_changed(quint64 value)
{
m_settings.m_centerFrequency = value * 1000;
m_settingsKeys.append("centerFrequency");
sendSettings();
}
@ -159,18 +161,21 @@ void KiwiSDRGui::on_serverAddressApplyButton_clicked()
m_settings.m_serverAddress = serverAddress;
}
m_settingsKeys.append("serverAddress");
sendSettings();
}
void KiwiSDRGui::on_dcBlock_toggled(bool checked)
{
m_settings.m_dcBlock = checked;
m_settingsKeys.append("dcBlock");
sendSettings();
}
void KiwiSDRGui::on_agc_toggled(bool checked)
{
m_settings.m_useAGC = checked;
m_settingsKeys.append("useAGC");
sendSettings();
}
@ -178,6 +183,7 @@ void KiwiSDRGui::on_gain_valueChanged(int value)
{
m_settings.m_gain = value;
ui->gainText->setText(QString::number(m_settings.m_gain) + " dB");
m_settingsKeys.append("gain");
sendSettings();
}
@ -206,9 +212,10 @@ void KiwiSDRGui::updateHardware()
{
if (m_doApplySettings)
{
KiwiSDRInput::MsgConfigureKiwiSDR* message = KiwiSDRInput::MsgConfigureKiwiSDR::create(m_settings, m_forceSettings);
KiwiSDRInput::MsgConfigureKiwiSDR* message = KiwiSDRInput::MsgConfigureKiwiSDR::create(m_settings, m_settingsKeys, m_forceSettings);
m_sampleSource->getInputMessageQueue()->push(message);
m_forceSettings = false;
m_settingsKeys.clear();
m_updateTimer.stop();
}
}
@ -248,7 +255,13 @@ bool KiwiSDRGui::handleMessage(const Message& message)
{
qDebug("KiwiSDRGui::handleMessage: MsgConfigureKiwiSDR");
const KiwiSDRInput::MsgConfigureKiwiSDR& cfg = (KiwiSDRInput::MsgConfigureKiwiSDR&) message;
m_settings = cfg.getSettings();
if (cfg.getForce()) {
m_settings = cfg.getSettings();
} else {
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
}
displaySettings();
return true;
}
@ -330,6 +343,10 @@ void KiwiSDRGui::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:
Ui::KiwiSDRGui* ui;
KiwiSDRSettings m_settings;
QList<QString> m_settingsKeys;
QTimer m_updateTimer;
QTimer m_statusTimer;
bool m_doApplySettings;

View File

@ -88,7 +88,7 @@ void KiwiSDRInput::destroy()
void KiwiSDRInput::init()
{
applySettings(m_settings, true);
applySettings(m_settings, QList<QString>(), true);
}
bool KiwiSDRInput::start()
@ -115,7 +115,7 @@ bool KiwiSDRInput::start()
m_running = true;
mutexLocker.unlock();
applySettings(m_settings, true);
applySettings(m_settings, QList<QString>(), true);
return true;
}
@ -155,12 +155,12 @@ bool KiwiSDRInput::deserialize(const QByteArray& data)
success = false;
}
MsgConfigureKiwiSDR* message = MsgConfigureKiwiSDR::create(m_settings, true);
MsgConfigureKiwiSDR* message = MsgConfigureKiwiSDR::create(m_settings, QList<QString>(), true);
m_inputMessageQueue.push(message);
if (m_guiMessageQueue)
{
MsgConfigureKiwiSDR* messageToGUI = MsgConfigureKiwiSDR::create(m_settings, true);
MsgConfigureKiwiSDR* messageToGUI = MsgConfigureKiwiSDR::create(m_settings, QList<QString>(), true);
m_guiMessageQueue->push(messageToGUI);
}
@ -187,12 +187,12 @@ void KiwiSDRInput::setCenterFrequency(qint64 centerFrequency)
KiwiSDRSettings settings = m_settings;
settings.m_centerFrequency = centerFrequency;
MsgConfigureKiwiSDR* message = MsgConfigureKiwiSDR::create(settings, false);
MsgConfigureKiwiSDR* message = MsgConfigureKiwiSDR::create(settings, QList<QString>{"centerFrequency"}, false);
m_inputMessageQueue.push(message);
if (m_guiMessageQueue)
{
MsgConfigureKiwiSDR* messageToGUI = MsgConfigureKiwiSDR::create(settings, false);
MsgConfigureKiwiSDR* messageToGUI = MsgConfigureKiwiSDR::create(settings, QList<QString>{"centerFrequency"}, false);
m_guiMessageQueue->push(messageToGUI);
}
}
@ -211,10 +211,9 @@ bool KiwiSDRInput::handleMessage(const Message& message)
MsgConfigureKiwiSDR& conf = (MsgConfigureKiwiSDR&) message;
qDebug() << "KiwiSDRInput::handleMessage: MsgConfigureKiwiSDR";
bool success = applySettings(conf.getSettings(), conf.getForce());
bool success = applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce());
if (!success)
{
if (!success) {
qDebug("KiwiSDRInput::handleMessage: config error");
}
@ -227,8 +226,7 @@ bool KiwiSDRInput::handleMessage(const Message& message)
if (cmd.getStartStop())
{
if (m_deviceAPI->initDeviceEngine())
{
if (m_deviceAPI->initDeviceEngine()) {
m_deviceAPI->startDeviceEngine();
}
}
@ -258,50 +256,27 @@ int KiwiSDRInput::getStatus() const
}
}
bool KiwiSDRInput::applySettings(const KiwiSDRSettings& settings, bool force)
bool KiwiSDRInput::applySettings(const KiwiSDRSettings& settings, const QList<QString>& settingsKeys, bool force)
{
qDebug() << "KiwiSDRInput::applySettings: "
<< " m_serverAddress: " << settings.m_serverAddress
<< " m_centerFrequency: " << settings.m_centerFrequency
<< " m_gain: " << settings.m_gain
<< " m_useAGC: " << settings.m_useAGC
<< " m_useAGC: " << settings.m_useAGC
<< " m_useReverseAPI: " << settings.m_useReverseAPI
<< " m_reverseAPIAddress: " << settings.m_reverseAPIAddress
<< " m_reverseAPIPort: " << settings.m_reverseAPIPort
<< " m_reverseAPIDeviceIndex: " << settings.m_reverseAPIDeviceIndex;
qDebug() << "KiwiSDRInput::applySettings: force: "<< force << settings.getDebugString(settingsKeys, force);
QList<QString> reverseAPIKeys;
if (m_settings.m_serverAddress != settings.m_serverAddress || force)
if (settingsKeys.contains("serverAddress") || force)
{
reverseAPIKeys.append("serverAddress");
emit setWorkerServerAddress(settings.m_serverAddress);
}
if (m_settings.m_gain != settings.m_gain || force) {
reverseAPIKeys.append("gain");
}
if (m_settings.m_useAGC != settings.m_useAGC || force) {
reverseAPIKeys.append("useAGC");
}
if (m_settings.m_gain != settings.m_gain ||
m_settings.m_useAGC != settings.m_useAGC || force)
if (settingsKeys.contains("gain") ||
settingsKeys.contains("useAGC") || force)
{
emit setWorkerGain(settings.m_gain, settings.m_useAGC);
}
if (m_settings.m_dcBlock != settings.m_dcBlock)
{
reverseAPIKeys.append("dcBlock");
if (settingsKeys.contains("dcBlock")) {
m_deviceAPI->configureCorrections(settings.m_dcBlock, false);
}
if (m_settings.m_centerFrequency != settings.m_centerFrequency || force)
if (settingsKeys.contains("centerFrequency") || force)
{
reverseAPIKeys.append("centerFrequency");
emit setWorkerCenterFrequency(settings.m_centerFrequency);
DSPSignalNotification *notif = new DSPSignalNotification(
@ -309,17 +284,21 @@ bool KiwiSDRInput::applySettings(const KiwiSDRSettings& settings, bool force)
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
}
if (settings.m_useReverseAPI)
if (settingsKeys.contains("useReverseAPI"))
{
qDebug("KiwiSDRInput::applySettings: call webapiReverseSendSettings");
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);
}
if (force) {
m_settings = settings;
} else {
m_settings.applySettings(settingsKeys, settings);
}
m_settings = settings;
return true;
}
@ -372,12 +351,12 @@ int KiwiSDRInput::webapiSettingsPutPatch(
KiwiSDRSettings settings = m_settings;
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
MsgConfigureKiwiSDR *msg = MsgConfigureKiwiSDR::create(settings, force);
MsgConfigureKiwiSDR *msg = MsgConfigureKiwiSDR::create(settings, deviceSettingsKeys, force);
m_inputMessageQueue.push(msg);
if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureKiwiSDR *msgToGUI = MsgConfigureKiwiSDR::create(settings, force);
MsgConfigureKiwiSDR *msgToGUI = MsgConfigureKiwiSDR::create(settings, deviceSettingsKeys, force);
m_guiMessageQueue->push(msgToGUI);
}
@ -460,7 +439,7 @@ void KiwiSDRInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& respon
response.getKiwiSdrReport()->setStatus(getStatus());
}
void KiwiSDRInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const KiwiSDRSettings& settings, bool force)
void KiwiSDRInput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const KiwiSDRSettings& settings, bool force)
{
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
swgDeviceSettings->setDirection(0); // single Rx

View File

@ -41,20 +41,23 @@ public:
public:
const KiwiSDRSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
static MsgConfigureKiwiSDR* create(const KiwiSDRSettings& settings, bool force)
static MsgConfigureKiwiSDR* create(const KiwiSDRSettings& settings, const QList<QString>& settingsKeys, bool force)
{
return new MsgConfigureKiwiSDR(settings, force);
return new MsgConfigureKiwiSDR(settings, settingsKeys, force);
}
private:
KiwiSDRSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
MsgConfigureKiwiSDR(const KiwiSDRSettings& settings, bool force) :
MsgConfigureKiwiSDR(const KiwiSDRSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
@ -162,9 +165,9 @@ private:
QNetworkRequest m_networkRequest;
int getStatus() const;
bool applySettings(const KiwiSDRSettings& settings, bool force);
bool applySettings(const KiwiSDRSettings& settings, const QList<QString>& settingsKeys, bool force);
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const KiwiSDRSettings& settings, bool force);
void webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const KiwiSDRSettings& settings, bool force);
void webapiReverseSendStartStop(bool start);
signals:

View File

@ -97,8 +97,68 @@ bool KiwiSDRSettings::deserialize(const QByteArray& data)
}
}
void KiwiSDRSettings::applySettings(const QStringList& settingsKeys, const KiwiSDRSettings& settings)
{
if (settingsKeys.contains("centerFrequency")) {
m_centerFrequency = settings.m_centerFrequency;
}
if (settingsKeys.contains("gain")) {
m_gain = settings.m_gain;
}
if (settingsKeys.contains("useAGC")) {
m_useAGC = settings.m_useAGC;
}
if (settingsKeys.contains("dcBlock")) {
m_dcBlock = settings.m_dcBlock;
}
if (settingsKeys.contains("serverAddress")) {
m_serverAddress = settings.m_serverAddress;
}
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 KiwiSDRSettings::getDebugString(const QStringList& settingsKeys, bool force) const
{
std::ostringstream ostr;
if (settingsKeys.contains("centerFrequency") || force) {
ostr << " m_centerFrequency: " << m_centerFrequency;
}
if (settingsKeys.contains("gain") || force) {
ostr << " m_gain: " << m_gain;
}
if (settingsKeys.contains("useAGC") || force) {
ostr << " m_useAGC: " << m_useAGC;
}
if (settingsKeys.contains("dcBlock") || force) {
ostr << " m_dcBlock: " << m_dcBlock;
}
if (settingsKeys.contains("serverAddress") || force) {
ostr << " m_serverAddress: " << m_serverAddress.toStdString();
}
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

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