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

New preset design: changed device registration

This commit is contained in:
f4exb 2015-09-30 06:57:40 +02:00
parent f50e717c20
commit a1efdcc8dc
13 changed files with 176 additions and 88 deletions

View File

@ -57,7 +57,7 @@ public:
void updateSampleSourceDevices();
void fillSampleSourceSelector(QComboBox* comboBox);
int selectSampleSource(int index);
int selectSampleSource(const QString& source);
int selectFirstSampleSource(const QString& sourceId);
private:
struct ChannelRegistration {
@ -86,10 +86,10 @@ private:
typedef QList<ChannelInstanceRegistration> ChannelInstanceRegistrations;
struct SampleSourceRegistration {
QString m_sourceName;
QString m_sourceId;
PluginInterface* m_plugin;
SampleSourceRegistration(const QString& sourceName, PluginInterface* plugin) :
m_sourceName(sourceName),
SampleSourceRegistration(const QString& sourceId, PluginInterface* plugin) :
m_sourceId(sourceId),
m_plugin(plugin)
{ }
};
@ -98,14 +98,20 @@ private:
struct SampleSourceDevice {
PluginInterface* m_plugin;
QString m_displayName;
QString m_sourceName;
QByteArray m_address;
QString m_sourceId;
QString m_sourceSerial;
int m_sourceSequence;
SampleSourceDevice(PluginInterface* plugin, const QString& displayName, const QString& sourceName, const QByteArray& address) :
SampleSourceDevice(PluginInterface* plugin,
const QString& displayName,
const QString& sourceId,
const QString& sourceSerial,
int sourceSequence) :
m_plugin(plugin),
m_displayName(displayName),
m_sourceName(sourceName),
m_address(address)
m_sourceId(sourceId),
m_sourceSerial(sourceSerial),
m_sourceSequence(sourceSequence)
{ }
};
typedef QList<SampleSourceDevice> SampleSourceDevices;
@ -120,7 +126,9 @@ private:
SampleSourceRegistrations m_sampleSourceRegistrations;
SampleSourceDevices m_sampleSourceDevices;
QString m_sampleSourceName;
QString m_sampleSourceId;
QString m_sampleSourceSerial;
int m_sampleSourceSequence;
PluginGUI* m_sampleSourcePluginGUI;
void loadPlugins(const QDir& dir);

View File

@ -42,12 +42,17 @@ public:
int getChannelCount() const { return m_channelConfigs.count(); }
const ChannelConfig& getChannelConfig(int index) const { return m_channelConfigs.at(index); }
void setSourceConfig(const QString& source, const QByteArray& config)
void setSourceConfig(const QString& sourceId, const QString& sourceSerial, int sourceSequence, const QByteArray& config)
{
m_source = source;
m_sourceId = sourceId;
m_sourceSerial = sourceSerial;
m_sourceSequence = sourceSequence;
m_sourceConfig = config;
}
const QString& getSource() const { return m_source; }
const QString& getSourceId() const { return m_sourceId; }
const QString& getSourceSerial() const { return m_sourceSerial; }
const int getSourceSequence() const { return m_sourceSequence; }
const QByteArray& getSourceConfig() const { return m_sourceConfig; }
protected:
@ -64,7 +69,9 @@ protected:
bool m_iqImbalanceCorrection;
// sample source and sample source configuration
QString m_source;
QString m_sourceId;
QString m_sourceSerial;
int m_sourceSequence;
QByteArray m_sourceConfig;
// channels and configurations

View File

@ -19,15 +19,21 @@ class PluginGUI;
class PluginInterface {
public:
struct SampleSourceDevice {
struct SampleSourceDevice
{
QString displayedName;
QString name;
QByteArray address;
QString id;
QString serial;
int sequence;
SampleSourceDevice(const QString& _displayedName, const QString& _name, const QByteArray& _address) :
SampleSourceDevice(const QString& _displayedName,
const QString& _id,
const QString& _serial,
int _sequence) :
displayedName(_displayedName),
name(_name),
address(_address)
id(_id),
serial(_serial),
sequence(_sequence)
{ }
};
typedef QList<SampleSourceDevice> SampleSourceDevices;
@ -37,10 +43,10 @@ public:
virtual const PluginDescriptor& getPluginDescriptor() const = 0;
virtual void initPlugin(PluginAPI* pluginAPI) = 0;
virtual PluginGUI* createChannel(const QString& channelName) { return NULL; }
virtual PluginGUI* createChannel(const QString& channelName) { return 0; }
virtual SampleSourceDevices enumSampleSources() { return SampleSourceDevices(); }
virtual PluginGUI* createSampleSourcePluginGUI(const QString& sourceName, const QByteArray& address) { return NULL; }
virtual PluginGUI* createSampleSourcePluginGUI(const QString& sourceId, const QString& sourceSerial, int sourceSequence) { return 0; }
};
Q_DECLARE_INTERFACE(PluginInterface, "de.maintech.SDRangelove.PluginInterface/0.1");

View File

@ -91,11 +91,12 @@ PluginInterface::SampleSourceDevices AirspyPlugin::enumSampleSources()
QString serial_str = QString::number(serial_msb, 16) + QString::number(serial_lsb, 16);
uint64_t serial_num = (((uint64_t) serial_msb)<<32) + serial_lsb;
QString displayedName(QString("Airspy #%1 0x%2").arg(i).arg(serial_str));
SimpleSerializer s(1);
s.writeS32(1, i);
s.writeString(2, serial_str);
s.writeU64(3, serial_num);
result.append(SampleSourceDevice(displayedName, "org.osmocom.sdr.samplesource.airspy", s.final()));
result.append(SampleSourceDevice(displayedName,
"org.osmocom.sdr.samplesource.airspy",
serial_str,
i));
qDebug("AirspyPlugin::enumSampleSources: enumerated Airspy device #%d", i);
}

View File

@ -58,10 +58,11 @@ PluginInterface::SampleSourceDevices BlderfPlugin::enumSampleSources()
for(int i = 0; i < count; i++)
{
QString displayedName(QString("BladeRF #%1 %2 (%3,%4)").arg(devinfo[i].instance).arg(devinfo[i].serial).arg(devinfo[i].usb_bus).arg(devinfo[i].usb_addr));
SimpleSerializer s(1);
s.writeS32(1, i);
s.writeString(2, devinfo[i].serial);
result.append(SampleSourceDevice(displayedName, "org.osmocom.sdr.samplesource.bladerf", s.final()));
result.append(SampleSourceDevice(displayedName,
"org.osmocom.sdr.samplesource.bladerf",
QString(devinfo[i].serial),
i));
}
if (devinfo)

View File

@ -54,16 +54,18 @@ PluginInterface::SampleSourceDevices FCDProPlugin::enumSampleSources()
{
SampleSourceDevices result;
int i = 1;
int i = 0;
struct hid_device_info *device_info = hid_enumerate(fcd_traits<Pro>::vendorId, fcd_traits<Pro>::productId);
while (device_info != 0)
{
QString serialNumber = QString::fromWCharArray(device_info->serial_number);
QString displayedName(QString("%1 #%2 %3").arg(fcd_traits<Pro>::displayedName).arg(i).arg(serialNumber));
SimpleSerializer s(1);
s.writeS32(1, 0);
result.append(SampleSourceDevice(displayedName, fcd_traits<Pro>::interfaceIID, s.final()));
result.append(SampleSourceDevice(displayedName,
fcd_traits<Pro>::interfaceIID,
QString::null,
i));
device_info = device_info->next;
i++;

View File

@ -52,16 +52,18 @@ PluginInterface::SampleSourceDevices FCDProPlusPlugin::enumSampleSources()
{
SampleSourceDevices result;
int i = 1;
int i = 0;
struct hid_device_info *device_info = hid_enumerate(fcd_traits<ProPlus>::vendorId, fcd_traits<ProPlus>::productId);
while (device_info != 0)
{
QString serialNumber = QString::fromWCharArray(device_info->serial_number);
QString displayedName(QString("%1 #%2 %3").arg(fcd_traits<ProPlus>::displayedName).arg(i).arg(serialNumber));
SimpleSerializer s(1);
s.writeS32(1, 0);
result.append(SampleSourceDevice(displayedName, fcd_traits<ProPlus>::interfaceIID, s.final()));
result.append(SampleSourceDevice(displayedName,
fcd_traits<ProPlus>::interfaceIID,
QString::null,
i));
device_info = device_info->next;
i++;

View File

@ -59,7 +59,11 @@ PluginInterface::SampleSourceDevices FileSourcePlugin::enumSampleSources()
SimpleSerializer s(1);
s.writeS32(1, i);
s.writeString(2, "");
result.append(SampleSourceDevice(displayedName, "org.osmocom.sdr.samplesource.filesource", s.final()));
result.append(SampleSourceDevice(displayedName,
"org.osmocom.sdr.samplesource.filesource",
QString::null,
i));
}
return result;

View File

@ -98,7 +98,11 @@ PluginInterface::SampleSourceDevices HackRFPlugin::enumSampleSources()
s.writeS32(1, i);
s.writeString(2, serial_str);
s.writeU64(3, serial_num);
result.append(SampleSourceDevice(displayedName, m_deviceTypeID, s.final()));
result.append(SampleSourceDevice(displayedName, m_deviceTypeID,
serial_str,
i));
qDebug("HackRFPlugin::enumSampleSources: enumerated HackRF device #%d", i);
hackrf_close(hackrf_ptr);

View File

@ -48,9 +48,11 @@ PluginInterface::SampleSourceDevices RTLSDRPlugin::enumSampleSources()
if(rtlsdr_get_device_usb_strings((uint32_t)i, vendor, product, serial) != 0)
continue;
QString displayedName(QString("RTL-SDR #%1 (%2 #%3)").arg(i + 1).arg(product).arg(serial));
SimpleSerializer s(1);
s.writeS32(1, i);
result.append(SampleSourceDevice(displayedName, "org.osmocom.sdr.samplesource.rtl-sdr", s.final()));
result.append(SampleSourceDevice(displayedName,
"org.osmocom.sdr.samplesource.rtl-sdr",
QString(serial),
i));
}
return result;
}

View File

@ -115,7 +115,7 @@ MainWindow::MainWindow(QWidget* parent) :
qDebug() << "MainWindow::MainWindow: select SampleSource from settings...";
int sampleSourceIndex = m_pluginManager->selectSampleSource(m_settings.getCurrent()->getSource()); // select SampleSource from settings
int sampleSourceIndex = m_pluginManager->selectFirstSampleSource(m_settings.getCurrent()->getSourceId()); // select SampleSource from settings
if(sampleSourceIndex >= 0)
{
@ -208,7 +208,7 @@ void MainWindow::loadSettings()
void MainWindow::loadPresetSettings(const Preset* preset)
{
qDebug() << "MainWindow::loadPresetSettings: preset: " << preset->getSource().toStdString().c_str();
qDebug() << "MainWindow::loadPresetSettings: preset: " << preset->getSourceId().toStdString().c_str();
ui->glSpectrumGUI->deserialize(preset->getSpectrumConfig());
@ -229,7 +229,7 @@ void MainWindow::saveSettings()
void MainWindow::savePresetSettings(Preset* preset)
{
qDebug() << "MainWindow::savePresetSettings: preset: " << preset->getSource().toStdString().c_str();
qDebug() << "MainWindow::savePresetSettings: preset: " << preset->getSourceId().toStdString().c_str();
preset->setSpectrumConfig(ui->glSpectrumGUI->serialize());
preset->clearChannels();

View File

@ -16,7 +16,7 @@ PluginManager::PluginManager(MainWindow* mainWindow, DSPEngine* dspEngine, QObje
m_pluginAPI(this, mainWindow, dspEngine),
m_mainWindow(mainWindow),
m_dspEngine(dspEngine),
m_sampleSourceName(),
m_sampleSourceId(),
m_sampleSourcePluginGUI(NULL)
{
}
@ -142,12 +142,12 @@ void PluginManager::loadSettings(const Preset* preset)
if(m_sampleSourcePluginGUI != 0)
{
qDebug("PluginManager::loadSettings: source compare [%s] vs [%s]", qPrintable(m_sampleSourceName), qPrintable(preset->getSource()));
qDebug("PluginManager::loadSettings: source compare [%s] vs [%s]", qPrintable(m_sampleSourceId), qPrintable(preset->getSourceId()));
// TODO: have one set of source presets per identified source (preset -> find source with name)
if(m_sampleSourceName == preset->getSource())
if(m_sampleSourceId == preset->getSourceId())
{
qDebug() << "PluginManager::loadSettings: deserializing source " << qPrintable(m_sampleSourceName);
qDebug() << "PluginManager::loadSettings: deserializing source " << qPrintable(m_sampleSourceId);
m_sampleSourcePluginGUI->deserialize(preset->getSourceConfig());
}
@ -174,12 +174,12 @@ void PluginManager::saveSettings(Preset* preset)
{
if(m_sampleSourcePluginGUI != NULL)
{
preset->setSourceConfig(m_sampleSourceName, m_sampleSourcePluginGUI->serialize());
preset->setSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize());
preset->setCenterFrequency(m_sampleSourcePluginGUI->getCenterFrequency());
}
else
{
preset->setSourceConfig(QString::null, QByteArray());
preset->setSourceConfig(QString::null, QString::null, 0, QByteArray());
}
qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type
@ -203,7 +203,7 @@ void PluginManager::freeAll()
m_dspEngine->setSource(NULL);
m_sampleSourcePluginGUI->destroy();
m_sampleSourcePluginGUI = NULL;
m_sampleSourceName.clear();
m_sampleSourceId.clear();
}
}
@ -237,10 +237,19 @@ bool PluginManager::handleMessage(const Message& message)
void PluginManager::updateSampleSourceDevices()
{
m_sampleSourceDevices.clear();
for(int i = 0; i < m_sampleSourceRegistrations.count(); ++i) {
for(int i = 0; i < m_sampleSourceRegistrations.count(); ++i)
{
PluginInterface::SampleSourceDevices ssd = m_sampleSourceRegistrations[i].m_plugin->enumSampleSources();
for(int j = 0; j < ssd.count(); ++j)
m_sampleSourceDevices.append(SampleSourceDevice(m_sampleSourceRegistrations[i].m_plugin, ssd[j].displayedName, ssd[j].name, ssd[j].address));
{
m_sampleSourceDevices.append(SampleSourceDevice(m_sampleSourceRegistrations[i].m_plugin,
ssd[j].displayedName,
ssd[j].id,
ssd[j].serial,
ssd[j].sequence));
}
}
}
@ -262,35 +271,56 @@ int PluginManager::selectSampleSource(int index)
m_dspEngine->setSource(NULL);
m_sampleSourcePluginGUI->destroy();
m_sampleSourcePluginGUI = NULL;
m_sampleSourceName.clear();
m_sampleSourceId.clear();
}
if(index == -1) {
if(!m_sampleSourceName.isEmpty()) {
for(int i = 0; i < m_sampleSourceDevices.count(); i++) {
if(m_sampleSourceDevices[i].m_sourceName == m_sampleSourceName) {
if(index == -1)
{
if(!m_sampleSourceId.isEmpty())
{
for(int i = 0; i < m_sampleSourceDevices.count(); i++)
{
if(m_sampleSourceDevices[i].m_sourceId == m_sampleSourceId)
{
index = i;
break;
}
}
}
if(index == -1) {
if(index == -1)
{
if(m_sampleSourceDevices.count() > 0)
{
index = 0;
}
}
}
if(index == -1)
return -1;
m_sampleSourceName = m_sampleSourceDevices[index].m_sourceName;
qDebug() << "m_sampleSource at index " << index << " is " << m_sampleSourceName.toStdString().c_str();
m_sampleSourcePluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceName, m_sampleSourceDevices[index].m_address);
if(index == -1)
{
return -1;
}
m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId;
m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial;
m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence;
qDebug() << "m_sampleSource at index " << index
<< " id: " << m_sampleSourceId.toStdString().c_str()
<< " ser: " << m_sampleSourceSerial.toStdString().c_str()
<< " seq: " << m_sampleSourceSequence;
m_sampleSourcePluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceId,
m_sampleSourceSerial,
m_sampleSourceSequence);
return index;
}
int PluginManager::selectSampleSource(const QString& source)
int PluginManager::selectFirstSampleSource(const QString& sourceId)
{
qDebug() << "PluginManager::selectSampleSource by name: " << source.toStdString().c_str();
qDebug() << "PluginManager::selectFirstSampleSource by id: " << sourceId.toStdString().c_str();
int index = -1;
@ -301,27 +331,48 @@ int PluginManager::selectSampleSource(const QString& source)
m_dspEngine->setSource(NULL);
m_sampleSourcePluginGUI->destroy();
m_sampleSourcePluginGUI = NULL;
m_sampleSourceName.clear();
m_sampleSourceId.clear();
}
qDebug("finding sample source [%s]", qPrintable(source));
for(int i = 0; i < m_sampleSourceDevices.count(); i++) {
qDebug("*** %s vs %s", qPrintable(m_sampleSourceDevices[i].m_sourceName), qPrintable(source));
if(m_sampleSourceDevices[i].m_sourceName == source) {
qDebug("finding first sample source [%s]", qPrintable(sourceId));
for(int i = 0; i < m_sampleSourceDevices.count(); i++)
{
qDebug("*** %s vs %s", qPrintable(m_sampleSourceDevices[i].m_sourceId), qPrintable(sourceId));
if(m_sampleSourceDevices[i].m_sourceId == sourceId)
{
index = i;
break;
}
}
if(index == -1) {
if(m_sampleSourceDevices.count() > 0)
index = 0;
}
if(index == -1)
return -1;
m_sampleSourceName = m_sampleSourceDevices[index].m_sourceName;
qDebug() << "m_sampleSource at index " << index << " is " << m_sampleSourceName.toStdString().c_str();
m_sampleSourcePluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceName, m_sampleSourceDevices[index].m_address);
if(index == -1)
{
if(m_sampleSourceDevices.count() > 0)
{
index = 0;
}
}
if(index == -1)
{
return -1;
}
m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId;
m_sampleSourceSerial = m_sampleSourceDevices[index].m_sourceSerial;
m_sampleSourceSequence = m_sampleSourceDevices[index].m_sourceSequence;
qDebug() << "m_sampleSource at index " << index
<< " id: " << m_sampleSourceId.toStdString().c_str()
<< " ser: " << m_sampleSourceSerial.toStdString().c_str()
<< " seq: " << m_sampleSourceSequence;
m_sampleSourcePluginGUI = m_sampleSourceDevices[index].m_plugin->createSampleSourcePluginGUI(m_sampleSourceId,
m_sampleSourceSerial,
m_sampleSourceSequence);
return index;
}

View File

@ -17,13 +17,13 @@ void Preset::resetToDefaults()
m_layout.clear();
m_spectrumConfig.clear();
m_channelConfigs.clear();
m_source.clear();
m_sourceId.clear();
m_sourceConfig.clear();
}
QByteArray Preset::serialize() const
{
qDebug() << "Preset::serialize (" << this->getSource().toStdString().c_str() << ")";
qDebug() << "Preset::serialize (" << this->getSourceId().toStdString().c_str() << ")";
SimpleSerializer s(1);
s.writeString(1, m_group);
@ -31,7 +31,7 @@ QByteArray Preset::serialize() const
s.writeU64(3, m_centerFrequency);
s.writeBlob(4, m_layout);
s.writeBlob(5, m_spectrumConfig);
s.writeString(6, m_source);
s.writeString(6, m_sourceId);
s.writeBlob(7, m_sourceConfig);
s.writeS32(200, m_channelConfigs.size());
@ -48,7 +48,7 @@ QByteArray Preset::serialize() const
bool Preset::deserialize(const QByteArray& data)
{
qDebug() << "Preset::deserialize (" << this->getSource().toStdString().c_str() << ")";
qDebug() << "Preset::deserialize (" << this->getSourceId().toStdString().c_str() << ")";
SimpleDeserializer d(data);
if(!d.isValid()) {
@ -62,7 +62,7 @@ bool Preset::deserialize(const QByteArray& data)
d.readU64(3, &m_centerFrequency, 0);
d.readBlob(4, &m_layout);
d.readBlob(5, &m_spectrumConfig);
d.readString(6, &m_source);
d.readString(6, &m_sourceId);
d.readBlob(7, &m_sourceConfig);
qDebug() << "Preset::deserialize: m_group: " << m_group.toStdString().c_str();