1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-03 15:31:15 -05:00
sdrangel/plugins/feature/satellitetracker/satellitedevicesettingsgui.cpp

290 lines
12 KiB
C++
Raw Normal View History

2021-02-26 15:25:48 -05:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021 Jon Beniston, M7RCE //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QDebug>
#include <QFormLayout>
2021-02-26 15:25:48 -05:00
#include <QSizePolicy>
#include "satellitedevicesettingsgui.h"
#include "device/deviceset.h"
#include "settings/mainsettings.h"
#include "maincore.h"
#include "util/messagequeue.h"
#include "plugin/pluginmanager.h"
#include "plugin/pluginapi.h"
SatelliteDeviceSettingsGUI::SatelliteDeviceSettingsGUI(SatelliteTrackerSettings::SatelliteDeviceSettings *devSettings,
QTabWidget *tab, QWidget *parent) :
QWidget(parent),
m_tab(tab)
2021-02-26 15:25:48 -05:00
{
m_devSettings = devSettings;
QFormLayout *formLayout = new QFormLayout();
2021-02-26 15:25:48 -05:00
// Device set
m_deviceSetWidget = new QComboBox();
m_deviceSetWidget->setEditable(true);
m_deviceSetWidget->setToolTip("Device set to control");
formLayout->addRow("Device set", m_deviceSetWidget);
2021-02-26 15:25:48 -05:00
addDeviceSets();
int devSetIdx = m_deviceSetWidget->findText(devSettings->m_deviceSet);
if (devSetIdx != -1)
{
2021-02-26 15:25:48 -05:00
m_deviceSetWidget->setCurrentIndex(devSetIdx);
}
2021-02-26 15:25:48 -05:00
else
{
m_deviceSetWidget->addItem(devSettings->m_deviceSet);
m_deviceSetWidget->setCurrentIndex(m_deviceSetWidget->count() - 1);
}
// Preset
m_presetWidget = new QComboBox();
m_presetWidget->setEditable(false);
m_presetWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_presetWidget->setToolTip("Preset to load on AOS");
formLayout->addRow("Preset", m_presetWidget);
2021-02-26 15:25:48 -05:00
addPresets(devSettings->m_deviceSet);
const MainSettings& mainSettings = MainCore::instance()->getSettings();
if (!devSettings->m_deviceSet.isEmpty())
{
int count = mainSettings.getPresetCount();
int idx = 0;
for (int i = 0; i < count; i++)
{
const Preset *preset = mainSettings.getPreset(i);
if ( ((preset->isSourcePreset() && (devSettings->m_deviceSet[0] == "R")))
|| ((preset->isSinkPreset() && (devSettings->m_deviceSet[0] == "T")))
|| ((preset->isMIMOPreset() && (devSettings->m_deviceSet[0] == "M"))))
{
if ( (devSettings->m_presetGroup == preset->getGroup())
&& (devSettings->m_presetFrequency == preset->getCenterFrequency())
&& (devSettings->m_presetDescription == preset->getDescription()))
{
m_presetWidget->setCurrentIndex(idx);
break;
}
idx++;
}
}
}
// Doppler
m_dopplerWidget = new QListView();
2021-02-26 15:25:48 -05:00
m_dopplerWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_dopplerWidget->setToolTip("Channels that will have Doppler correction applied");
formLayout->addRow("Doppler correction", m_dopplerWidget);
2021-02-26 15:25:48 -05:00
m_dopplerWidget->setModel(&m_dopplerModel);
addChannels();
for (int i = 0; i < devSettings->m_doppler.size(); i++)
{
int idx = devSettings->m_doppler[i];
if (idx < m_dopplerItems.size()) {
m_dopplerItems[idx]->setData(Qt::Checked, Qt::CheckStateRole);
} else {
qDebug() << "SatelliteDeviceSettingsGUI - Doppler index " << idx << " out of range: " << m_dopplerItems.size();
}
}
2021-02-26 15:25:48 -05:00
// Start on AOS
m_startOnAOSWidget = new QCheckBox();
m_startOnAOSWidget->setChecked(devSettings->m_startOnAOS);
m_startOnAOSWidget->setToolTip("Start acquisition on AOS");
formLayout->addRow("Start acquisition on AOS", m_startOnAOSWidget);
2021-02-26 15:25:48 -05:00
// Stop on AOS
m_stopOnLOSWidget = new QCheckBox();
m_stopOnLOSWidget->setChecked(devSettings->m_stopOnLOS);
m_stopOnLOSWidget->setToolTip("Stop acquisition on LOS");
formLayout->addRow("Stop acquisition on LOS", m_stopOnLOSWidget);
2021-02-26 15:25:48 -05:00
// Start file sink
m_startStopFileSinkWidget = new QCheckBox();
m_startStopFileSinkWidget->setChecked(devSettings->m_startStopFileSink);
m_startStopFileSinkWidget->setToolTip("Start file sinks recording on AOS and stop recording on LOS");
formLayout->addRow("Start/stop file sinks on AOS/LOS", m_startStopFileSinkWidget);
2021-02-26 15:25:48 -05:00
// Frequency override
m_frequencyWidget = new QLineEdit();
m_frequencyWidget->setToolTip("Override the center frequency in the preset with a value specified here in MHz.\nThis allows a single preset to be shared between different satellites that differ only in frequency.");
// FIXME: Set mask for numeric or blank
if (devSettings->m_frequency != 0) {
m_frequencyWidget->setText(QString("%1").arg(devSettings->m_frequency/1000000.0, 0, 'f', 3, QLatin1Char(' ')));
}
formLayout->addRow("Override preset frequency (MHz)", m_frequencyWidget);
2021-02-26 15:25:48 -05:00
// AOS command
m_aosCommandWidget = new QLineEdit();
m_aosCommandWidget->setText(devSettings->m_aosCommand);
m_aosCommandWidget->setToolTip("Command to execute on AOS");
formLayout->addRow("AOS command", m_aosCommandWidget);
2021-02-26 15:25:48 -05:00
// LOS command
m_losCommandWidget = new QLineEdit();
m_losCommandWidget->setText(devSettings->m_losCommand);
m_losCommandWidget->setToolTip("Command to execute on LOS");
formLayout->addRow("LOS command", m_losCommandWidget);
2021-02-26 15:25:48 -05:00
setLayout(formLayout);
2021-02-26 15:25:48 -05:00
connect(m_deviceSetWidget, SIGNAL(currentTextChanged(const QString &)), this, SLOT(on_m_deviceSetWidget_currentTextChanged(const QString &)));
connect(m_presetWidget, SIGNAL(currentIndexChanged(int)), this, SLOT(on_m_presetWidget_currentIndexChanged(int)));
}
// Add available devicesets to the combobox
void SatelliteDeviceSettingsGUI::addDeviceSets()
{
MainCore *mainCore = MainCore::instance();
std::vector<DeviceSet*>& deviceSets = mainCore->getDeviceSets();
std::vector<DeviceSet*>::const_iterator it = deviceSets.begin();
for (unsigned int deviceIndex = 0; it != deviceSets.end(); ++it, deviceIndex++)
{
DSPDeviceSourceEngine *deviceSourceEngine = (*it)->m_deviceSourceEngine;
DSPDeviceSinkEngine *deviceSinkEngine = (*it)->m_deviceSinkEngine;
if (deviceSourceEngine) {
m_deviceSetWidget->addItem(QString("R%1").arg(deviceIndex), deviceIndex);
} else if (deviceSinkEngine) {
m_deviceSetWidget->addItem(QString("T%1").arg(deviceIndex), deviceIndex);
}
}
}
// Add all available presets for a deviceset to the combobox
void SatelliteDeviceSettingsGUI::addPresets(const QString& deviceSet)
{
m_presetWidget->clear();
const MainSettings& mainSettings = MainCore::instance()->getSettings();
int count = mainSettings.getPresetCount();
m_currentPresets = deviceSet[0];
for (int i = 0; i < count; i++)
{
const Preset *preset = mainSettings.getPreset(i);
if ( ((preset->isSourcePreset() && (m_currentPresets == "R")))
|| ((preset->isSinkPreset() && (m_currentPresets == "T")))
|| ((preset->isMIMOPreset() && (m_currentPresets == "M"))))
{
m_presetWidget->addItem(QString("%1: %2 - %3")
.arg(preset->getGroup())
.arg(preset->getCenterFrequency()/1000000.0, 0, 'f', 3)
.arg(preset->getDescription()));
}
}
}
const Preset* SatelliteDeviceSettingsGUI::getSelectedPreset()
{
int listIdx = m_presetWidget->currentIndex();
const MainSettings& mainSettings = MainCore::instance()->getSettings();
int count = mainSettings.getPresetCount();
int presetIdx = 0;
for (int i = 0; i < count; i++)
{
const Preset *preset = mainSettings.getPreset(i);
if ( ((preset->isSourcePreset() && (m_currentPresets == "R")))
|| ((preset->isSinkPreset() && (m_currentPresets == "T")))
|| ((preset->isMIMOPreset() && (m_currentPresets == "M"))))
{
if (listIdx == presetIdx) {
2021-02-26 15:25:48 -05:00
return preset;
}
2021-02-26 15:25:48 -05:00
presetIdx++;
}
}
return nullptr;
}
// Add checkable list of channels from a preset to the combobox
void SatelliteDeviceSettingsGUI::addChannels()
{
m_dopplerModel.clear();
m_dopplerItems.clear();
const PluginManager *pluginManager = MainCore::instance()->getPluginManager();
const Preset* preset = getSelectedPreset();
if (preset != nullptr)
{
int channels = preset->getChannelCount();
for (int i = 0; i < channels; i++)
{
const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i);
QStandardItem *item = new QStandardItem();
item->setText(pluginManager->uriToId(channelConfig.m_channelIdURI));
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item->setData(Qt::Unchecked, Qt::CheckStateRole);
m_dopplerModel.appendRow(item);
m_dopplerItems.append(item);
}
}
}
// Update preset list, to match type of deviceset entered
void SatelliteDeviceSettingsGUI::on_m_deviceSetWidget_currentTextChanged(const QString &text)
{
if (!text.isEmpty())
{
if (text[0] != m_currentPresets) {
2021-02-26 15:25:48 -05:00
addPresets(text[0]);
}
// Set name of tab to match
int currentTabIndex = m_tab->currentIndex();
m_tab->setTabText(currentTabIndex, text);
2021-02-26 15:25:48 -05:00
}
}
// Update doppler combo, to correspond to selected preset
void SatelliteDeviceSettingsGUI::on_m_presetWidget_currentIndexChanged(int index)
{
(void) index;
2021-02-26 15:25:48 -05:00
addChannels();
}
// Update devSettings with current GUI values
void SatelliteDeviceSettingsGUI::accept()
{
m_devSettings->m_deviceSet = m_deviceSetWidget->currentText();
const Preset* preset = getSelectedPreset();
if (preset != nullptr)
{
m_devSettings->m_presetGroup = preset->getGroup();
m_devSettings->m_presetFrequency = preset->getCenterFrequency();
m_devSettings->m_presetDescription = preset->getDescription();
}
else
{
m_devSettings->m_presetGroup = "";
m_devSettings->m_presetFrequency = 0;
m_devSettings->m_presetDescription = "";
}
m_devSettings->m_doppler.clear();
for (int i = 0; i < m_dopplerItems.size(); i++)
{
if (m_dopplerItems[i]->checkState() == Qt::Checked) {
2021-02-26 15:25:48 -05:00
m_devSettings->m_doppler.append(i);
}
2021-02-26 15:25:48 -05:00
}
m_devSettings->m_startOnAOS = m_startOnAOSWidget->isChecked();
m_devSettings->m_stopOnLOS = m_stopOnLOSWidget->isChecked();
m_devSettings->m_startStopFileSink = m_startStopFileSinkWidget->isChecked();
m_devSettings->m_frequency = (quint64)(m_frequencyWidget->text().toDouble() * 1000000.0);
m_devSettings->m_aosCommand = m_aosCommandWidget->text();
m_devSettings->m_losCommand = m_losCommandWidget->text();
2021-02-26 15:25:48 -05:00
}