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.
hackrfinputplugin.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 
19 #include <QtPlugin>
20 #include "libhackrf/hackrf.h"
21 
22 #include "plugin/pluginapi.h"
23 #include "util/simpleserializer.h"
24 
25 #ifdef SERVER_MODE
26 #include "hackrfinput.h"
27 #else
28 #include "hackrfinputgui.h"
29 #endif
30 #include "hackrfinputplugin.h"
31 
33  QString("HackRF Input"),
34  QString("4.5.4"),
35  QString("(c) Edouard Griffiths, F4EXB"),
36  QString("https://github.com/f4exb/sdrangel"),
37  true,
38  QString("https://github.com/f4exb/sdrangel")
39 };
40 
41 const QString HackRFInputPlugin::m_hardwareID = "HackRF";
43 
45  QObject(parent)
46 {
47 }
48 
50 {
51  return m_pluginDescriptor;
52 }
53 
55 {
56  pluginAPI->registerSampleSource(m_deviceTypeID, this);
57 }
58 
60 {
62 // hackrf_error rc = (hackrf_error) hackrf_init();
63 //
64 // if (rc != HACKRF_SUCCESS)
65 // {
66 // qCritical("HackRFPlugin::SampleSourceDevices: failed to initiate HackRF library: %s", hackrf_error_name(rc));
67 // }
68 
69  SamplingDevices result;
70  hackrf_device_list_t *hackrf_devices = hackrf_device_list();
71  hackrf_device *hackrf_ptr;
72  read_partid_serialno_t read_partid_serialno;
73  int i;
74 
75  for (i=0; i < hackrf_devices->devicecount; i++)
76  {
77  hackrf_error rc = (hackrf_error) hackrf_device_list_open(hackrf_devices, i, &hackrf_ptr);
78 
79  if (rc == HACKRF_SUCCESS)
80  {
81  qDebug("HackRFPlugin::enumSampleSources: try to enumerate HackRF device #%d", i);
82 
83  rc = (hackrf_error) hackrf_board_partid_serialno_read(hackrf_ptr, &read_partid_serialno);
84 
85  if (rc != HACKRF_SUCCESS)
86  {
87  qDebug("HackRFPlugin::enumSampleSources: failed to read serial no: %s", hackrf_error_name(rc));
88  hackrf_close(hackrf_ptr);
89  continue; // next
90  }
91 
92  uint32_t serial_msb = read_partid_serialno.serial_no[2];
93  uint32_t serial_lsb = read_partid_serialno.serial_no[3];
94 
95  QString serial_str = QString::number(serial_msb, 16) + QString::number(serial_lsb, 16);
96  //uint64_t serial_num = (((uint64_t) serial_msb)<<32) + serial_lsb;
97  QString displayedName(QString("HackRF[%1] %2").arg(i).arg(serial_str));
98 
99  result.append(SamplingDevice(displayedName,
100  m_hardwareID,
102  serial_str,
103  i,
106  1,
107  0));
108 
109  qDebug("HackRFPlugin::enumSampleSources: enumerated HackRF device #%d", i);
110 
111  hackrf_close(hackrf_ptr);
112  }
113  else
114  {
115  qDebug("HackRFPlugin::enumSampleSources: failed to enumerate HackRF device #%d: %s", i, hackrf_error_name(rc));
116  }
117  }
118 
119  hackrf_device_list_free(hackrf_devices);
120 // rc = (hackrf_error) hackrf_exit();
121 // qDebug("HackRFPlugin::enumSampleSources: hackrf_exit: %s", hackrf_error_name(rc));
122 
123  return result;
124 }
125 
126 #ifdef SERVER_MODE
128  const QString& sourceId,
129  QWidget **widget,
130  DeviceUISet *deviceUISet)
131 {
132  (void) sourceId;
133  (void) widget;
134  (void) deviceUISet;
135  return 0;
136 }
137 #else
139  const QString& sourceId,
140  QWidget **widget,
141  DeviceUISet *deviceUISet)
142 {
143  if(sourceId == m_deviceTypeID)
144  {
145  HackRFInputGui* gui = new HackRFInputGui(deviceUISet);
146  *widget = gui;
147  return gui;
148  }
149  else
150  {
151  return 0;
152  }
153 }
154 #endif
155 
157 {
158  if (sourceId == m_deviceTypeID)
159  {
160  HackRFInput* input = new HackRFInput(deviceAPI);
161  return input;
162  }
163  else
164  {
165  return 0;
166  }
167 }
#define HACKRF_DEVICE_TYPE_ID
void registerSampleSource(const QString &sourceName, PluginInterface *plugin)
Definition: pluginapi.cpp:9
static DeviceHackRF & instance()
unsigned int uint32_t
Definition: rtptypes_win.h:46
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
virtual SamplingDevices enumSampleSources()
virtual DeviceSampleSource * createSampleSourcePluginInstance(const QString &sourceId, DeviceAPI *deviceAPI)
static const QString m_deviceTypeID
static const PluginDescriptor m_pluginDescriptor
int32_t i
Definition: decimators.h:244
void initPlugin(PluginAPI *pluginAPI)
virtual PluginInstanceGUI * createSampleSourcePluginInstanceGUI(const QString &sourceId, QWidget **widget, DeviceUISet *deviceUISet)
Exposes a single input stream that can be one of the streams of a physical device.
const PluginDescriptor & getPluginDescriptor() const
QList< SamplingDevice > SamplingDevices
HackRFInputPlugin(QObject *parent=NULL)
static const QString m_hardwareID