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.
hackrfoutputplugin.cpp
Go to the documentation of this file.
1 // Copyright (C) 2017 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 "libhackrf/hackrf.h"
20 
21 #include "plugin/pluginapi.h"
22 #include "util/simpleserializer.h"
23 
24 #ifdef SERVER_MODE
25 #include "hackrfoutput.h"
26 #else
27 #include "hackrfoutputgui.h"
28 #endif
29 #include "hackrfoutputplugin.h"
30 
32  QString("HackRF Output"),
33  QString("4.5.5"),
34  QString("(c) Edouard Griffiths, F4EXB"),
35  QString("https://github.com/f4exb/sdrangel"),
36  true,
37  QString("https://github.com/f4exb/sdrangel")
38 };
39 
40 const QString HackRFOutputPlugin::m_hardwareID = "HackRF";
42 
44  QObject(parent)
45 {
46 }
47 
49 {
50  return m_pluginDescriptor;
51 }
52 
54 {
55  pluginAPI->registerSampleSink(m_deviceTypeID, this);
56 }
57 
59 {
60 // hackrf_error rc = (hackrf_error) hackrf_init();
61 //
62 // if (rc != HACKRF_SUCCESS)
63 // {
64 // qCritical("HackRFOutputPlugin::enumSampleSinks: failed to initiate HackRF library: %s", hackrf_error_name(rc));
65 // }
66 
67  SamplingDevices result;
68  hackrf_device_list_t *hackrf_devices = hackrf_device_list();
69  hackrf_device *hackrf_ptr;
70  read_partid_serialno_t read_partid_serialno;
71  int i;
72 
73  for (i=0; i < hackrf_devices->devicecount; i++)
74  {
75  hackrf_error rc = (hackrf_error) hackrf_device_list_open(hackrf_devices, i, &hackrf_ptr);
76 
77  if (rc == HACKRF_SUCCESS)
78  {
79  qDebug("HackRFOutputPlugin::enumSampleSinks: try to enumerate HackRF device #%d", i);
80 
81  rc = (hackrf_error) hackrf_board_partid_serialno_read(hackrf_ptr, &read_partid_serialno);
82 
83  if (rc != HACKRF_SUCCESS)
84  {
85  qDebug("HackRFOutputPlugin::enumSampleSinks: failed to read serial no: %s", hackrf_error_name(rc));
86  hackrf_close(hackrf_ptr);
87  continue; // next
88  }
89 
90  uint32_t serial_msb = read_partid_serialno.serial_no[2];
91  uint32_t serial_lsb = read_partid_serialno.serial_no[3];
92 
93  QString serial_str = QString::number(serial_msb, 16) + QString::number(serial_lsb, 16);
94  //uint64_t serial_num = (((uint64_t) serial_msb)<<32) + serial_lsb;
95  QString displayedName(QString("HackRF[%1] %2").arg(i).arg(serial_str));
96 
97  result.append(SamplingDevice(displayedName,
100  serial_str,
101  i,
104  1,
105  0));
106 
107  qDebug("HackRFOutputPlugin::enumSampleSinks: enumerated HackRF device #%d", i);
108 
109  hackrf_close(hackrf_ptr);
110  }
111  else
112  {
113  qDebug("HackRFOutputPlugin::enumSampleSinks: failed to enumerate HackRF device #%d: %s", i, hackrf_error_name(rc));
114  }
115  }
116 
117  hackrf_device_list_free(hackrf_devices);
118 // rc = (hackrf_error) hackrf_exit();
119 // qDebug("HackRFOutputPlugin::enumSampleSinks: hackrf_exit: %s", hackrf_error_name(rc));
120 
121  return result;
122 }
123 
124 #ifdef SERVER_MODE
126  const QString& sinkId,
127  QWidget **widget,
128  DeviceUISet *deviceUISet)
129 {
130  (void) sinkId;
131  (void) widget;
132  (void) deviceUISet;
133  return 0;
134 }
135 #else
137  const QString& sinkId,
138  QWidget **widget,
139  DeviceUISet *deviceUISet)
140 {
141  if(sinkId == m_deviceTypeID)
142  {
143  HackRFOutputGui* gui = new HackRFOutputGui(deviceUISet);
144  *widget = gui;
145  return gui;
146  }
147  else
148  {
149  return 0;
150  }
151 }
152 #endif
153 
155 {
156  if(sinkId == m_deviceTypeID)
157  {
158  HackRFOutput* output = new HackRFOutput(deviceAPI);
159  return output;
160  }
161  else
162  {
163  return 0;
164  }
165 
166 }
167 
168 
HackRFOutputPlugin(QObject *parent=NULL)
void registerSampleSink(const QString &sinkName, PluginInterface *plugin)
Definition: pluginapi.cpp:24
static const QString m_hardwareID
static const PluginDescriptor m_pluginDescriptor
virtual DeviceSampleSink * createSampleSinkPluginInstance(const QString &sinkId, DeviceAPI *deviceAPI)
unsigned int uint32_t
Definition: rtptypes_win.h:46
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
const PluginDescriptor & getPluginDescriptor() const
int32_t i
Definition: decimators.h:244
Exposes a single output stream that can be one of the streams of a physical device.
#define HACKRFOUTPUT_DEVICE_TYPE_ID
virtual PluginInstanceGUI * createSampleSinkPluginInstanceGUI(const QString &sinkId, QWidget **widget, DeviceUISet *deviceUISet)
static const QString m_deviceTypeID
void initPlugin(PluginAPI *pluginAPI)
QList< SamplingDevice > SamplingDevices
virtual SamplingDevices enumSampleSinks()