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.
deviceenumerator.cpp
Go to the documentation of this file.
1 // Copyright (C) 2016-2019 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 <QGlobalStatic>
19 
20 #include "plugin/pluginmanager.h"
21 #include "deviceenumerator.h"
22 
23 Q_GLOBAL_STATIC(DeviceEnumerator, deviceEnumerator)
25 {
26  return deviceEnumerator;
27 }
28 
30 {}
31 
33 {}
34 
36 {
37  m_rxEnumeration.clear();
38  PluginAPI::SamplingDeviceRegistrations& rxDeviceRegistrations = pluginManager->getSourceDeviceRegistrations();
39  int index = 0;
40 
41  for (int i = 0; i < rxDeviceRegistrations.count(); i++)
42  {
43  qDebug("DeviceEnumerator::enumerateRxDevices: %s", qPrintable(rxDeviceRegistrations[i].m_deviceId));
44  PluginInterface::SamplingDevices samplingDevices = rxDeviceRegistrations[i].m_plugin->enumSampleSources();
45 
46  for (int j = 0; j < samplingDevices.count(); j++)
47  {
48  m_rxEnumeration.push_back(
50  samplingDevices[j],
51  rxDeviceRegistrations[i].m_plugin,
52  index
53  )
54  );
55  index++;
56  }
57  }
58 }
59 
61 {
62  m_txEnumeration.clear();
63  PluginAPI::SamplingDeviceRegistrations& txDeviceRegistrations = pluginManager->getSinkDeviceRegistrations();
64  int index = 0;
65 
66  for (int i = 0; i < txDeviceRegistrations.count(); i++)
67  {
68  qDebug("DeviceEnumerator::enumerateTxDevices: %s", qPrintable(txDeviceRegistrations[i].m_deviceId));
69  PluginInterface::SamplingDevices samplingDevices = txDeviceRegistrations[i].m_plugin->enumSampleSinks();
70 
71  for (int j = 0; j < samplingDevices.count(); j++)
72  {
73  m_txEnumeration.push_back(
75  samplingDevices[j],
76  txDeviceRegistrations[i].m_plugin,
77  index
78  )
79  );
80  index++;
81  }
82  }
83 }
84 
86 {
87  m_mimoEnumeration.clear();
88  PluginAPI::SamplingDeviceRegistrations& mimoDeviceRegistrations = pluginManager->getMIMODeviceRegistrations();
89  int index = 0;
90 
91  for (int i = 0; i < mimoDeviceRegistrations.count(); i++)
92  {
93  qDebug("DeviceEnumerator::enumerateMIMODevices: %s", qPrintable(mimoDeviceRegistrations[i].m_deviceId));
94  PluginInterface::SamplingDevices samplingDevices = mimoDeviceRegistrations[i].m_plugin->enumSampleMIMO();
95 
96  for (int j = 0; j < samplingDevices.count(); j++)
97  {
98  m_mimoEnumeration.push_back(
100  samplingDevices[j],
101  mimoDeviceRegistrations[i].m_plugin,
102  index
103  )
104  );
105  index++;
106  }
107  }
108 }
109 
110 void DeviceEnumerator::listRxDeviceNames(QList<QString>& list, std::vector<int>& indexes) const
111 {
112  for (DevicesEnumeration::const_iterator it = m_rxEnumeration.begin(); it != m_rxEnumeration.end(); ++it)
113  {
114  if ((it->m_samplingDevice.claimed < 0) || (it->m_samplingDevice.type == PluginInterface::SamplingDevice::BuiltInDevice))
115  {
116  list.append(it->m_samplingDevice.displayedName);
117  indexes.push_back(it->m_index);
118  }
119  }
120 }
121 
122 void DeviceEnumerator::listTxDeviceNames(QList<QString>& list, std::vector<int>& indexes) const
123 {
124  for (DevicesEnumeration::const_iterator it = m_txEnumeration.begin(); it != m_txEnumeration.end(); ++it)
125  {
126  if ((it->m_samplingDevice.claimed < 0) || (it->m_samplingDevice.type == PluginInterface::SamplingDevice::BuiltInDevice))
127  {
128  list.append(it->m_samplingDevice.displayedName);
129  indexes.push_back(it->m_index);
130  }
131  }
132 }
133 
134 void DeviceEnumerator::listMIMODeviceNames(QList<QString>& list, std::vector<int>& indexes) const
135 {
136  for (DevicesEnumeration::const_iterator it = m_mimoEnumeration.begin(); it != m_mimoEnumeration.end(); ++it)
137  {
138  if ((it->m_samplingDevice.claimed < 0) || (it->m_samplingDevice.type == PluginInterface::SamplingDevice::BuiltInDevice))
139  {
140  list.append(it->m_samplingDevice.displayedName);
141  indexes.push_back(it->m_index);
142  }
143  }
144 }
145 
146 void DeviceEnumerator::changeRxSelection(int tabIndex, int deviceIndex)
147 {
148  for (DevicesEnumeration::iterator it = m_rxEnumeration.begin(); it != m_rxEnumeration.end(); ++it)
149  {
150  if (it->m_samplingDevice.claimed == tabIndex) {
151  it->m_samplingDevice.claimed = -1;
152  }
153  if (it->m_index == deviceIndex) {
154  it->m_samplingDevice.claimed = tabIndex;
155  }
156  }
157 }
158 
159 void DeviceEnumerator::changeTxSelection(int tabIndex, int deviceIndex)
160 {
161  for (DevicesEnumeration::iterator it = m_txEnumeration.begin(); it != m_txEnumeration.end(); ++it)
162  {
163  if (it->m_samplingDevice.claimed == tabIndex) {
164  it->m_samplingDevice.claimed = -1;
165  }
166  if (it->m_index == deviceIndex) {
167  it->m_samplingDevice.claimed = tabIndex;
168  }
169  }
170 }
171 
172 void DeviceEnumerator::changeMIMOSelection(int tabIndex, int deviceIndex)
173 {
174  for (DevicesEnumeration::iterator it = m_mimoEnumeration.begin(); it != m_mimoEnumeration.end(); ++it)
175  {
176  if (it->m_samplingDevice.claimed == tabIndex) {
177  it->m_samplingDevice.claimed = -1;
178  }
179  if (it->m_index == deviceIndex) {
180  it->m_samplingDevice.claimed = tabIndex;
181  }
182  }
183 }
184 
186 {
187  for (DevicesEnumeration::iterator it = m_rxEnumeration.begin(); it != m_rxEnumeration.end(); ++it)
188  {
189  if (it->m_samplingDevice.claimed == tabIndex) {
190  it->m_samplingDevice.claimed = -1;
191  }
192  }
193 }
194 
196 {
197  for (DevicesEnumeration::iterator it = m_txEnumeration.begin(); it != m_txEnumeration.end(); ++it)
198  {
199  if (it->m_samplingDevice.claimed == tabIndex) {
200  it->m_samplingDevice.claimed = -1;
201  }
202  }
203 }
204 
206 {
207  for (DevicesEnumeration::iterator it = m_mimoEnumeration.begin(); it != m_mimoEnumeration.end(); ++it)
208  {
209  if (it->m_samplingDevice.claimed == tabIndex) {
210  it->m_samplingDevice.claimed = -1;
211  }
212  }
213 }
214 
216 {
217  for (DevicesEnumeration::const_iterator it = m_rxEnumeration.begin(); it != m_rxEnumeration.end(); ++it)
218  {
219  if (it->m_samplingDevice.id == PluginManager::getFileInputDeviceId()) {
220  return it->m_index;
221  }
222  }
223 
224  return -1;
225 }
226 
228 {
229  for (DevicesEnumeration::const_iterator it = m_txEnumeration.begin(); it != m_txEnumeration.end(); ++it)
230  {
231  if (it->m_samplingDevice.id == PluginManager::getFileSinkDeviceId()) {
232  return it->m_index;
233  }
234  }
235 
236  return -1;
237 }
238 
240 {
241  for (DevicesEnumeration::const_iterator it = m_mimoEnumeration.begin(); it != m_mimoEnumeration.end(); ++it)
242  {
243  if (it->m_samplingDevice.id == PluginManager::getTestMIMODeviceId()) {
244  return it->m_index;
245  }
246  }
247 
248  return -1;
249 }
250 
251 int DeviceEnumerator::getRxSamplingDeviceIndex(const QString& deviceId, int sequence)
252 {
253  for (DevicesEnumeration::iterator it = m_rxEnumeration.begin(); it != m_rxEnumeration.end(); ++it)
254  {
255  if ((it->m_samplingDevice.id == deviceId) && (it->m_samplingDevice.sequence == sequence)) {
256  return it->m_index;
257  }
258  }
259 
260  return -1;
261 }
262 
263 int DeviceEnumerator::getTxSamplingDeviceIndex(const QString& deviceId, int sequence)
264 {
265  for (DevicesEnumeration::iterator it = m_txEnumeration.begin(); it != m_txEnumeration.end(); ++it)
266  {
267  if ((it->m_samplingDevice.id == deviceId) && (it->m_samplingDevice.sequence == sequence)) {
268  return it->m_index;
269  }
270  }
271 
272  return -1;
273 }
274 
275 int DeviceEnumerator::getMIMOSamplingDeviceIndex(const QString& deviceId, int sequence)
276 {
277  for (DevicesEnumeration::iterator it = m_mimoEnumeration.begin(); it != m_mimoEnumeration.end(); ++it)
278  {
279  if ((it->m_samplingDevice.id == deviceId) && (it->m_samplingDevice.sequence == sequence)) {
280  return it->m_index;
281  }
282  }
283 
284  return -1;
285 }
void changeMIMOSelection(int tabIndex, int deviceIndex)
int getFileSinkDeviceIndex() const
Get Tx default device.
void enumerateTxDevices(PluginManager *pluginManager)
int getMIMOSamplingDeviceIndex(const QString &deviceId, int sequence)
static const QString & getFileSinkDeviceId()
Definition: pluginmanager.h:84
static const QString & getFileInputDeviceId()
Definition: pluginmanager.h:83
void listRxDeviceNames(QList< QString > &list, std::vector< int > &indexes) const
int getRxSamplingDeviceIndex(const QString &deviceId, int sequence)
void removeMIMOSelection(int tabIndex)
QList< SamplingDeviceRegistration > SamplingDeviceRegistrations
Definition: pluginapi.h:30
void changeTxSelection(int tabIndex, int deviceIndex)
void listTxDeviceNames(QList< QString > &list, std::vector< int > &indexes) const
static const QString & getTestMIMODeviceId()
Definition: pluginmanager.h:85
void removeRxSelection(int tabIndex)
DevicesEnumeration m_rxEnumeration
void enumerateMIMODevices(PluginManager *pluginManager)
int32_t i
Definition: decimators.h:244
void enumerateRxDevices(PluginManager *pluginManager)
int getTestMIMODeviceIndex() const
Get MIMO default device.
void changeRxSelection(int tabIndex, int deviceIndex)
void removeTxSelection(int tabIndex)
void listMIMODeviceNames(QList< QString > &list, std::vector< int > &indexes) const
PluginAPI::SamplingDeviceRegistrations & getSinkDeviceRegistrations()
Definition: pluginmanager.h:72
DevicesEnumeration m_txEnumeration
int getFileInputDeviceIndex() const
Get Rx default device.
int getTxSamplingDeviceIndex(const QString &deviceId, int sequence)
PluginAPI::SamplingDeviceRegistrations & getMIMODeviceRegistrations()
Definition: pluginmanager.h:73
PluginAPI::SamplingDeviceRegistrations & getSourceDeviceRegistrations()
Definition: pluginmanager.h:71
QList< SamplingDevice > SamplingDevices
DevicesEnumeration m_mimoEnumeration