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.
devicebladerf1.cpp
Go to the documentation of this file.
1 // Copyright (C) 2016-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 <QtGlobal>
19 
20 #include <cstdio>
21 #include <cstring>
22 
23 #include "devicebladerf1.h"
24 
25 bool DeviceBladeRF1::open_bladerf(struct bladerf **dev, const char *serial)
26 {
27  int fpga_loaded;
28 
29  if ((*dev = open_bladerf_from_serial(serial)) == 0)
30  {
31  qCritical("DeviceBladeRF::open_bladerf: could not open BladeRF");
32  return false;
33  }
34 
35  fpga_loaded = bladerf_is_fpga_configured(*dev);
36 
37  if (fpga_loaded < 0)
38  {
39  qCritical("DeviceBladeRF::open_bladerf: failed to check FPGA state: %s",
40  bladerf_strerror(fpga_loaded));
41  return false;
42  }
43  else if (fpga_loaded == 0)
44  {
45  qCritical("BladerfOutput::start: the device's FPGA is not loaded.");
46  return false;
47  }
48 
49  return true;
50 }
51 
52 struct bladerf *DeviceBladeRF1::open_bladerf_from_serial(const char *serial)
53 {
54  int status;
55  struct bladerf *dev;
56  struct bladerf_devinfo info;
57 
58  /* Initialize all fields to "don't care" wildcard values.
59  *
60  * Immediately passing this to bladerf_open_with_devinfo() would cause
61  * libbladeRF to open any device on any available backend. */
62  bladerf_init_devinfo(&info);
63 
64  /* Specify the desired device's serial number, while leaving all other
65  * fields in the info structure wildcard values */
66  if (serial != 0)
67  {
68  strncpy(info.serial, serial, BLADERF_SERIAL_LENGTH - 1);
69  info.serial[BLADERF_SERIAL_LENGTH - 1] = '\0';
70  }
71 
72  status = bladerf_open_with_devinfo(&dev, &info);
73 
74  if (status == BLADERF_ERR_NODEV)
75  {
76  qCritical("DeviceBladeRF::open_bladerf_from_serial: No devices available with serial %s", serial);
77  return 0;
78  }
79  else if (status != 0)
80  {
81  qCritical("DeviceBladeRF::open_bladerf_from_serial: Failed to open device with serial %s (%s)",
82  serial, bladerf_strerror(status));
83  return 0;
84  }
85  else
86  {
87  return dev;
88  }
89 }
90 
91 const unsigned int BladerfBandwidths::m_nb_halfbw = 16;
93  750,
94  875,
95  1250,
96  1375,
97  1500,
98  1920,
99  2500,
100  2750,
101  3000,
102  3500,
103  4375,
104  5000,
105  6000,
106  7000,
107  10000,
108  14000};
109 
110 unsigned int BladerfBandwidths::getBandwidth(unsigned int bandwidth_index)
111 {
112  if (bandwidth_index < m_nb_halfbw)
113  {
114  return m_halfbw[bandwidth_index] * 2;
115  }
116  else
117  {
118  return m_halfbw[0] * 2;
119  }
120 }
121 
122 unsigned int BladerfBandwidths::getBandwidthIndex(unsigned int bandwidth)
123 {
124  for (unsigned int i=0; i < m_nb_halfbw; i++)
125  {
126  if (bandwidth/2000 == m_halfbw[i])
127  {
128  return i;
129  }
130  }
131 
132  return 0;
133 }
134 
136 {
138 }
139 
static bool open_bladerf(struct bladerf **dev, const char *serial)
static struct bladerf * open_bladerf_from_serial(const char *serial)
static unsigned int getBandwidth(unsigned int bandwidth_index)
int32_t i
Definition: decimators.h:244
static const unsigned int m_nb_halfbw
static unsigned int getNbBandwidths()
static unsigned int getBandwidthIndex(unsigned int bandwidth)
static const unsigned int m_halfbw[]