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.
devicesoapysdrscan.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 <SoapySDR/Version.hpp>
19 #include <SoapySDR/Modules.hpp>
20 #include <SoapySDR/Registry.hpp>
21 #include <SoapySDR/Device.hpp>
22 
23 #include <QDebug>
24 #include <QString>
25 
26 #include "devicesoapysdrscan.h"
27 
29 {
30  qDebug("DeviceSoapySDRScan::scan: Lib Version: v%s", SoapySDR::getLibVersion().c_str());
31  qDebug("DeviceSoapySDRScan::scan: API Version: v%s", SoapySDR::getAPIVersion().c_str());
32  qDebug("DeviceSoapySDRScan::scan: ABI Version: v%s", SoapySDR::getABIVersion().c_str());
33  qDebug("DeviceSoapySDRScan::scan: Install root: %s", SoapySDR::getRootPath().c_str());
34 
35  const std::vector<std::string>& modules = SoapySDR::listModules();
36 
37  for (const auto &it : modules)
38  {
39  const auto &errMsg = SoapySDR::loadModule(it);
40 
41  if (not errMsg.empty()) {
42  qWarning("DeviceSoapySDRScan::scan: cannot load module %s: %s", it.c_str(), errMsg.c_str());
43  } else {
44  qDebug("DeviceSoapySDRScan::scan: loaded module: %s", it.c_str());
45  }
46  }
47 
48  SoapySDR::FindFunctions findFunctions = SoapySDR::Registry::listFindFunctions();
49  SoapySDR::Kwargs kwargs;
50  m_deviceEnums.clear();
51 
52  for (const auto &it : findFunctions) // for each driver
53  {
54  qDebug("DeviceSoapySDRScan::scan: driver: %s", it.first.c_str());
55  kwargs["driver"] = it.first;
56 
57  SoapySDR::KwargsList kwargsList = SoapySDR::Device::enumerate(kwargs);
58  SoapySDR::KwargsList::const_iterator kit = kwargsList.begin();
59 
60  for (int deviceSeq = 0; kit != kwargsList.end(); ++kit, deviceSeq++) // for each device
61  {
62  m_deviceEnums.push_back(SoapySDRDeviceEnum());
63  m_deviceEnums.back().m_driverName = QString(it.first.c_str());
64  m_deviceEnums.back().m_sequence = deviceSeq;
65 
66  // collect identification information
67 
68  SoapySDR::Kwargs::const_iterator kargIt;
69 
70  if ((kargIt = kit->find("label")) != kit->end()) {
71  m_deviceEnums.back().m_label = QString(kargIt->second.c_str());
72  } else { // if no label is registered for this device then create a label with the driver name and sequence
73  m_deviceEnums.back().m_label = QString("%1-%2").arg(m_deviceEnums.back().m_driverName).arg(deviceSeq);
74  }
75 
76  if ((kargIt = kit->find("serial")) != kit->end())
77  {
78  m_deviceEnums.back().m_idKey = QString(kargIt->first.c_str());
79  m_deviceEnums.back().m_idValue = QString(kargIt->second.c_str());
80  }
81  else if ((kargIt = kit->find("device_id")) != kit->end())
82  {
83  m_deviceEnums.back().m_idKey = QString(kargIt->first.c_str());
84  m_deviceEnums.back().m_idValue = QString(kargIt->second.c_str());
85  }
86  else if ((kargIt = kit->find("addr")) != kit->end())
87  {
88  m_deviceEnums.back().m_idKey = QString(kargIt->first.c_str());
89  m_deviceEnums.back().m_idValue = QString(kargIt->second.c_str());
90  }
91 
92  qDebug("DeviceSoapySDRScan::scan: %s #%u %s id: %s=%s",
93  m_deviceEnums.back().m_driverName.toStdString().c_str(),
94  deviceSeq,
95  m_deviceEnums.back().m_label.toStdString().c_str(),
96  m_deviceEnums.back().m_idKey.toStdString().c_str(),
97  m_deviceEnums.back().m_idValue.toStdString().c_str());
98 
99  // access the device to get the number of Rx and Tx channels and at the same time probe
100  // whether it is available for Soapy
101 
102  try
103  {
104  SoapySDR::Device *device;
105  SoapySDR::Kwargs kwargs;
106  kwargs["driver"] = m_deviceEnums.back().m_driverName.toStdString();
107 
108  if (m_deviceEnums.back().m_idKey.size() > 0) {
109  kwargs[m_deviceEnums.back().m_idKey.toStdString()] = m_deviceEnums.back().m_idValue.toStdString();
110  }
111 
112  device = SoapySDR::Device::make(kwargs);
113  m_deviceEnums.back().m_nbRx = device->getNumChannels(SOAPY_SDR_RX);
114  m_deviceEnums.back().m_nbTx = device->getNumChannels(SOAPY_SDR_TX);
115  qDebug("DeviceSoapySDRScan::scan: %s #%u driver=%s hardware=%s #Rx=%u #Tx=%u",
116  m_deviceEnums.back().m_driverName.toStdString().c_str(),
117  deviceSeq,
118  device->getDriverKey().c_str(),
119  device->getHardwareKey().c_str(),
120  m_deviceEnums.back().m_nbRx,
121  m_deviceEnums.back().m_nbTx);
122 
123  SoapySDR::Device::unmake(device);
124  }
125  catch (const std::exception &ex)
126  {
127  qWarning("DeviceSoapySDRScan::scan: %s #%u cannot be opened: %s",
128  m_deviceEnums.back().m_driverName.toStdString().c_str(),
129  deviceSeq,
130  ex.what());
131  m_deviceEnums.pop_back();
132  }
133  } // for each device
134  }
135 }
std::vector< SoapySDRDeviceEnum > m_deviceEnums
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401