mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-10-01 01:06:35 -04:00
SoapySDR support: input: manage global and individual gains coupling
This commit is contained in:
parent
b316af2d1d
commit
9d014d841b
@ -31,6 +31,7 @@
|
|||||||
MESSAGE_CLASS_DEFINITION(SoapySDRInput::MsgConfigureSoapySDRInput, Message)
|
MESSAGE_CLASS_DEFINITION(SoapySDRInput::MsgConfigureSoapySDRInput, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(SoapySDRInput::MsgFileRecord, Message)
|
MESSAGE_CLASS_DEFINITION(SoapySDRInput::MsgFileRecord, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(SoapySDRInput::MsgStartStop, Message)
|
MESSAGE_CLASS_DEFINITION(SoapySDRInput::MsgStartStop, Message)
|
||||||
|
MESSAGE_CLASS_DEFINITION(SoapySDRInput::MsgReportGainChange, Message)
|
||||||
|
|
||||||
SoapySDRInput::SoapySDRInput(DeviceSourceAPI *deviceAPI) :
|
SoapySDRInput::SoapySDRInput(DeviceSourceAPI *deviceAPI) :
|
||||||
m_deviceAPI(deviceAPI),
|
m_deviceAPI(deviceAPI),
|
||||||
@ -40,6 +41,7 @@ SoapySDRInput::SoapySDRInput(DeviceSourceAPI *deviceAPI) :
|
|||||||
m_thread(0)
|
m_thread(0)
|
||||||
{
|
{
|
||||||
openDevice();
|
openDevice();
|
||||||
|
initGainSettings(m_settings);
|
||||||
|
|
||||||
m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID()));
|
m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID()));
|
||||||
m_deviceAPI->addSink(m_fileSink);
|
m_deviceAPI->addSink(m_fileSink);
|
||||||
@ -261,6 +263,19 @@ const std::vector<DeviceSoapySDRParams::GainSetting>& SoapySDRInput::getIndividu
|
|||||||
return channelSettings->m_gainSettings;
|
return channelSettings->m_gainSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SoapySDRInput::initGainSettings(SoapySDRInputSettings& settings)
|
||||||
|
{
|
||||||
|
const DeviceSoapySDRParams::ChannelSettings* channelSettings = m_deviceShared.m_deviceParams->getRxChannelSettings(m_deviceShared.m_channel);
|
||||||
|
settings.m_individualGains.clear();
|
||||||
|
settings.m_globalGain = 0;
|
||||||
|
|
||||||
|
for (const auto &it : channelSettings->m_gainSettings) {
|
||||||
|
settings.m_individualGains[QString(it.m_name.c_str())] = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateGains(m_deviceShared.m_device, m_deviceShared.m_channel, settings);
|
||||||
|
}
|
||||||
|
|
||||||
void SoapySDRInput::init()
|
void SoapySDRInput::init()
|
||||||
{
|
{
|
||||||
applySettings(m_settings, true);
|
applySettings(m_settings, true);
|
||||||
@ -610,6 +625,19 @@ bool SoapySDRInput::setDeviceCenterFrequency(SoapySDR::Device *dev, int requeste
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SoapySDRInput::updateGains(SoapySDR::Device *dev, int requestedChannel, SoapySDRInputSettings& settings)
|
||||||
|
{
|
||||||
|
if (dev == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.m_globalGain = round(dev->getGain(SOAPY_SDR_RX, requestedChannel));
|
||||||
|
|
||||||
|
for (const auto &name : settings.m_individualGains.keys()) {
|
||||||
|
settings.m_individualGains[name] = dev->getGain(SOAPY_SDR_RX, requestedChannel, name.toStdString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool SoapySDRInput::handleMessage(const Message& message __attribute__((unused)))
|
bool SoapySDRInput::handleMessage(const Message& message __attribute__((unused)))
|
||||||
{
|
{
|
||||||
if (MsgConfigureSoapySDRInput::match(message))
|
if (MsgConfigureSoapySDRInput::match(message))
|
||||||
@ -709,6 +737,8 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo
|
|||||||
{
|
{
|
||||||
bool forwardChangeOwnDSP = false;
|
bool forwardChangeOwnDSP = false;
|
||||||
bool forwardChangeToBuddies = false;
|
bool forwardChangeToBuddies = false;
|
||||||
|
bool globalGainChanged = false;
|
||||||
|
bool individualGainsChanged = false;
|
||||||
|
|
||||||
SoapySDR::Device *dev = m_deviceShared.m_device;
|
SoapySDR::Device *dev = m_deviceShared.m_device;
|
||||||
SoapySDRInputThread *inputThread = findThread();
|
SoapySDRInputThread *inputThread = findThread();
|
||||||
@ -867,6 +897,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo
|
|||||||
{
|
{
|
||||||
dev->setGain(SOAPY_SDR_RX, requestedChannel, settings.m_globalGain);
|
dev->setGain(SOAPY_SDR_RX, requestedChannel, settings.m_globalGain);
|
||||||
qDebug("SoapySDRInput::applySettings: set global gain to %d", settings.m_globalGain);
|
qDebug("SoapySDRInput::applySettings: set global gain to %d", settings.m_globalGain);
|
||||||
|
globalGainChanged = true;
|
||||||
}
|
}
|
||||||
catch (const std::exception &ex)
|
catch (const std::exception &ex)
|
||||||
{
|
{
|
||||||
@ -880,7 +911,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo
|
|||||||
{
|
{
|
||||||
auto nvalue = settings.m_individualGains.find(oname);
|
auto nvalue = settings.m_individualGains.find(oname);
|
||||||
|
|
||||||
if (nvalue != settings.m_individualGains.end() && (m_settings.m_individualGains[oname] != *nvalue))
|
if (nvalue != settings.m_individualGains.end() && ((m_settings.m_individualGains[oname] != *nvalue) || force))
|
||||||
{
|
{
|
||||||
if (dev != 0)
|
if (dev != 0)
|
||||||
{
|
{
|
||||||
@ -889,6 +920,7 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo
|
|||||||
dev->setGain(SOAPY_SDR_RX, requestedChannel, oname.toStdString(), *nvalue);
|
dev->setGain(SOAPY_SDR_RX, requestedChannel, oname.toStdString(), *nvalue);
|
||||||
qDebug("SoapySDRInput::applySettings: individual gain %s set to %lf",
|
qDebug("SoapySDRInput::applySettings: individual gain %s set to %lf",
|
||||||
oname.toStdString().c_str(), *nvalue);
|
oname.toStdString().c_str(), *nvalue);
|
||||||
|
individualGainsChanged = true;
|
||||||
}
|
}
|
||||||
catch (const std::exception &ex)
|
catch (const std::exception &ex)
|
||||||
{
|
{
|
||||||
@ -940,6 +972,19 @@ bool SoapySDRInput::applySettings(const SoapySDRInputSettings& settings, bool fo
|
|||||||
|
|
||||||
m_settings = settings;
|
m_settings = settings;
|
||||||
|
|
||||||
|
if (globalGainChanged || individualGainsChanged)
|
||||||
|
{
|
||||||
|
if (dev) {
|
||||||
|
updateGains(dev, requestedChannel, m_settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getMessageQueueToGUI())
|
||||||
|
{
|
||||||
|
MsgReportGainChange *report = MsgReportGainChange::create(m_settings, individualGainsChanged, globalGainChanged);
|
||||||
|
getMessageQueueToGUI()->push(report);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "SoapySDRInput::applySettings: "
|
qDebug() << "SoapySDRInput::applySettings: "
|
||||||
<< " m_transverterMode: " << m_settings.m_transverterMode
|
<< " m_transverterMode: " << m_settings.m_transverterMode
|
||||||
<< " m_transverterDeltaFrequency: " << m_settings.m_transverterDeltaFrequency
|
<< " m_transverterDeltaFrequency: " << m_settings.m_transverterDeltaFrequency
|
||||||
|
@ -99,6 +99,32 @@ public:
|
|||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MsgReportGainChange : public Message {
|
||||||
|
MESSAGE_CLASS_DECLARATION
|
||||||
|
|
||||||
|
public:
|
||||||
|
const SoapySDRInputSettings& getSettings() const { return m_settings; }
|
||||||
|
bool getGlobalGain() const { return m_globalGain; }
|
||||||
|
bool getIndividualGains() const { return m_individualGains; }
|
||||||
|
|
||||||
|
static MsgReportGainChange* create(const SoapySDRInputSettings& settings, bool globalGain, bool individualGains)
|
||||||
|
{
|
||||||
|
return new MsgReportGainChange(settings, globalGain, individualGains);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
SoapySDRInputSettings m_settings;
|
||||||
|
bool m_globalGain;
|
||||||
|
bool m_individualGains;
|
||||||
|
|
||||||
|
MsgReportGainChange(const SoapySDRInputSettings& settings, bool globalGain, bool individualGains) :
|
||||||
|
Message(),
|
||||||
|
m_settings(settings),
|
||||||
|
m_globalGain(globalGain),
|
||||||
|
m_individualGains(individualGains)
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
SoapySDRInput(DeviceSourceAPI *deviceAPI);
|
SoapySDRInput(DeviceSourceAPI *deviceAPI);
|
||||||
virtual ~SoapySDRInput();
|
virtual ~SoapySDRInput();
|
||||||
virtual void destroy();
|
virtual void destroy();
|
||||||
@ -128,6 +154,7 @@ public:
|
|||||||
int getAntennaIndex(const std::string& antenna);
|
int getAntennaIndex(const std::string& antenna);
|
||||||
const std::vector<DeviceSoapySDRParams::FrequencySetting>& getTunableElements();
|
const std::vector<DeviceSoapySDRParams::FrequencySetting>& getTunableElements();
|
||||||
const std::vector<DeviceSoapySDRParams::GainSetting>& getIndividualGainsRanges();
|
const std::vector<DeviceSoapySDRParams::GainSetting>& getIndividualGainsRanges();
|
||||||
|
void initGainSettings(SoapySDRInputSettings& settings);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceSourceAPI *m_deviceAPI;
|
DeviceSourceAPI *m_deviceAPI;
|
||||||
@ -145,6 +172,7 @@ private:
|
|||||||
void moveThreadToBuddy();
|
void moveThreadToBuddy();
|
||||||
bool applySettings(const SoapySDRInputSettings& settings, bool force = false);
|
bool applySettings(const SoapySDRInputSettings& settings, bool force = false);
|
||||||
bool setDeviceCenterFrequency(SoapySDR::Device *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths);
|
bool setDeviceCenterFrequency(SoapySDR::Device *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths);
|
||||||
|
void updateGains(SoapySDR::Device *dev, int requestedChannel, SoapySDRInputSettings& settings);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ SoapySDRInputGui::SoapySDRInputGui(DeviceUISet *deviceUISet, QWidget* parent) :
|
|||||||
createTunableElementsControl(m_sampleSource->getTunableElements());
|
createTunableElementsControl(m_sampleSource->getTunableElements());
|
||||||
createGlobalGainControl();
|
createGlobalGainControl();
|
||||||
createIndividualGainsControl(m_sampleSource->getIndividualGainsRanges());
|
createIndividualGainsControl(m_sampleSource->getIndividualGainsRanges());
|
||||||
|
m_sampleSource->initGainSettings(m_settings);
|
||||||
|
|
||||||
if (m_sampleRateGUI) {
|
if (m_sampleRateGUI) {
|
||||||
connect(m_sampleRateGUI, SIGNAL(valueChanged(double)), this, SLOT(sampleRateChanged(double)));
|
connect(m_sampleRateGUI, SIGNAL(valueChanged(double)), this, SLOT(sampleRateChanged(double)));
|
||||||
@ -282,6 +283,24 @@ bool SoapySDRInputGui::handleMessage(const Message& message)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (SoapySDRInput::MsgReportGainChange::match(message))
|
||||||
|
{
|
||||||
|
const SoapySDRInput::MsgReportGainChange& report = (SoapySDRInput::MsgReportGainChange&) message;
|
||||||
|
const SoapySDRInputSettings& gainSettings = report.getSettings();
|
||||||
|
|
||||||
|
if (report.getGlobalGain()) {
|
||||||
|
m_settings.m_globalGain = gainSettings.m_globalGain;
|
||||||
|
}
|
||||||
|
if (report.getIndividualGains()) {
|
||||||
|
m_settings.m_individualGains = gainSettings.m_individualGains;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockApplySettings(true);
|
||||||
|
displaySettings();
|
||||||
|
blockApplySettings(false);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else if (SoapySDRInput::MsgStartStop::match(message))
|
else if (SoapySDRInput::MsgStartStop::match(message))
|
||||||
{
|
{
|
||||||
SoapySDRInput::MsgStartStop& notif = (SoapySDRInput::MsgStartStop&) message;
|
SoapySDRInput::MsgStartStop& notif = (SoapySDRInput::MsgStartStop&) message;
|
||||||
|
Loading…
Reference in New Issue
Block a user