SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
devicesoapysdr.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #include <QStringList>
19 #include "devicesoapysdr.h"
20 
22 {
23  m_scanner.scan();
24 }
25 
27 {}
28 
30 {
31  static DeviceSoapySDR inst;
32  return inst;
33 }
34 
35 SoapySDR::Device *DeviceSoapySDR::openSoapySDR(uint32_t sequence, const QString& hardwareUserArguments)
36 {
37  instance();
38  return openopenSoapySDRFromSequence(sequence, hardwareUserArguments);
39 }
40 
41 void DeviceSoapySDR::closeSoapySdr(SoapySDR::Device *device)
42 {
43  SoapySDR::Device::unmake(device);
44 }
45 
46 SoapySDR::Device *DeviceSoapySDR::openopenSoapySDRFromSequence(uint32_t sequence, const QString& hardwareUserArguments)
47 {
48  if (sequence > m_scanner.getNbDevices())
49  {
50  return 0;
51  }
52  else
53  {
55 
56  try
57  {
58  SoapySDR::Kwargs kwargs;
59  kwargs["driver"] = deviceEnum.m_driverName.toStdString();
60 
61  if (hardwareUserArguments.size() > 0)
62  {
63  QStringList kvArgs = hardwareUserArguments.split(',');
64 
65  for (int i = 0; i < kvArgs.size(); i++)
66  {
67  QStringList kv = kvArgs.at(i).split('=');
68 
69  if (kv.size() > 1) {
70  kwargs[kv.at(0).toStdString()] = kv.at(1).toStdString();
71  }
72  }
73  }
74  else if (deviceEnum.m_idKey.size() > 0)
75  {
76  kwargs[deviceEnum.m_idKey.toStdString()] = deviceEnum.m_idValue.toStdString();
77  }
78 
79  SoapySDR::Kwargs::const_iterator it = kwargs.begin();
80 
81  for (; it != kwargs.end(); ++it) {
82  qDebug("DeviceSoapySDR::openopenSoapySDRFromSequence: %s=%s", it->first.c_str(), it->second.c_str());
83  }
84 
85  SoapySDR::Device *device = SoapySDR::Device::make(kwargs);
86  return device;
87  }
88  catch (const std::exception &ex)
89  {
90  qWarning("DeviceSoapySDR::openopenSoapySDRFromSequence: %s cannot be opened: %s",
91  deviceEnum.m_label.toStdString().c_str(), ex.what());
92  return 0;
93  }
94  }
95 }
static DeviceSoapySDR & instance()
void closeSoapySdr(SoapySDR::Device *device)
const std::vector< SoapySDRDeviceEnum > & getDevicesEnumeration() const
QString m_idValue
value for the above key
unsigned int uint32_t
Definition: rtptypes_win.h:46
uint32_t getNbDevices() const
int32_t i
Definition: decimators.h:244
QString m_label
the label key for display should always be present
SoapySDR::Device * openopenSoapySDRFromSequence(uint32_t sequence, const QString &hardwareUserArguments)
DeviceSoapySDRScan m_scanner
SoapySDR::Device * openSoapySDR(uint32_t sequence, const QString &hardwareUserArguments)
QString m_idKey
key to uniquely identify device