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.
airspyplugin.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 #include <libairspy/airspy.h>
20 
21 #ifdef SERVER_MODE
22 #include "airspyinput.h"
23 #else
24 #include "airspygui.h"
25 #endif
26 #include "airspyplugin.h"
27 
28 #include "plugin/pluginapi.h"
29 #include "util/simpleserializer.h"
30 
31 const int AirspyPlugin::m_maxDevices = 32;
32 
34  QString("Airspy Input"),
35  QString("4.5.2"),
36  QString("(c) Edouard Griffiths, F4EXB"),
37  QString("https://github.com/f4exb/sdrangel"),
38  true,
39  QString("https://github.com/f4exb/sdrangel")
40 };
41 
42 const QString AirspyPlugin::m_hardwareID = "Airspy";
44 
45 AirspyPlugin::AirspyPlugin(QObject* parent) :
46  QObject(parent)
47 {
48 }
49 
51 {
52  return m_pluginDescriptor;
53 }
54 
56 {
57  pluginAPI->registerSampleSource(m_deviceTypeID, this);
58 }
59 
61 {
62  SamplingDevices result;
63  airspy_read_partid_serialno_t read_partid_serialno;
64  struct airspy_device *devinfo;
65  uint32_t serial_msb = 0;
66  uint32_t serial_lsb = 0;
67  airspy_error rc;
68  int i;
69 
70  rc = (airspy_error) airspy_init();
71 
72  if (rc != AIRSPY_SUCCESS)
73  {
74  qCritical("AirspyPlugin::enumSampleSources: failed to initiate Airspy library: %s", airspy_error_name(rc));
75  }
76 
77  for (i=0; i < m_maxDevices; i++)
78  {
79  rc = (airspy_error) airspy_open(&devinfo);
80 
81  if (rc == AIRSPY_SUCCESS)
82  {
83  qDebug("AirspyPlugin::enumSampleSources: try to enumerate Airspy device #%d", i);
84 
85  rc = (airspy_error) airspy_board_partid_serialno_read(devinfo, &read_partid_serialno);
86 
87  if (rc != AIRSPY_SUCCESS)
88  {
89  qDebug("AirspyPlugin::enumSampleSources: failed to read serial no: %s", airspy_error_name(rc));
90  airspy_close(devinfo);
91  continue; // next
92  }
93 
94  if ((read_partid_serialno.serial_no[2] != serial_msb) && (read_partid_serialno.serial_no[3] != serial_lsb))
95  {
96  serial_msb = read_partid_serialno.serial_no[2];
97  serial_lsb = read_partid_serialno.serial_no[3];
98 
99  QString serial_str = QString::number(serial_msb, 16) + QString::number(serial_lsb, 16);
100  //uint64_t serial_num = (((uint64_t) serial_msb)<<32) + serial_lsb;
101  QString displayedName(QString("Airspy[%1] %2").arg(i).arg(serial_str));
102 
103  result.append(SamplingDevice(displayedName,
104  m_hardwareID,
106  serial_str,
107  i,
110  1,
111  0));
112 
113  qDebug("AirspyPlugin::enumSampleSources: enumerated Airspy device #%d", i);
114  }
115 
116  airspy_close(devinfo);
117  }
118  else
119  {
120  qDebug("AirspyPlugin::enumSampleSources: enumerated %d Airspy devices %s", i, airspy_error_name(rc));
121  break; // finished
122  }
123  }
124 
125  rc = (airspy_error) airspy_exit();
126  qDebug("AirspyPlugin::enumSampleSources: airspy_exit: %s", airspy_error_name(rc));
127 
128  return result;
129 }
130 
131 #ifdef SERVER_MODE
133  const QString& sourceId,
134  QWidget **widget,
135  DeviceUISet *deviceUISet)
136 {
137  (void) sourceId;
138  (void) widget;
139  (void) deviceUISet;
140  return 0;
141 }
142 #else
144  const QString& sourceId,
145  QWidget **widget,
146  DeviceUISet *deviceUISet)
147 {
148  if (sourceId == m_deviceTypeID)
149  {
150  AirspyGui* gui = new AirspyGui(deviceUISet);
151  *widget = gui;
152  return gui;
153  }
154  else
155  {
156  return 0;
157  }
158 }
159 #endif
160 
162 {
163  if (sourceId == m_deviceTypeID)
164  {
165  AirspyInput* input = new AirspyInput(deviceAPI);
166  return input;
167  }
168  else
169  {
170  return 0;
171  }
172 }
void registerSampleSource(const QString &sourceName, PluginInterface *plugin)
Definition: pluginapi.cpp:9
const PluginDescriptor & getPluginDescriptor() const
static const int m_maxDevices
Definition: airspyplugin.h:48
static const PluginDescriptor m_pluginDescriptor
Definition: airspyplugin.h:51
unsigned int uint32_t
Definition: rtptypes_win.h:46
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
static const QString m_deviceTypeID
Definition: airspyplugin.h:47
AirspyPlugin(QObject *parent=NULL)
int32_t i
Definition: decimators.h:244
#define AIRSPY_DEVICE_TYPE_ID
Definition: airspyplugin.h:24
virtual DeviceSampleSource * createSampleSourcePluginInstance(const QString &sourceId, DeviceAPI *deviceAPI)
static const QString m_hardwareID
Definition: airspyplugin.h:46
Exposes a single input stream that can be one of the streams of a physical device.
void initPlugin(PluginAPI *pluginAPI)
virtual SamplingDevices enumSampleSources()
QList< SamplingDevice > SamplingDevices
virtual PluginInstanceGUI * createSampleSourcePluginInstanceGUI(const QString &sourceId, QWidget **widget, DeviceUISet *deviceUISet)