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.
Classes | Public Member Functions | Private Attributes | List of all members
DevicePlutoSDRScan Class Reference

#include <deviceplutosdrscan.h>

Classes

struct  DeviceScan
 

Public Member Functions

void scan ()
 
int getNbDevices () const
 
const std::string * getURIAt (unsigned int index) const
 
const std::string * getSerialAt (unsigned int index) const
 
const std::string * getURIFromSerial (const std::string &serial) const
 
void getSerials (std::vector< std::string > &serials) const
 

Private Attributes

std::vector< DeviceScanm_scans
 
std::map< std::string, DeviceScan * > m_serialMap
 
std::map< std::string, DeviceScan * > m_urilMap
 

Detailed Description

Definition at line 27 of file deviceplutosdrscan.h.

Member Function Documentation

◆ getNbDevices()

int DevicePlutoSDRScan::getNbDevices ( ) const
inline

Definition at line 38 of file deviceplutosdrscan.h.

38 { return m_scans.size(); }
std::vector< DeviceScan > m_scans

◆ getSerialAt()

const std::string * DevicePlutoSDRScan::getSerialAt ( unsigned int  index) const

Definition at line 107 of file deviceplutosdrscan.cpp.

References m_scans.

108 {
109  if (index < m_scans.size()) {
110  return &(m_scans[index].m_serial);
111  } else {
112  return 0;
113  }
114 }
std::vector< DeviceScan > m_scans

◆ getSerials()

void DevicePlutoSDRScan::getSerials ( std::vector< std::string > &  serials) const

Definition at line 127 of file deviceplutosdrscan.cpp.

References m_scans.

128 {
129  std::vector<DeviceScan>::const_iterator it = m_scans.begin();
130  serials.clear();
131 
132  for (; it != m_scans.end(); ++it) {
133  serials.push_back(it->m_serial);
134  }
135 }
std::vector< DeviceScan > m_scans

◆ getURIAt()

const std::string * DevicePlutoSDRScan::getURIAt ( unsigned int  index) const

Definition at line 98 of file deviceplutosdrscan.cpp.

References m_scans.

99 {
100  if (index < m_scans.size()) {
101  return &(m_scans[index].m_uri);
102  } else {
103  return 0;
104  }
105 }
std::vector< DeviceScan > m_scans

◆ getURIFromSerial()

const std::string * DevicePlutoSDRScan::getURIFromSerial ( const std::string &  serial) const

Definition at line 116 of file deviceplutosdrscan.cpp.

References m_serialMap.

Referenced by DevicePlutoSDR::getDeviceFromSerial().

118 {
119  std::map<std::string, DeviceScan*>::const_iterator it = m_serialMap.find(serial);
120  if (it == m_serialMap.end()) {
121  return 0;
122  } else {
123  return &((it->second)->m_uri);
124  }
125 }
std::map< std::string, DeviceScan * > m_serialMap
+ Here is the caller graph for this function:

◆ scan()

void DevicePlutoSDRScan::scan ( )

Definition at line 29 of file deviceplutosdrscan.cpp.

References i, m_scans, m_serialMap, m_urilMap, and DevicePlutoSDRBox::probeURI().

30 {
31  int i, num_contexts;
32  struct iio_scan_context *scan_ctx;
33  struct iio_context_info **info;
34 
35  scan_ctx = iio_create_scan_context(0, 0);
36 
37  if (!scan_ctx)
38  {
39  qCritical("PlutoSDRScan::scan: could not create scan context");
40  return;
41  }
42 
43  num_contexts = iio_scan_context_get_info_list(scan_ctx, &info);
44 
45  if (num_contexts < 0)
46  {
47  qCritical("PlutoSDRScan::scan: could not get contexts");
48  return;
49  }
50 
51  m_scans.clear();
52 
53  if (num_contexts == 0)
54  {
55  struct iio_context *ctx = iio_create_network_context("pluto.local");
56  if(!ctx) {
57  return;
58  }
59  m_scans.push_back({std::string("PlutoSDR"), std::string("networked"), std::string("ip:pluto.local")});
60  m_serialMap[m_scans.back().m_serial] = &m_scans.back();
61  m_urilMap[m_scans.back().m_uri] = &m_scans.back();
62  iio_context_destroy(ctx);
63  }
64 
65  for (i = 0; i < num_contexts; i++)
66  {
67  const char *description = iio_context_info_get_description(info[i]);
68  const char *uri = iio_context_info_get_uri(info[i]);
69 
70  if (!DevicePlutoSDRBox::probeURI(std::string(uri))) { // continue if not accessible
71  continue;
72  }
73 
74  qDebug("PlutoSDRScan::scan: %d: %s [%s]", i, description, uri);
75  char *pch = strstr(const_cast<char*>(description), "PlutoSDR");
76 
77  if (pch)
78  {
79  m_scans.push_back({std::string(description), std::string("TBD"), std::string(uri)});
80  m_urilMap[m_scans.back().m_uri] = &m_scans.back();
81 
82  std::regex desc_regex(".*serial=(.+)");
83  std::smatch desc_match;
84  std::regex_search(m_scans.back().m_name, desc_match, desc_regex);
85 
86  if (desc_match.size() == 2)
87  {
88  m_scans.back().m_serial = desc_match[1];
89  m_serialMap[m_scans.back().m_serial] = &m_scans.back();
90  }
91  }
92  }
93 
94  iio_context_info_list_free(info);
95  iio_scan_context_destroy(scan_ctx);
96 }
std::vector< DeviceScan > m_scans
std::map< std::string, DeviceScan * > m_urilMap
std::map< std::string, DeviceScan * > m_serialMap
int32_t i
Definition: decimators.h:244
static bool probeURI(const std::string &uri)
+ Here is the call graph for this function:

Member Data Documentation

◆ m_scans

std::vector<DeviceScan> DevicePlutoSDRScan::m_scans
private

Definition at line 45 of file deviceplutosdrscan.h.

Referenced by getSerialAt(), getSerials(), getURIAt(), and scan().

◆ m_serialMap

std::map<std::string, DeviceScan*> DevicePlutoSDRScan::m_serialMap
private

Definition at line 46 of file deviceplutosdrscan.h.

Referenced by getURIFromSerial(), and scan().

◆ m_urilMap

std::map<std::string, DeviceScan*> DevicePlutoSDRScan::m_urilMap
private

Definition at line 47 of file deviceplutosdrscan.h.

Referenced by scan().


The documentation for this class was generated from the following files: