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.
limesdrinputplugin.cpp
Go to the documentation of this file.
1 // Copyright (C) 2015 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 <QtPlugin>
19 
20 #include <regex>
21 #include <string>
22 
23 #include "lime/LimeSuite.h"
24 #include "plugin/pluginapi.h"
25 #include "util/simpleserializer.h"
26 
27 #ifdef SERVER_MODE
28 #include "limesdrinput.h"
29 #else
30 #include "limesdrinputgui.h"
31 #endif
32 #include "limesdrinputplugin.h"
33 
35  QString("LimeSDR Input"),
36  QString("4.5.5"),
37  QString("(c) Edouard Griffiths, F4EXB"),
38  QString("https://github.com/f4exb/sdrangel"),
39  true,
40  QString("https://github.com/f4exb/sdrangel")
41 };
42 
43 const QString LimeSDRInputPlugin::m_hardwareID = "LimeSDR";
45 
47  QObject(parent)
48 {
49 }
50 
52 {
53  return m_pluginDescriptor;
54 }
55 
57 {
58  pluginAPI->registerSampleSource(m_deviceTypeID, this);
59 }
60 
62 {
63  lms_info_str_t* deviceList;
64  int nbDevices;
65  SamplingDevices result;
66 
67  if ((nbDevices = LMS_GetDeviceList(0)) <= 0)
68  {
69  qDebug("LimeSDRInputPlugin::enumSampleSources: Could not find any LimeSDR device");
70  return result; // empty result
71  }
72 
73  deviceList = new lms_info_str_t[nbDevices];
74 
75  if (LMS_GetDeviceList(deviceList) < 0)
76  {
77  qDebug("LimeSDRInputPlugin::enumSampleSources: Could not obtain LimeSDR devices information");
78  delete[] deviceList;
79  return result; // empty result
80  }
81  else
82  {
83  for (int i = 0; i < nbDevices; i++)
84  {
85  std::string serial("N/D");
86  findSerial((const char *) deviceList[i], serial);
87 
88  DeviceLimeSDRParams limeSDRParams;
89  limeSDRParams.open(deviceList[i]);
90  limeSDRParams.close();
91 
92  for (unsigned int j = 0; j < limeSDRParams.m_nbRxChannels; j++)
93  {
94  qDebug("LimeSDRInputPlugin::enumSampleSources: device #%d channel %u: %s", i, j, (char *) deviceList[i]);
95  QString displayedName(QString("LimeSDR[%1:%2] %3").arg(i).arg(j).arg(serial.c_str()));
96  result.append(SamplingDevice(displayedName,
99  QString(deviceList[i]),
100  i,
103  limeSDRParams.m_nbRxChannels,
104  j));
105  }
106  }
107  }
108 
109  delete[] deviceList;
110  return result;
111 }
112 
113 #ifdef SERVER_MODE
115  const QString& sourceId,
116  QWidget **widget,
117  DeviceUISet *deviceUISet)
118 {
119  (void) sourceId;
120  (void) widget;
121  (void) deviceUISet;
122  return 0;
123 }
124 #else
126  const QString& sourceId,
127  QWidget **widget,
128  DeviceUISet *deviceUISet)
129 {
130  if(sourceId == m_deviceTypeID)
131  {
132  LimeSDRInputGUI* gui = new LimeSDRInputGUI(deviceUISet);
133  *widget = gui;
134  return gui;
135  }
136  else
137  {
138  return 0;
139  }
140 }
141 #endif
142 
143 bool LimeSDRInputPlugin::findSerial(const char *lmsInfoStr, std::string& serial)
144 {
145  std::regex serial_reg("serial=([0-9,A-F]+)");
146  std::string input(lmsInfoStr);
147  std::smatch result;
148  std::regex_search(input, result, serial_reg);
149 
150  if (result[1].str().length()>0)
151  {
152  serial = result[1].str();
153  return true;
154  }
155  else
156  {
157  return false;
158  }
159 }
160 
162 {
163  if (sourceId == m_deviceTypeID)
164  {
165  LimeSDRInput* input = new LimeSDRInput(deviceAPI);
166  return input;
167  }
168  else
169  {
170  return 0;
171  }
172 }
173 
const PluginDescriptor & getPluginDescriptor() const
virtual DeviceSampleSource * createSampleSourcePluginInstance(const QString &sourceId, DeviceAPI *deviceAPI)
void initPlugin(PluginAPI *pluginAPI)
virtual PluginInstanceGUI * createSampleSourcePluginInstanceGUI(const QString &sourceId, QWidget **widget, DeviceUISet *deviceUISet)
void registerSampleSource(const QString &sourceName, PluginInterface *plugin)
Definition: pluginapi.cpp:9
uint32_t m_nbRxChannels
number of Rx channels (normally 2, we&#39;ll see if we really use it...)
static const PluginDescriptor m_pluginDescriptor
static const QString m_hardwareID
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
LimeSDRInputPlugin(QObject *parent=0)
int32_t i
Definition: decimators.h:244
static const QString m_deviceTypeID
virtual SamplingDevices enumSampleSources()
Exposes a single input stream that can be one of the streams of a physical device.
static bool findSerial(const char *lmsInfoStr, std::string &serial)
#define LIMESDR_DEVICE_TYPE_ID
bool open(lms_info_str_t deviceStr)
QList< SamplingDevice > SamplingDevices