Audio CAT SISO: implement CAT device and type in GUI

This commit is contained in:
f4exb 2023-06-05 01:06:12 +02:00
parent 7ae44d6e12
commit d02fe23263
9 changed files with 190 additions and 0 deletions

View File

@ -7,6 +7,7 @@ set(audiocatsiso_SOURCES
audiocatsisoplugin.cpp
audiocatsisosettings.cpp
audiocatsisowebapiadapter.cpp
audiocatsisohamlib.cpp
)
set(audiocatsiso_HEADERS
@ -16,6 +17,7 @@ set(audiocatsiso_HEADERS
audiocatsisoplugin.h
audiocatsisosettings.h
audiocatsisowebapiadapter.h
audiocatsisohamlib.h
)
include_directories(

View File

@ -34,6 +34,7 @@
#include "dsp/devicesamplesource.h"
#include "dsp/devicesamplesink.h"
#include "device/deviceapi.h"
#include "util/serialutil.h"
#include "audiocatsiso.h"
#include "audiocatinputworker.h"
@ -81,6 +82,8 @@ AudioCATSISO::AudioCATSISO(DeviceAPI *deviceAPI) :
this,
&AudioCATSISO::networkManagerFinished
);
listComPorts();
}
AudioCATSISO::~AudioCATSISO()
@ -491,6 +494,17 @@ void AudioCATSISO::applySettings(const AudioCATSISOSettings& settings, const QLi
}
}
void AudioCATSISO::listComPorts()
{
m_comPorts.clear();
std::vector<std::string> comPorts;
SerialUtil::getComPorts(comPorts, "tty(USB|ACM)[0-9]+"); // regex is for Linux only
for (std::vector<std::string>::const_iterator it = comPorts.begin(); it != comPorts.end(); ++it) {
m_comPorts.push_back(QString(it->c_str()));
}
}
int AudioCATSISO::webapiRunGet(
int subsystemIndex,
SWGSDRangel::SWGDeviceState& response,

View File

@ -29,6 +29,7 @@
#include "audio/audiooutputdevice.h"
#include "audio/audiofifo.h"
#include "audiocatsisosettings.h"
#include "audiocatsisohamlib.h"
class DeviceAPI;
class QNetworkAccessManager;
@ -117,6 +118,10 @@ public:
virtual bool handleMessage(const Message& message);
const QStringList& getComPorts() { return m_comPorts; }
const QMap<uint32_t, QString>& getRigModels() const { return m_hamlibHandler.getRigModels(); }
const QMap<QString, uint32_t>& getRigNames() const { return m_hamlibHandler.getRigNames(); }
virtual int webapiSettingsGet(
SWGSDRangel::SWGDeviceSettings& response,
QString& errorMessage);
@ -175,8 +180,11 @@ private:
const QTimer& m_masterTimer;
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
QStringList m_comPorts;
AudioCATSISOHamlib m_hamlibHandler;
void applySettings(const AudioCATSISOSettings& settings, const QList<QString>& settingsKeys, bool force);
void listComPorts();
void webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const AudioCATSISOSettings& settings, bool force);
void webapiReverseSendStartStop(bool start);

View File

@ -72,6 +72,14 @@ AudioCATSISOGUI::AudioCATSISOGUI(DeviceUISet *deviceUISet, QWidget* parent) :
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
ui->centerFrequency->setValueRange(9, 0, m_absMaxFreq);
for (const auto& comPortName : m_sampleMIMO->getComPorts()) {
ui->catDevice->addItem(comPortName);
}
for (const auto& rigName : m_sampleMIMO->getRigNames().keys()) {
ui->catType->addItem(rigName);
}
displaySettings();
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
@ -355,6 +363,20 @@ void AudioCATSISOGUI::on_fcPosRx_currentIndexChanged(int index)
}
void AudioCATSISOGUI::on_catDevice_currentIndexChanged(int index)
{
m_settings.m_catDevicePath = ui->catDevice->itemText(index);
m_settingsKeys.append("catDevicePath");
sendSettings();
}
void AudioCATSISOGUI::on_catType_currentIndexChanged(int index)
{
m_settings.m_hamlibModel = m_sampleMIMO->getRigNames()[ui->catType->itemText(index)];
m_settingsKeys.append("hamlibModel");
sendSettings();
}
void AudioCATSISOGUI::displaySettings()
{
blockApplySettings(true);
@ -378,6 +400,8 @@ void AudioCATSISOGUI::displaySettings()
displaySampleRate();
updateSpectrum();
displayFcRxTooltip();
displayCatDevice();
displayCatType();
blockApplySettings(false);
}
@ -393,6 +417,37 @@ void AudioCATSISOGUI::displayFcRxTooltip()
ui->fcPosRx->setToolTip(tr("Relative position of device center frequency: %1 kHz").arg(QString::number(fShift / 1000.0f, 'g', 5)));
}
void AudioCATSISOGUI::displayCatDevice()
{
QMap<QString, int> catDevices;
for (int index = 0; index < ui->catDevice->count(); index++) {
catDevices[ui->catDevice->itemText(index)] = index;
}
if (catDevices.contains(m_settings.m_catDevicePath)) {
ui->catDevice->setCurrentIndex(catDevices[m_settings.m_catDevicePath]);
}
}
void AudioCATSISOGUI::displayCatType()
{
QMap<QString, int> catTypes;
for (int index = 0; index < ui->catType->count(); index++) {
catTypes[ui->catType->itemText(index)] = index;
}
auto const it = m_sampleMIMO->getRigModels().find(m_settings.m_hamlibModel);
if (it != m_sampleMIMO->getRigModels().end())
{
if (catTypes.contains(it.value())) {
ui->catType->setCurrentIndex(catTypes[it.value()]);
}
}
}
void AudioCATSISOGUI::sendSettings()
{
if (!m_updateTimer.isActive()) {
@ -619,4 +674,6 @@ void AudioCATSISOGUI::makeUIConnections()
QObject::connect(ui->txChannels, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AudioCATSISOGUI::on_txChannels_currentIndexChanged);
QObject::connect(ui->txVolume, &QDial::valueChanged, this, &AudioCATSISOGUI::on_txVolume_valueChanged);
QObject::connect(ui->fcPosRx, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AudioCATSISOGUI::on_fcPosRx_currentIndexChanged);
QObject::connect(ui->catDevice, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AudioCATSISOGUI::on_catDevice_currentIndexChanged);
QObject::connect(ui->catType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AudioCATSISOGUI::on_catType_currentIndexChanged);
}

View File

@ -70,6 +70,8 @@ private:
void displayFrequency();
void displaySampleRate();
void displayFcRxTooltip();
void displayCatDevice();
void displayCatType();
void updateSpectrum();
void sendSettings();
void setCenterFrequency(qint64 centerFrequency);
@ -95,6 +97,8 @@ private slots:
void on_txChannels_currentIndexChanged(int index);
void on_txVolume_valueChanged(int value);
void on_fcPosRx_currentIndexChanged(int index);
void on_catDevice_currentIndexChanged(int index);
void on_catType_currentIndexChanged(int index);
void openDeviceSettingsDialog(const QPoint& p);
void updateStatus();
void updateHardware();

View File

@ -0,0 +1,39 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2023 Edouard Griffiths, F4EXB //
// //
// 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 <hamlib/rig.h>
#include "audiocatsisohamlib.h"
AudioCATSISOHamlib::AudioCATSISOHamlib()
{
rig_load_all_backends();
int status = rig_list_foreach(hash_model_list, this);
qDebug("AudioCATSISOHamlib::AudioCATSISOHamlib: status: %d", status);
}
AudioCATSISOHamlib::~AudioCATSISOHamlib()
{
}
int AudioCATSISOHamlib::hash_model_list(const struct rig_caps *caps, void *data)
{
AudioCATSISOHamlib *hamlibHandler = (AudioCATSISOHamlib*) data;
hamlibHandler->m_rigModels[caps->rig_model] = caps->model_name;
hamlibHandler->m_rigNames[caps->model_name] = caps->rig_model;
return 1; /* !=0, we want them all ! */
}

View File

@ -0,0 +1,41 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2023 Edouard Griffiths, F4EXB //
// //
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef _AUDIOCATSISO_AUDIOCATSISOHAMLIB_H_
#define _AUDIOCATSISO_AUDIOCATSISOHAMLIB_H_
#include <QMap>
struct rig_caps;
class AudioCATSISOHamlib
{
public:
AudioCATSISOHamlib();
~AudioCATSISOHamlib();
const QMap<uint32_t, QString>& getRigModels() const { return m_rigModels; }
const QMap<QString, uint32_t>& getRigNames() const { return m_rigNames; }
private:
QMap<uint32_t, QString> m_rigModels;
QMap<QString, uint32_t> m_rigNames;
static int hash_model_list(const struct rig_caps *caps, void *data);
};
#endif // _AUDIOCATSISO_AUDIOCATSISOHAMLIB_H_

View File

@ -43,6 +43,8 @@ void AudioCATSISOSettings::resetToDefaults()
m_streamIndex = 0;
m_spectrumStreamIndex = 0;
m_txEnable = false;
m_catDevicePath = "";
m_hamlibModel = 1; // Hamlib dummy model
m_useReverseAPI = false;
m_reverseAPIAddress = "127.0.0.1";
m_reverseAPIPort = 8888;
@ -68,6 +70,8 @@ AudioCATSISOSettings::AudioCATSISOSettings(const AudioCATSISOSettings& other)
m_streamIndex = other.m_streamIndex;
m_spectrumStreamIndex = other.m_spectrumStreamIndex;
m_txEnable = other.m_txEnable;
m_catDevicePath = other.m_catDevicePath;
m_hamlibModel = other.m_hamlibModel;
m_useReverseAPI = other.m_useReverseAPI;
m_reverseAPIAddress = other.m_reverseAPIAddress;
m_reverseAPIPort = other.m_reverseAPIPort;
@ -94,6 +98,9 @@ QByteArray AudioCATSISOSettings::serialize() const
s.writeU32(25, m_log2Decim);
s.writeS32(26, (int) m_fcPosTx);
s.writeString(31, m_catDevicePath);
s.writeU32(32, m_hamlibModel);
s.writeBool(51, m_useReverseAPI);
s.writeString(52, m_reverseAPIAddress);
s.writeU32(53, m_reverseAPIPort);
@ -138,6 +145,9 @@ bool AudioCATSISOSettings::deserialize(const QByteArray& data)
d.readS32(26, &intval, 2);
m_fcPosTx = (fcPos_t) intval;
d.readString(31, &m_catDevicePath, "");
d.readU32(32, &m_hamlibModel, 1);
d.readBool(51, &m_useReverseAPI, false);
d.readString(52, &m_reverseAPIAddress, "127.0.0.1");
d.readU32(53, &uintval, 0);
@ -219,6 +229,12 @@ void AudioCATSISOSettings::applySettings(const QStringList& settingsKeys, const
if (settingsKeys.contains("txEnable")) {
m_txEnable = settings.m_txEnable;
}
if (settingsKeys.contains("catDevicePath")) {
m_catDevicePath = settings.m_catDevicePath;
}
if (settingsKeys.contains("hamlibModel")) {
m_hamlibModel = settings.m_hamlibModel;
}
if (settingsKeys.contains("useReverseAPI")) {
m_useReverseAPI = settings.m_useReverseAPI;
}
@ -287,6 +303,12 @@ QString AudioCATSISOSettings::getDebugString(const QStringList& settingsKeys, bo
if (settingsKeys.contains("txEnable") || force) {
ostr << " m_txEnable: " << m_txEnable;
}
if (settingsKeys.contains("catDevicePath") || force) {
ostr << " m_catDevicePath: " << m_catDevicePath.toStdString();
}
if (settingsKeys.contains("hamlibModel") || force) {
ostr << " m_hamlibModel: " << m_hamlibModel;
}
if (settingsKeys.contains("useReverseAPI") || force) {
ostr << " m_useReverseAPI: " << m_useReverseAPI;
}

View File

@ -58,6 +58,9 @@ struct AudioCATSISOSettings {
fcPos_t m_fcPosTx; //!< Not implemented yet
float m_txVolume; //!< Not implemented yet
QString m_catDevicePath;
uint32_t m_hamlibModel; //!< Hamlib model number
bool m_useReverseAPI;
QString m_reverseAPIAddress;
uint16_t m_reverseAPIPort;