mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-25 17:28:50 -05:00
SoapySDR support: use singleton for enumeration and device management
This commit is contained in:
parent
c82d838708
commit
0e9a0f4f6d
@ -3,10 +3,12 @@ project(soapysdrdevice)
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
|
||||
set(soapysdrdevice_SOURCES
|
||||
devicesoapysdr.cpp
|
||||
devicesoapysdrscan.cpp
|
||||
)
|
||||
|
||||
set(soapysdrdevice_HEADERS
|
||||
devicesoapysdr.h
|
||||
devicesoapysdrscan.h
|
||||
)
|
||||
|
||||
|
68
devices/soapysdr/devicesoapysdr.cpp
Normal file
68
devices/soapysdr/devicesoapysdr.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 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 //
|
||||
// //
|
||||
// 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 "devicesoapysdr.h"
|
||||
|
||||
DeviceSoapySDR::DeviceSoapySDR()
|
||||
{
|
||||
m_scanner.scan();
|
||||
}
|
||||
|
||||
DeviceSoapySDR::~DeviceSoapySDR()
|
||||
{}
|
||||
|
||||
DeviceSoapySDR& DeviceSoapySDR::instance()
|
||||
{
|
||||
static DeviceSoapySDR inst;
|
||||
return inst;
|
||||
}
|
||||
|
||||
SoapySDR::Device *DeviceSoapySDR::openSoapySDR(uint32_t sequence)
|
||||
{
|
||||
instance();
|
||||
return openopenSoapySDRFromSequence(sequence);
|
||||
}
|
||||
|
||||
SoapySDR::Device *DeviceSoapySDR::openopenSoapySDRFromSequence(uint32_t sequence)
|
||||
{
|
||||
if (sequence > m_scanner.getNbDevices())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
const DeviceSoapySDRScan::SoapySDRDeviceEnum& deviceEnum = m_scanner.getDevicesEnumeration()[sequence];
|
||||
|
||||
try
|
||||
{
|
||||
SoapySDR::Kwargs kwargs;
|
||||
kwargs["driver"] = deviceEnum.m_driverName.toStdString();
|
||||
|
||||
if (deviceEnum.m_idKey.size() > 0) {
|
||||
kwargs[deviceEnum.m_idKey.toStdString()] = deviceEnum.m_idValue.toStdString();
|
||||
}
|
||||
|
||||
SoapySDR::Device *device = SoapySDR::Device::make(kwargs);
|
||||
return device;
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
qWarning("DeviceSoapySDR::openopenSoapySDRFromSequence: %s cannot be opened: %s",
|
||||
deviceEnum.m_label.toStdString().c_str(), ex.what());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
46
devices/soapysdr/devicesoapysdr.h
Normal file
46
devices/soapysdr/devicesoapysdr.h
Normal file
@ -0,0 +1,46 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 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 //
|
||||
// //
|
||||
// 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 DEVICES_SOAPYSDR_DEVICESOAPYSDR_H_
|
||||
#define DEVICES_SOAPYSDR_DEVICESOAPYSDR_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <SoapySDR/Device.hpp>
|
||||
|
||||
#include "export.h"
|
||||
#include "devicesoapysdrscan.h"
|
||||
|
||||
class DEVICES_API DeviceSoapySDR
|
||||
{
|
||||
public:
|
||||
static DeviceSoapySDR& instance();
|
||||
SoapySDR::Device *openSoapySDR(uint32_t sequence);
|
||||
|
||||
uint32_t getNbDevices() const { return m_scanner.getNbDevices(); }
|
||||
const std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>& getDevicesEnumeration() const { return m_scanner.getDevicesEnumeration(); }
|
||||
|
||||
protected:
|
||||
DeviceSoapySDR();
|
||||
DeviceSoapySDR(const DeviceSoapySDR&) {}
|
||||
DeviceSoapySDR& operator=(const DeviceSoapySDR& other __attribute__((unused))) { return *this; }
|
||||
~DeviceSoapySDR();
|
||||
|
||||
private:
|
||||
SoapySDR::Device *openopenSoapySDRFromSequence(uint32_t sequence);
|
||||
DeviceSoapySDRScan m_scanner;
|
||||
};
|
||||
|
||||
#endif /* DEVICES_SOAPYSDR_DEVICESOAPYSDR_H_ */
|
@ -18,7 +18,7 @@
|
||||
#include "plugin/pluginapi.h"
|
||||
#include "util/simpleserializer.h"
|
||||
#include "device/devicesourceapi.h"
|
||||
#include "soapysdr/devicesoapysdrscan.h"
|
||||
#include "soapysdr/devicesoapysdr.h"
|
||||
|
||||
#include "soapysdrinputplugin.h"
|
||||
|
||||
@ -58,9 +58,8 @@ void SoapySDRInputPlugin::initPlugin(PluginAPI* pluginAPI)
|
||||
PluginInterface::SamplingDevices SoapySDRInputPlugin::enumSampleSources()
|
||||
{
|
||||
SamplingDevices result;
|
||||
DeviceSoapySDRScan scanner;
|
||||
scanner.scan();
|
||||
const std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>& devicesEnumeration = scanner.getDevicesEnumeration();
|
||||
DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance();
|
||||
const std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>& devicesEnumeration = deviceSoapySDR.getDevicesEnumeration();
|
||||
qDebug("SoapySDRInputPlugin::enumSampleSources: found %lu devices", devicesEnumeration.size());
|
||||
std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>::const_iterator it = devicesEnumeration.begin();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user