2018-10-29 12:20:04 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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 //
|
2019-04-11 00:39:30 -04:00
|
|
|
// (at your option) any later version. //
|
2018-10-29 12:20:04 -04:00
|
|
|
// //
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-06-13 19:14:27 -04:00
|
|
|
#include <QStringList>
|
2018-10-29 12:20:04 -04:00
|
|
|
#include "devicesoapysdr.h"
|
|
|
|
|
|
|
|
DeviceSoapySDR::DeviceSoapySDR()
|
|
|
|
{
|
|
|
|
m_scanner.scan();
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceSoapySDR::~DeviceSoapySDR()
|
|
|
|
{}
|
|
|
|
|
|
|
|
DeviceSoapySDR& DeviceSoapySDR::instance()
|
|
|
|
{
|
|
|
|
static DeviceSoapySDR inst;
|
|
|
|
return inst;
|
|
|
|
}
|
|
|
|
|
2019-06-13 19:14:27 -04:00
|
|
|
SoapySDR::Device *DeviceSoapySDR::openSoapySDR(uint32_t sequence, const QString& hardwareUserArguments)
|
2018-10-29 12:20:04 -04:00
|
|
|
{
|
|
|
|
instance();
|
2019-06-13 19:14:27 -04:00
|
|
|
return openopenSoapySDRFromSequence(sequence, hardwareUserArguments);
|
2018-10-29 12:20:04 -04:00
|
|
|
}
|
|
|
|
|
2018-10-29 20:58:39 -04:00
|
|
|
void DeviceSoapySDR::closeSoapySdr(SoapySDR::Device *device)
|
|
|
|
{
|
|
|
|
SoapySDR::Device::unmake(device);
|
|
|
|
}
|
|
|
|
|
2019-06-13 19:14:27 -04:00
|
|
|
SoapySDR::Device *DeviceSoapySDR::openopenSoapySDRFromSequence(uint32_t sequence, const QString& hardwareUserArguments)
|
2018-10-29 12:20:04 -04:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2019-06-13 19:14:27 -04:00
|
|
|
if (hardwareUserArguments.size() > 0)
|
|
|
|
{
|
|
|
|
QStringList kvArgs = hardwareUserArguments.split(',');
|
|
|
|
|
|
|
|
for (int i = 0; i < kvArgs.size(); i++)
|
|
|
|
{
|
|
|
|
QStringList kv = kvArgs.at(i).split('=');
|
|
|
|
|
|
|
|
if (kv.size() > 1) {
|
|
|
|
kwargs[kv.at(0).toStdString()] = kv.at(1).toStdString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (deviceEnum.m_idKey.size() > 0)
|
|
|
|
{
|
2018-10-29 12:20:04 -04:00
|
|
|
kwargs[deviceEnum.m_idKey.toStdString()] = deviceEnum.m_idValue.toStdString();
|
|
|
|
}
|
|
|
|
|
2019-06-13 19:14:27 -04:00
|
|
|
SoapySDR::Kwargs::const_iterator it = kwargs.begin();
|
|
|
|
|
|
|
|
for (; it != kwargs.end(); ++it) {
|
|
|
|
qDebug("DeviceSoapySDR::openopenSoapySDRFromSequence: %s=%s", it->first.c_str(), it->second.c_str());
|
|
|
|
}
|
|
|
|
|
2018-10-29 12:20:04 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|