Skip to content

Commit

Permalink
Merge pull request #1789 from srcejon/fix_1430
Browse files Browse the repository at this point in the history
Add support for Plugin Presets
  • Loading branch information
f4exb authored Aug 25, 2023
2 parents 2565a38 + 667908a commit 6105212
Show file tree
Hide file tree
Showing 29 changed files with 1,432 additions and 41 deletions.
2 changes: 2 additions & 0 deletions sdrbase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ set(sdrbase_SOURCES

settings/configuration.cpp
settings/featuresetpreset.cpp
settings/pluginpreset.cpp
settings/preferences.cpp
settings/preset.cpp
settings/mainsettings.cpp
Expand Down Expand Up @@ -437,6 +438,7 @@ set(sdrbase_HEADERS

settings/configuration.h
settings/featuresetpreset.h
settings/pluginpreset.h
settings/preferences.h
settings/preset.h
settings/mainsettings.h
Expand Down
112 changes: 112 additions & 0 deletions sdrbase/device/deviceapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "dsp/devicesamplemimo.h"
#include "settings/preset.h"
#include "channel/channelapi.h"
#include "util/simpleserializer.h"

#include "deviceapi.h"

Expand Down Expand Up @@ -467,6 +468,117 @@ ChannelAPI *DeviceAPI::getMIMOChannelAPIAt(int index)
}
}

QList<quint64> DeviceAPI::getCenterFrequency() const
{
QList<quint64> frequencies;

if (m_deviceSourceEngine && m_deviceSourceEngine->getSource())
{
frequencies.append(m_deviceSourceEngine->getSource()->getCenterFrequency());
}
else if (m_deviceSinkEngine && m_deviceSinkEngine->getSink())
{
frequencies.append(m_deviceSinkEngine->getSink()->getCenterFrequency());
}
else if (m_deviceMIMOEngine && m_deviceMIMOEngine->getMIMO())
{
for (uint32_t i = 0; i < m_deviceMIMOEngine->getMIMO()->getNbSourceStreams(); i++) {
frequencies.append(m_deviceMIMOEngine->getMIMO()->getSourceCenterFrequency(i));
}
for (uint32_t i = 0; i < m_deviceMIMOEngine->getMIMO()->getNbSinkStreams(); i++) {
frequencies.append(m_deviceMIMOEngine->getMIMO()->getSinkCenterFrequency(i));
}
}
return frequencies;
}

void DeviceAPI::setCenterFrequency(QList<quint64> centerFrequency)
{
if (m_deviceSourceEngine && m_deviceSourceEngine->getSource())
{
m_deviceSourceEngine->getSource()->setCenterFrequency(centerFrequency[0]);
}
else if (m_deviceSinkEngine && m_deviceSinkEngine->getSink())
{
m_deviceSinkEngine->getSink()->setCenterFrequency(centerFrequency[0]);
}
else if (m_deviceMIMOEngine && m_deviceMIMOEngine->getMIMO())
{
int idx = 0;
for (uint32_t i = 0; i < m_deviceMIMOEngine->getMIMO()->getNbSourceStreams(); i++, idx++) {
m_deviceMIMOEngine->getMIMO()->setSourceCenterFrequency(centerFrequency[idx], i);
}
for (uint32_t i = 0; i < m_deviceMIMOEngine->getMIMO()->getNbSinkStreams(); i++, idx++) {
m_deviceMIMOEngine->getMIMO()->setSinkCenterFrequency(centerFrequency[idx], i);
}
}
}

// Serialization is only currently used for saving device settings as part of a Device preset
// loadSamplingDeviceSettings/saveSamplingDeviceSettings is used for Device Set presets (which includes channel settings)

QByteArray DeviceAPI::serialize() const
{
SimpleSerializer s(1);

if (m_deviceSourceEngine && m_deviceSourceEngine->getSource()) {
s.writeBlob(1, m_deviceSourceEngine->getSource()->serialize());
}
if (m_deviceSinkEngine && m_deviceSinkEngine->getSink()) {
s.writeBlob(2, m_deviceSinkEngine->getSink()->serialize());
}
if (m_deviceMIMOEngine && m_deviceMIMOEngine->getMIMO()) {
s.writeBlob(3, m_deviceMIMOEngine->getMIMO()->serialize());
}
s.writeList<quint64>(4, getCenterFrequency());
return s.final();
}

bool DeviceAPI::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);

if (!d.isValid()) {
return false;
}

if (d.getVersion() == 1)
{
QByteArray data;
QList<quint64> centerFrequency;

if (m_deviceSourceEngine && m_deviceSourceEngine->getSource())
{
d.readBlob(1, &data);
if (data.size() > 0) {
m_deviceSourceEngine->getSource()->deserialize(data);
}
}
if (m_deviceSinkEngine && m_deviceSinkEngine->getSink())
{
d.readBlob(2, &data);
if (data.size() > 0) {
m_deviceSinkEngine->getSink()->deserialize(data);
}
}
if (m_deviceMIMOEngine && m_deviceMIMOEngine->getMIMO())
{
d.readBlob(3, &data);
if (data.size() > 0) {
m_deviceMIMOEngine->getMIMO()->deserialize(data);
}
}
d.readList<quint64>(4, &centerFrequency);
setCenterFrequency(centerFrequency);

return true;
}
else
{
return false;
}
}

void DeviceAPI::loadSamplingDeviceSettings(const Preset* preset)
{
if (m_deviceSourceEngine && (preset->isSourcePreset()))
Expand Down
10 changes: 9 additions & 1 deletion sdrbase/device/deviceapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QString>
#include <QTimer>

#include "settings/serializableinterface.h"
#include "export.h"

class BasebandSampleSink;
Expand All @@ -38,7 +39,7 @@ class DSPDeviceSinkEngine;
class DSPDeviceMIMOEngine;
class Preset;

class SDRBASE_API DeviceAPI : public QObject {
class SDRBASE_API DeviceAPI : public QObject, public SerializableInterface {
Q_OBJECT
public:
enum StreamType //!< This is the same enum as in PluginInterface
Expand Down Expand Up @@ -146,6 +147,13 @@ class SDRBASE_API DeviceAPI : public QObject {
// void saveSourceSettings(Preset* preset);
// void saveSinkSettings(Preset* preset);

QByteArray serialize() const override;
bool deserialize(const QByteArray& data) override;

// List of one frequency for Single Rx / Tx or one frequency per stream for MIMO
QList<quint64> getCenterFrequency() const;
void setCenterFrequency(QList<quint64> centerFrequency);

DSPDeviceSourceEngine *getDeviceSourceEngine() { return m_deviceSourceEngine; }
DSPDeviceSinkEngine *getDeviceSinkEngine() { return m_deviceSinkEngine; }
DSPDeviceMIMOEngine *getDeviceMIMOEngine() { return m_deviceMIMOEngine; }
Expand Down
1 change: 1 addition & 0 deletions sdrbase/maincore.h
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ class SDRBASE_API MainCore : public QObject
qint64 getElapsedNsecs() const { return m_masterElapsedTimer.nsecsElapsed(); } //!< Elapsed nanoseconds since main core construction
qint64 getStartMsecsSinceEpoch() const { return m_startMsecsSinceEpoch; } //!< Epoch timestamp in millisecodns close to elapsed timer start
const MainSettings& getSettings() const { return m_settings; }
MainSettings& getMutableSettings() { return m_settings; }
MessageQueue *getMainMessageQueue() { return m_mainMessageQueue; }
PluginManager *getPluginManager() const { return m_pluginManager; }
std::vector<DeviceSet*>& getDeviceSets() { return m_deviceSets; }
Expand Down
110 changes: 110 additions & 0 deletions sdrbase/settings/mainsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ MainSettings::~MainSettings()
{
delete m_featureSetPresets[i];
}
for (int i = 0; i < m_pluginPresets.count(); ++i)
{
delete m_pluginPresets[i];
}
}

QString MainSettings::getFileLocation() const
Expand Down Expand Up @@ -108,6 +112,22 @@ void MainSettings::load()
delete featureSetPreset;
}

s.endGroup();
}
else if (groups[i].startsWith("pluginpreset"))
{
s.beginGroup(groups[i]);
PluginPreset* pluginPreset = new PluginPreset;

if (pluginPreset->deserialize(qUncompress(QByteArray::fromBase64(s.value("data").toByteArray()))))
{
m_pluginPresets.append(pluginPreset);
}
else
{
delete pluginPreset;
}

s.endGroup();
}
else if (groups[i].startsWith("configuration"))
Expand Down Expand Up @@ -176,6 +196,14 @@ void MainSettings::save() const
s.endGroup();
}

for (int i = 0; i < m_pluginPresets.count(); ++i)
{
QString group = QString("pluginpreset-%1").arg(i + 1);
s.beginGroup(group);
s.setValue("data", qCompress(m_pluginPresets[i]->serialize()).toBase64());
s.endGroup();
}

for (int i = 0; i < m_configurations.count(); ++i)
{
QString group = QString("configuration-%1").arg(i + 1);
Expand All @@ -193,6 +221,7 @@ void MainSettings::initialize()
clearCommands();
clearPresets();
clearFeatureSetPresets();
clearPluginPresets();
clearConfigurations();
}

Expand All @@ -201,6 +230,7 @@ void MainSettings::resetToDefaults()
m_preferences.resetToDefaults();
m_workingPreset.resetToDefaults();
m_workingFeatureSetPreset.resetToDefaults();
m_workingPluginPreset.resetToDefaults();
m_workingConfiguration.resetToDefaults();
}

Expand Down Expand Up @@ -452,6 +482,86 @@ void MainSettings::clearFeatureSetPresets()
m_featureSetPresets.clear();
}

// FeatureSet presets

PluginPreset* MainSettings::newPluginPreset(const QString& group, const QString& description)
{
PluginPreset* preset = new PluginPreset();
preset->setGroup(group);
preset->setDescription(description);
addPluginPreset(preset);
return preset;
}

void MainSettings::addPluginPreset(PluginPreset *preset)
{
m_pluginPresets.append(preset);
}

void MainSettings::deletePluginPreset(const PluginPreset* preset)
{
m_pluginPresets.removeAll((PluginPreset*) preset);
delete (PluginPreset*) preset;
}

void MainSettings::deletePluginPresetGroup(const QString& groupName)
{
PluginPresets::iterator it = m_pluginPresets.begin();

while (it != m_pluginPresets.end())
{
if ((*it)->getGroup() == groupName) {
it = m_pluginPresets.erase(it);
} else {
++it;
}
}
}

void MainSettings::sortPluginPresets()
{
std::sort(m_pluginPresets.begin(), m_pluginPresets.end(), PluginPreset::presetCompare);
}

void MainSettings::renamePluginPresetGroup(const QString& oldGroupName, const QString& newGroupName)
{
int nbPresets = getPluginPresetCount();

for (int i = 0; i < nbPresets; i++)
{
if (getPluginPreset(i)->getGroup() == oldGroupName)
{
PluginPreset *preset_mod = const_cast<PluginPreset*>(getPluginPreset(i));
preset_mod->setGroup(newGroupName);
}
}
}

const PluginPreset* MainSettings::getPluginPreset(const QString& groupName, const QString& description) const
{
int nbPresets = getPluginPresetCount();

for (int i = 0; i < nbPresets; i++)
{
if ((getPluginPreset(i)->getGroup() == groupName) &&
(getPluginPreset(i)->getDescription() == description))
{
return getPluginPreset(i);
}
}

return nullptr;
}

void MainSettings::clearPluginPresets()
{
foreach (PluginPreset *preset, m_pluginPresets) {
delete preset;
}

m_pluginPresets.clear();
}

// Configurations

Configuration* MainSettings::newConfiguration(const QString& group, const QString& description)
Expand Down
18 changes: 18 additions & 0 deletions sdrbase/settings/mainsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "preferences.h"
#include "preset.h"
#include "featuresetpreset.h"
#include "pluginpreset.h"
#include "configuration.h"
#include "export.h"
#include "plugin/pluginmanager.h"
Expand Down Expand Up @@ -72,6 +73,20 @@ class SDRBASE_API MainSettings : public QObject {
FeatureSetPreset* getWorkingFeatureSetPreset() { return &m_workingFeatureSetPreset; }
QList<FeatureSetPreset*> *getFeatureSetPresets() { return &m_featureSetPresets; }

PluginPreset* newPluginPreset(const QString& group, const QString& description);
void addPluginPreset(PluginPreset *preset);
void deletePluginPreset(const PluginPreset* preset);
int getPluginPresetCount() const { return m_pluginPresets.count(); }
const PluginPreset* getPluginPreset(int index) const { return m_pluginPresets[index]; }
const PluginPreset* getPluginPreset(const QString& groupName, const QString& description) const;
void sortPluginPresets();
void renamePluginPresetGroup(const QString& oldGroupName, const QString& newGroupName);
void deletePluginPresetGroup(const QString& groupName);
void clearPluginPresets();
const PluginPreset& getWorkingPluginPresetConst() const { return m_workingPluginPreset; }
PluginPreset* getWorkingPluginPreset() { return &m_workingPluginPreset; }
QList<PluginPreset*> *getPluginPresets() { return &m_pluginPresets; }

Configuration* newConfiguration(const QString& group, const QString& description);
void addConfiguration(Configuration *configuration);
void deleteConfiguration(const Configuration *configuration);
Expand Down Expand Up @@ -231,6 +246,9 @@ class SDRBASE_API MainSettings : public QObject {
FeatureSetPreset m_workingFeatureSetPreset;
typedef QList<FeatureSetPreset*> FeatureSetPresets;
FeatureSetPresets m_featureSetPresets;
PluginPreset m_workingPluginPreset;
typedef QList<PluginPreset*> PluginPresets;
PluginPresets m_pluginPresets;
Configuration m_workingConfiguration;
typedef QList<Configuration*> Configurations;
Configurations m_configurations;
Expand Down
Loading

0 comments on commit 6105212

Please sign in to comment.