From 00ca85c0bf59ec5e01ae987013fef460c32f8c3a Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 13 Jan 2019 22:09:45 +0100 Subject: [PATCH] On preset load match on serial or driver id for SoapySDR devices --- sdrbase/settings/preset.cpp | 78 +++++++++++++++++++++++++++++++++++-- sdrbase/settings/preset.h | 3 ++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/sdrbase/settings/preset.cpp b/sdrbase/settings/preset.cpp index ff9d16394..4a5fb98ec 100644 --- a/sdrbase/settings/preset.cpp +++ b/sdrbase/settings/preset.cpp @@ -201,6 +201,13 @@ const QByteArray* Preset::findBestDeviceConfig(const QString& sourceId, const QString& sourceSerial, int sourceSequence) const { + // Special case for SoapySDR based on serial (driver name) + if (sourceId == "sdrangel.samplesource.soapysdrinput") { + return findBestDeviceConfigSoapy(sourceId, sourceSerial); + } else if (sourceId == "sdrangel.samplesource.soapysdroutput") { + return findBestDeviceConfigSoapy(sourceId, sourceSerial); + } + DeviceeConfigs::const_iterator it = m_deviceConfigs.begin(); DeviceeConfigs::const_iterator itFirstOfKind = m_deviceConfigs.end(); DeviceeConfigs::const_iterator itMatchSequence = m_deviceConfigs.end(); @@ -239,12 +246,14 @@ const QByteArray* Preset::findBestDeviceConfig(const QString& sourceId, { if (itMatchSequence != m_deviceConfigs.end()) // match sequence ? { - qDebug("Preset::findBestSourceConfig: sequence matched: id: %s seq: %d", qPrintable(itMatchSequence->m_deviceId), itMatchSequence->m_deviceSequence); + qDebug("Preset::findBestSourceConfig: sequence matched: id: %s ser: %s seq: %d", + qPrintable(itMatchSequence->m_deviceId), qPrintable(itMatchSequence->m_deviceSerial), itMatchSequence->m_deviceSequence); return &(itMatchSequence->m_config); } else if (itFirstOfKind != m_deviceConfigs.end()) // match source type ? { - qDebug("Preset::findBestSourceConfig: first of kind matched: id: %s", qPrintable(itFirstOfKind->m_deviceId)); + qDebug("Preset::findBestSourceConfig: first of kind matched: id: %s ser: %s seq: %d", + qPrintable(itFirstOfKind->m_deviceId), qPrintable(itFirstOfKind->m_deviceSerial), itFirstOfKind->m_deviceSequence); return &(itFirstOfKind->m_config); } else // definitely not found ! @@ -255,7 +264,70 @@ const QByteArray* Preset::findBestDeviceConfig(const QString& sourceId, } else // exact match { - qDebug("Preset::findBestSourceConfig: serial matched (exact): id: %s ser: %s", qPrintable(it->m_deviceId), qPrintable(it->m_deviceSerial)); + qDebug("Preset::findBestSourceConfig: serial matched (exact): id: %s ser: %s", + qPrintable(it->m_deviceId), qPrintable(it->m_deviceSerial)); + return &(it->m_config); + } +} + +const QByteArray* Preset::findBestDeviceConfigSoapy(const QString& sourceId, const QString& sourceSerial) const +{ + QStringList sourceSerialPieces = sourceSerial.split("-"); + + if (sourceSerialPieces.size() == 0) { + return 0; // unable to process + } + + DeviceeConfigs::const_iterator it = m_deviceConfigs.begin(); + DeviceeConfigs::const_iterator itFirstOfKind = m_deviceConfigs.end(); + + for (; it != m_deviceConfigs.end(); ++it) + { + if (it->m_deviceId != sourceId) // skip non matching device + { + continue; + } + else if (it->m_deviceSerial == sourceSerial) // exact match + { + break; + } + else // try to find best match on driver id (first part of serial) + { + QStringList serialPieces = it->m_deviceSerial.split("-"); + + if (serialPieces.size() == 0) + { + continue; + } + else if (sourceSerialPieces[0] == serialPieces[0]) + { + if (itFirstOfKind == m_deviceConfigs.end()) + { + itFirstOfKind = it; + break; + } + } + } + } + + if (it == m_deviceConfigs.end()) // no exact match + { + if (itFirstOfKind == m_deviceConfigs.end()) + { + qDebug("Preset::findBestDeviceConfigSoapy: no match"); + return 0; + } + else + { + qDebug("Preset::findBestSourceConfig: first of kind matched: id: %s ser: %s seq: %d", + qPrintable(itFirstOfKind->m_deviceId), qPrintable(itFirstOfKind->m_deviceSerial), itFirstOfKind->m_deviceSequence); + return &(itFirstOfKind->m_config); + } + } + else // exact match + { + qDebug("Preset::findBestDeviceConfigSoapy: serial matched (exact): id: %s ser: %s seq: %d", + qPrintable(it->m_deviceId), qPrintable(it->m_deviceSerial), it->m_deviceSequence); return &(it->m_config); } } diff --git a/sdrbase/settings/preset.h b/sdrbase/settings/preset.h index 26be52469..2e47e7e00 100644 --- a/sdrbase/settings/preset.h +++ b/sdrbase/settings/preset.h @@ -127,6 +127,9 @@ protected: // screen and dock layout QByteArray m_layout; + +private: + const QByteArray* findBestDeviceConfigSoapy(const QString& sourceId, const QString& deviceSerial) const; }; Q_DECLARE_METATYPE(const Preset*);