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.
limesdroutputplugin.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"
27 
28 #ifdef SERVER_MODE
29 #include "limesdroutput.h"
30 #else
31 #include "limesdroutputgui.h"
32 #endif
33 #include "limesdroutputplugin.h"
34 
36  QString("LimeSDR Output"),
37  QString("4.5.5"),
38  QString("(c) Edouard Griffiths, F4EXB"),
39  QString("https://github.com/f4exb/sdrangel"),
40  true,
41  QString("https://github.com/f4exb/sdrangel")
42 };
43 
44 const QString LimeSDROutputPlugin::m_hardwareID = "LimeSDR";
46 
48  QObject(parent)
49 {
50 }
51 
53 {
54  return m_pluginDescriptor;
55 }
56 
58 {
59  pluginAPI->registerSampleSink(m_deviceTypeID, this);
60 }
61 
63 {
64  lms_info_str_t* deviceList;
65  int nbDevices;
66  SamplingDevices result;
67 
68  if ((nbDevices = LMS_GetDeviceList(0)) <= 0)
69  {
70  qDebug("LimeSDROutputPlugin::enumSampleSources: Could not find any LimeSDR device");
71  return result; // empty result
72  }
73 
74  deviceList = new lms_info_str_t[nbDevices];
75 
76  if (LMS_GetDeviceList(deviceList) < 0)
77  {
78  qDebug("LimeSDROutputPlugin::enumSampleSources: Could not obtain LimeSDR devices information");
79  delete[] deviceList;
80  return result; // empty result
81  }
82  else
83  {
84  for (int i = 0; i < nbDevices; i++)
85  {
86  std::string serial("N/D");
87  findSerial((const char *) deviceList[i], serial);
88 
89  DeviceLimeSDRParams limeSDRParams;
90  limeSDRParams.open(deviceList[i]);
91  limeSDRParams.close();
92 
93  for (unsigned int j = 0; j < limeSDRParams.m_nbTxChannels; j++)
94  {
95  qDebug("LimeSDROutputPlugin::enumSampleSources: device #%d channel %u: %s", i, j, (char *) deviceList[i]);
96  QString displayedName(QString("LimeSDR[%1:%2] %3").arg(i).arg(j).arg(serial.c_str()));
97  result.append(SamplingDevice(displayedName,
100  QString(deviceList[i]),
101  i,
104  limeSDRParams.m_nbTxChannels,
105  j));
106  }
107  }
108  }
109 
110  delete[] deviceList;
111  return result;
112 }
113 
114 #ifdef SERVER_MODE
116  const QString& sinkId,
117  QWidget **widget,
118  DeviceUISet *deviceUISet)
119 {
120  (void) sinkId;
121  (void) widget;
122  (void) deviceUISet;
123  return 0;
124 }
125 #else
127  const QString& sinkId,
128  QWidget **widget,
129  DeviceUISet *deviceUISet)
130 {
131  if(sinkId == m_deviceTypeID)
132  {
133  LimeSDROutputGUI* gui = new LimeSDROutputGUI(deviceUISet);
134  *widget = gui;
135  return gui;
136  }
137  else
138  {
139  return 0;
140  }
141 }
142 #endif
143 
144 bool LimeSDROutputPlugin::findSerial(const char *lmsInfoStr, std::string& serial)
145 {
146  std::regex serial_reg("serial=([0-9,A-F]+)");
147  std::string input(lmsInfoStr);
148  std::smatch result;
149  std::regex_search(input, result, serial_reg);
150 
151  if (result[1].str().length()>0)
152  {
153  serial = result[1].str();
154  return true;
155  }
156  else
157  {
158  return false;
159  }
160 }
161 
163 {
164  if(sinkId == m_deviceTypeID)
165  {
166  LimeSDROutput* output = new LimeSDROutput(deviceAPI);
167  return output;
168  }
169  else
170  {
171  return 0;
172  }
173 }
174 
static bool findSerial(const char *lmsInfoStr, std::string &serial)
void registerSampleSink(const QString &sinkName, PluginInterface *plugin)
Definition: pluginapi.cpp:24
const PluginDescriptor & getPluginDescriptor() const
uint32_t m_nbTxChannels
number of Tx channels (normally 2, we&#39;ll see if we really use it...)
virtual PluginInstanceGUI * createSampleSinkPluginInstanceGUI(const QString &sinkId, QWidget **widget, DeviceUISet *deviceUISet)
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
static const QString m_hardwareID
static const PluginDescriptor m_pluginDescriptor
LimeSDROutputPlugin(QObject *parent=0)
#define LIMESDROUTPUT_DEVICE_TYPE_ID
virtual DeviceSampleSink * createSampleSinkPluginInstance(const QString &sinkId, DeviceAPI *deviceAPI)
int32_t i
Definition: decimators.h:244
static const QString m_deviceTypeID
virtual SamplingDevices enumSampleSinks()
Exposes a single output stream that can be one of the streams of a physical device.
bool open(lms_info_str_t deviceStr)
void initPlugin(PluginAPI *pluginAPI)
QList< SamplingDevice > SamplingDevices