1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

Use common code for creating and processing device and channel Ids.

This commit is contained in:
srcejon 2023-12-05 12:32:53 +00:00
parent 070f8077b2
commit d989561df5
10 changed files with 173 additions and 73 deletions

View File

@ -577,12 +577,7 @@ void AircraftModel::findOnMap(int index)
// Get list of frequeny scanners to use in menu // Get list of frequeny scanners to use in menu
QStringList AirportModel::getFreqScanners() const QStringList AirportModel::getFreqScanners() const
{ {
QStringList list; return MainCore::instance()->getChannelIds("sdrangel.channel.freqscanner");
std::vector<ChannelAPI*> channels = MainCore::instance()->getChannels("sdrangel.channel.freqscanner");
for (const auto channel : channels) {
list.append(QString("R%1:%2").arg(channel->getDeviceSetIndex()).arg(channel->getIndexInDeviceSet()));
}
return list;
} }
// Send airport frequencies to frequency scanner with given id (Rn:n) // Send airport frequencies to frequency scanner with given id (Rn:n)
@ -592,14 +587,10 @@ void AirportModel::sendToFreqScanner(int index, const QString& id)
return; return;
} }
const AirportInformation *airport = m_airports[index]; const AirportInformation *airport = m_airports[index];
unsigned int deviceSet, channelIndex;
const QRegularExpression re("R([0-9]+):([0-9]+)"); if (MainCore::getDeviceAndChannelIndexFromId(id, deviceSet, channelIndex))
QRegularExpressionMatch match = re.match(id);
if (match.hasMatch())
{ {
int deviceSet = match.capturedTexts()[1].toInt();
int channelIndex = match.capturedTexts()[2].toInt();
QJsonArray array; QJsonArray array;
for (const auto airportFrequency : airport->m_frequencies) for (const auto airportFrequency : airport->m_frequencies)
{ {
@ -867,12 +858,10 @@ bool NavAidModel::setData(const QModelIndex &index, const QVariant& value, int r
// Set selected AM Demod to the given frequency (used to tune to ATC selected from airports on map) // Set selected AM Demod to the given frequency (used to tune to ATC selected from airports on map)
bool ADSBDemodGUI::setFrequency(qint64 targetFrequencyHz) bool ADSBDemodGUI::setFrequency(qint64 targetFrequencyHz)
{ {
const QRegularExpression re("R([0-9]+):([0-9]+)"); unsigned int deviceSet, channelIndex;
QRegularExpressionMatch match = re.match(m_settings.m_amDemod);
if (match.hasMatch()) if (MainCore::getDeviceAndChannelIndexFromId(m_settings.m_amDemod, deviceSet, channelIndex))
{ {
int deviceSet = match.capturedTexts()[1].toInt();
int channelIndex = match.capturedTexts()[2].toInt();
const int halfChannelBW = 20000/2; const int halfChannelBW = 20000/2;
int dcOffset = halfChannelBW; int dcOffset = halfChannelBW;

View File

@ -23,7 +23,6 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QBuffer> #include <QBuffer>
#include <QThread> #include <QThread>
#include <QRegExp>
#include <stdio.h> #include <stdio.h>
#include <complex.h> #include <complex.h>
@ -67,8 +66,8 @@ FreqScanner::FreqScanner(DeviceAPI *deviceAPI) :
m_basebandSink(nullptr), m_basebandSink(nullptr),
m_running(false), m_running(false),
m_basebandSampleRate(0), m_basebandSampleRate(0),
m_scanDeviceSetIndex(-1), m_scanDeviceSetIndex(0),
m_scanChannelIndex(-1), m_scanChannelIndex(0),
m_state(IDLE), m_state(IDLE),
m_timeoutTimer(this) m_timeoutTimer(this)
{ {
@ -670,28 +669,19 @@ void FreqScanner::muteAll(const FreqScannerSettings& settings)
} }
} }
const QRegExp re("R([0-9]+):([0-9]+)");
for (const auto& channel : channels) for (const auto& channel : channels)
{ {
if (re.indexIn(channel) >= 0) unsigned int deviceSetIndex, channelIndex;
{
int deviceSetIndex = re.capturedTexts()[1].toInt(); if (MainCore::getDeviceAndChannelIndexFromId(channel, deviceSetIndex, channelIndex)) {
int scanChannelIndex = re.capturedTexts()[2].toInt(); ChannelWebAPIUtils::setAudioMute(deviceSetIndex, channelIndex, true);
ChannelWebAPIUtils::setAudioMute(deviceSetIndex, scanChannelIndex, true);
} }
} }
} }
void FreqScanner::applyChannelSetting(const QString& channel) void FreqScanner::applyChannelSetting(const QString& channel)
{ {
const QRegExp re("R([0-9]+):([0-9]+)"); if (!MainCore::getDeviceAndChannelIndexFromId(channel, m_scanDeviceSetIndex, m_scanChannelIndex)) {
if (re.indexIn(channel) >= 0)
{
m_scanDeviceSetIndex = re.capturedTexts()[1].toInt();
m_scanChannelIndex = re.capturedTexts()[2].toInt();
}
else
{
qDebug() << "FreqScanner::applySettings: Failed to parse channel" << channel; qDebug() << "FreqScanner::applySettings: Failed to parse channel" << channel;
} }
} }

View File

@ -370,8 +370,8 @@ private:
QHash<ChannelAPI*, FreqScannerSettings::AvailableChannel> m_availableChannels; QHash<ChannelAPI*, FreqScannerSettings::AvailableChannel> m_availableChannels;
int m_scanDeviceSetIndex; unsigned int m_scanDeviceSetIndex;
int m_scanChannelIndex; unsigned int m_scanChannelIndex;
qint64 m_activeFrequency; qint64 m_activeFrequency;
QDateTime m_minFFTStartTime; QDateTime m_minFFTStartTime;
int m_scannerSampleRate; int m_scannerSampleRate;

View File

@ -21,7 +21,6 @@
#include <QMenu> #include <QMenu>
#include <QTableWidget> #include <QTableWidget>
#include <QTableWidgetItem> #include <QTableWidgetItem>
#include <QRegExp>
#include <QComboBox> #include <QComboBox>
#include "device/deviceset.h" #include "device/deviceset.h"
@ -41,6 +40,7 @@
#include "gui/int64delegate.h" #include "gui/int64delegate.h"
#include "gui/glspectrum.h" #include "gui/glspectrum.h"
#include "channel/channelwebapiutils.h" #include "channel/channelwebapiutils.h"
#include "maincore.h"
#include "freqscannergui.h" #include "freqscannergui.h"
#include "freqscanneraddrangedialog.h" #include "freqscanneraddrangedialog.h"
@ -935,15 +935,13 @@ void FreqScannerGUI::table_customContextMenuRequested(QPoint pos)
qint64 frequency = ui->table->item(row, COL_FREQUENCY)->text().toLongLong(); qint64 frequency = ui->table->item(row, COL_FREQUENCY)->text().toLongLong();
FreqScannerSettings::FrequencySettings *frequencySettings = m_settings.getFrequencySettings(frequency); FreqScannerSettings::FrequencySettings *frequencySettings = m_settings.getFrequencySettings(frequency);
QString channel = m_settings.getChannel(frequencySettings); QString channel = m_settings.getChannel(frequencySettings);
const QRegExp re("R([0-9]+):([0-9]+)"); unsigned int scanDeviceSetIndex, scanChannelIndex;
if (re.indexIn(channel) >= 0)
{
int scanDeviceSetIndex = re.capturedTexts()[1].toInt();
int scanChannelIndex = re.capturedTexts()[2].toInt();
if (MainCore::getDeviceAndChannelIndexFromId(channel, scanDeviceSetIndex, scanChannelIndex))
{
ButtonSwitch *startStop = ui->startStop; ButtonSwitch *startStop = ui->startStop;
QAction* findChannelMapAction = new QAction(QString("Tune R%1:%2 to %3").arg(scanDeviceSetIndex).arg(scanChannelIndex).arg(frequency), tableContextMenu); QAction* findChannelMapAction = new QAction(QString("Tune %1 to %2").arg(channel).arg(frequency), tableContextMenu);
connect(findChannelMapAction, &QAction::triggered, this, [this, scanDeviceSetIndex, scanChannelIndex, frequency, startStop]()->void { connect(findChannelMapAction, &QAction::triggered, this, [this, scanDeviceSetIndex, scanChannelIndex, frequency, startStop]()->void {
// Stop scanning // Stop scanning

View File

@ -24,7 +24,6 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QBuffer> #include <QBuffer>
#include <QThread> #include <QThread>
#include <QRegExp>
#include <QProcess> #include <QProcess>
#include <stdio.h> #include <stdio.h>
@ -479,12 +478,8 @@ void RadioAstronomy::sweepStart()
m_sweep1 = m_sweep1Start; m_sweep1 = m_sweep1Start;
m_sweep2 = m_settings.m_sweep2Start; m_sweep2 = m_settings.m_sweep2Start;
const QRegExp re("F([0-9]+):([0-9]+)"); if (MainCore::getFeatureIndexFromId(m_settings.m_starTracker, m_starTrackerFeatureSetIndex, m_starTrackerFeatureIndex))
if (re.indexIn(m_settings.m_starTracker) >= 0)
{ {
m_starTrackerFeatureSetIndex = re.capturedTexts()[1].toInt();
m_starTrackerFeatureIndex = re.capturedTexts()[2].toInt();
if (m_settings.m_sweepType == RadioAstronomySettings::SWP_AZEL) { if (m_settings.m_sweepType == RadioAstronomySettings::SWP_AZEL) {
ChannelWebAPIUtils::patchFeatureSetting(m_starTrackerFeatureSetIndex, m_starTrackerFeatureIndex, "target", "Custom Az/El"); ChannelWebAPIUtils::patchFeatureSetting(m_starTrackerFeatureSetIndex, m_starTrackerFeatureIndex, "target", "Custom Az/El");
} else if (m_settings.m_sweepType == RadioAstronomySettings::SWP_LB) { } else if (m_settings.m_sweepType == RadioAstronomySettings::SWP_LB) {
@ -499,11 +494,8 @@ void RadioAstronomy::sweepStart()
sweep2(); sweep2();
callOnStartTime(&RadioAstronomy::sweep1); callOnStartTime(&RadioAstronomy::sweep1);
} }
else if (re.indexIn(m_settings.m_rotator) >= 0) else if (MainCore::getFeatureIndexFromId(m_settings.m_rotator, m_rotatorFeatureSetIndex, m_rotatorFeatureIndex))
{ {
m_rotatorFeatureSetIndex = re.capturedTexts()[1].toInt();
m_rotatorFeatureIndex = re.capturedTexts()[2].toInt();
sweep2(); sweep2();
callOnStartTime(&RadioAstronomy::sweep1); callOnStartTime(&RadioAstronomy::sweep1);
} }

View File

@ -454,10 +454,10 @@ private:
QNetworkAccessManager *m_networkManager; QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest; QNetworkRequest m_networkRequest;
int m_starTrackerFeatureSetIndex; unsigned int m_starTrackerFeatureSetIndex;
int m_starTrackerFeatureIndex; unsigned int m_starTrackerFeatureIndex;
int m_rotatorFeatureSetIndex; unsigned int m_rotatorFeatureSetIndex;
int m_rotatorFeatureIndex; unsigned int m_rotatorFeatureIndex;
float m_sweep1; // Current sweep position float m_sweep1; // Current sweep position
float m_sweep2; float m_sweep2;

View File

@ -2744,12 +2744,10 @@ void RadioAstronomyGUI::on_rotator_currentTextChanged(const QString& text)
void RadioAstronomyGUI::setColumnPrecisionFromRotator() void RadioAstronomyGUI::setColumnPrecisionFromRotator()
{ {
// Match rotator precision // Match rotator precision
const QRegExp re("F([0-9]+):([0-9]+)"); unsigned int featureSetIndex, featureIndex;
if (re.indexIn(m_settings.m_rotator) >= 0)
{
int featureSetIndex = re.capturedTexts()[1].toInt();
int featureIndex = re.capturedTexts()[2].toInt();
if (MainCore::getFeatureIndexFromId(m_settings.m_rotator, featureSetIndex, featureIndex))
{
int precision = 0; int precision = 0;
if (ChannelWebAPIUtils::getFeatureSetting(featureSetIndex, featureIndex, "precision", precision)) if (ChannelWebAPIUtils::getFeatureSetting(featureSetIndex, featureIndex, "precision", precision))
{ {
@ -4687,12 +4685,10 @@ void RadioAstronomyGUI::addFFT(FFTMeasurement *fft, bool skipCalcs)
void RadioAstronomyGUI::getRotatorData(FFTMeasurement *fft) void RadioAstronomyGUI::getRotatorData(FFTMeasurement *fft)
{ {
const QRegExp re("F([0-9]+):([0-9]+)"); unsigned int rotatorFeatureSetIndex, rotatorFeatureIndex;
if (re.indexIn(m_settings.m_rotator) >= 0)
{
int rotatorFeatureSetIndex = re.capturedTexts()[1].toInt();
int rotatorFeatureIndex = re.capturedTexts()[2].toInt();
if (MainCore::getFeatureIndexFromId(m_settings.m_rotator, rotatorFeatureSetIndex, rotatorFeatureIndex))
{
SWGSDRangel::SWGFeatureReport featureReport; SWGSDRangel::SWGFeatureReport featureReport;
double value; double value;
qDebug() << m_settings.m_rotator << rotatorFeatureSetIndex << rotatorFeatureIndex; qDebug() << m_settings.m_rotator << rotatorFeatureSetIndex << rotatorFeatureIndex;

View File

@ -501,13 +501,10 @@ void StarTrackerWorker::update()
{ {
// Get Az/El from Satellite Tracker // Get Az/El from Satellite Tracker
double azimuth, elevation; double azimuth, elevation;
unsigned int satelliteTrackerFeatureSetIndex,satelliteTrackerFeatureIndex;
const QRegExp re("F([0-9]+):([0-9]+)"); if (MainCore::getFeatureIndexFromId(m_settings.m_target, satelliteTrackerFeatureSetIndex, satelliteTrackerFeatureIndex))
if (re.indexIn(m_settings.m_target) >= 0)
{ {
int satelliteTrackerFeatureSetIndex = re.capturedTexts()[1].toInt();
int satelliteTrackerFeatureIndex = re.capturedTexts()[2].toInt();
if (ChannelWebAPIUtils::getFeatureReportValue(satelliteTrackerFeatureSetIndex, satelliteTrackerFeatureIndex, "targetAzimuth", azimuth) if (ChannelWebAPIUtils::getFeatureReportValue(satelliteTrackerFeatureSetIndex, satelliteTrackerFeatureIndex, "targetAzimuth", azimuth)
&& ChannelWebAPIUtils::getFeatureReportValue(satelliteTrackerFeatureSetIndex, satelliteTrackerFeatureIndex, "targetElevation", elevation)) && ChannelWebAPIUtils::getFeatureReportValue(satelliteTrackerFeatureSetIndex, satelliteTrackerFeatureIndex, "targetElevation", elevation))
{ {

View File

@ -435,6 +435,121 @@ void MainCore::updateWakeLock()
} }
#endif #endif
QChar MainCore::getDeviceSetTypeId(const DeviceSet* deviceSet)
{
if (deviceSet->m_deviceMIMOEngine) {
return 'M';
} else if (deviceSet->m_deviceSinkEngine) {
return 'T';
} else if (deviceSet->m_deviceSourceEngine) {
return 'R';
} else {
return 'X'; // Unknown
}
}
QString MainCore::getDeviceSetId(const DeviceSet* deviceSet)
{
QChar type = getDeviceSetTypeId(deviceSet);
return QString("%1%2").arg(type).arg(deviceSet->getIndex());
}
QString MainCore::getChannelId(const ChannelAPI* channel)
{
std::vector<DeviceSet*> deviceSets = getDeviceSets();
DeviceSet* deviceSet = deviceSets[channel->getDeviceSetIndex()];
QString deviceSetId = getDeviceSetId(deviceSet);
int index = channel->getIndexInDeviceSet();
// FIXME: if (deviceSet->m_deviceMIMOEngine) {
// we should append stream index. E.g. "M0:0.0" However, only ChannelGUI seems to know what it is
return QString("%1:%2").arg(deviceSetId).arg(index);
}
QStringList MainCore::getDeviceSetIds(bool rx, bool tx, bool mimo)
{
QStringList list;
std::vector<DeviceSet*> deviceSets = getDeviceSets();
for (const auto deviceSet : deviceSets)
{
DSPDeviceSourceEngine *deviceSourceEngine = deviceSet->m_deviceSourceEngine;
DSPDeviceSinkEngine *deviceSinkEngine = deviceSet->m_deviceSinkEngine;
DSPDeviceMIMOEngine *deviceMIMOEngine = deviceSet->m_deviceMIMOEngine;
if (((deviceSourceEngine != nullptr) && rx)
|| ((deviceSinkEngine != nullptr) && tx)
|| ((deviceMIMOEngine != nullptr) && mimo))
{
list.append(getDeviceSetId(deviceSet));
}
}
return list;
}
bool MainCore::getDeviceSetTypeFromId(const QString& deviceSetId, QChar &type)
{
if (!deviceSetId.isEmpty())
{
type = deviceSetId[0];
return (type == 'R') || (type == 'T') || (type == 'M');
}
else
{
return false;
}
}
bool MainCore::getDeviceSetIndexFromId(const QString& deviceSetId, unsigned int &deviceSetIndex)
{
const QRegularExpression re("[RTM]([0-9]+)");
QRegularExpressionMatch match = re.match(deviceSetId);
if (match.hasMatch())
{
deviceSetIndex = match.capturedTexts()[1].toInt();
return true;
}
else
{
return false;
}
}
bool MainCore::getDeviceAndChannelIndexFromId(const QString& channelId, unsigned int &deviceSetIndex, unsigned int &channelIndex)
{
const QRegularExpression re("[RTM]([0-9]+):([0-9]+)");
QRegularExpressionMatch match = re.match(channelId);
if (match.hasMatch())
{
deviceSetIndex = match.capturedTexts()[1].toInt();
channelIndex = match.capturedTexts()[2].toInt();
return true;
}
else
{
return false;
}
}
bool MainCore::getFeatureIndexFromId(const QString& featureId, unsigned int &featureSetIndex, unsigned int &featureIndex)
{
const QRegularExpression re("[F]([0-9]+):([0-9]+)");
QRegularExpressionMatch match = re.match(featureId);
if (match.hasMatch())
{
featureSetIndex = match.capturedTexts()[1].toInt();
featureIndex = match.capturedTexts()[2].toInt();
return true;
}
else
{
return false;
}
}
std::vector<ChannelAPI*> MainCore::getChannels(const QString& uri) std::vector<ChannelAPI*> MainCore::getChannels(const QString& uri)
{ {
std::vector<ChannelAPI*> channels; std::vector<ChannelAPI*> channels;
@ -452,3 +567,15 @@ std::vector<ChannelAPI*> MainCore::getChannels(const QString& uri)
return channels; return channels;
} }
QStringList MainCore::getChannelIds(const QString& uri)
{
QStringList list;
std::vector<ChannelAPI*> channels = getChannels(uri);
for (const auto channel : channels) {
list.append(getChannelId(channel));
}
return list;
}

View File

@ -857,7 +857,6 @@ public:
PluginManager *getPluginManager() const { return m_pluginManager; } PluginManager *getPluginManager() const { return m_pluginManager; }
std::vector<DeviceSet*>& getDeviceSets() { return m_deviceSets; } std::vector<DeviceSet*>& getDeviceSets() { return m_deviceSets; }
std::vector<FeatureSet*>& getFeatureeSets() { return m_featureSets; } std::vector<FeatureSet*>& getFeatureeSets() { return m_featureSets; }
std::vector<ChannelAPI*> getChannels(const QString& uri); //!< Get all channels from any device set with the given URI
void setLoggingOptions(); void setLoggingOptions();
DeviceAPI *getDevice(unsigned int deviceSetIndex); DeviceAPI *getDevice(unsigned int deviceSetIndex);
ChannelAPI *getChannel(unsigned int deviceSetIndex, int channelIndex); ChannelAPI *getChannel(unsigned int deviceSetIndex, int channelIndex);
@ -887,6 +886,18 @@ public:
// Position // Position
const QGeoPositionInfo& getPosition() const; const QGeoPositionInfo& getPosition() const;
// Ids
QChar getDeviceSetTypeId(const DeviceSet* deviceSet); //!< Get Type Id (E.g. 'R', 'T' or 'M') for the given device set
QString getDeviceSetId(const DeviceSet* deviceSet); //!< Get Id (E.g. "R2") for the given device set
QString getChannelId(const ChannelAPI* channel); //!< Get Id (E.g. "R1:2") for the given channel
static bool getDeviceSetTypeFromId(const QString& deviceSetId, QChar &type); //!< "R1" -> 'R'
static bool getDeviceSetIndexFromId(const QString& deviceSetId, unsigned int &deviceSetIndex); //!< "R1" -> 1
static bool getDeviceAndChannelIndexFromId(const QString& channelId, unsigned int &deviceSetIndex, unsigned int &channelIndex); //!< "R3:4" -> 3, 4
static bool getFeatureIndexFromId(const QString& featureId, unsigned int &featureSetIndex, unsigned int &featureIndex); //!< "F0:2" -> 0, 2
QStringList getDeviceSetIds(bool rx, bool tx, bool mimo); //!< Get list of all device set Ids. E.g: {"R0", "R1", "T1", "M2"}
std::vector<ChannelAPI*> getChannels(const QString& uri); //!< Get all channels from any device set with the given URI
QStringList getChannelIds(const QString& uri); //!< Get all Ids for channels from any device set with the given URI. E.g. "sdrangel.channel.xyzdemod" -> {"R2:1", "M0:0.1"}
friend class MainServer; friend class MainServer;
friend class MainWindow; friend class MainWindow;
friend class WebAPIAdapter; friend class WebAPIAdapter;