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.
devicehackrf.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 <stdio.h>
19 #include <QtGlobal>
20 #include "devicehackrf.h"
21 
23 {
24  hackrf_error rc = (hackrf_error) hackrf_init();
25 
26  if (rc != HACKRF_SUCCESS) {
27  qCritical("DeviceHackRF::open_hackrf: failed to initiate HackRF library %s", hackrf_error_name(rc));
28  }
29 }
30 
32 {
33  hackrf_exit();
34 }
35 
37 {
38  static DeviceHackRF inst;
39  return inst;
40 }
41 
42 hackrf_device *DeviceHackRF::open_hackrf(int sequence)
43 {
44  instance();
45 
46  return open_hackrf_from_sequence(sequence);
47 }
48 
49 hackrf_device *DeviceHackRF::open_hackrf(const char * const serial)
50 {
51  hackrf_error rc;
52  hackrf_device *hackrf_ptr;
53 
54  instance();
55 
56  rc = (hackrf_error) hackrf_open_by_serial(serial, &hackrf_ptr);
57 
58  if (rc == HACKRF_SUCCESS)
59  {
60  return hackrf_ptr;
61  }
62  else
63  {
64  qCritical("DeviceHackRF::open_hackrf: error #%d: %s", (int) rc, hackrf_error_name(rc));
65  return 0;
66  }
67 }
68 
69 hackrf_device *DeviceHackRF::open_hackrf_from_sequence(int sequence)
70 {
71  hackrf_device_list_t *hackrf_devices = hackrf_device_list();
72  hackrf_device *hackrf_ptr;
73  hackrf_error rc;
74 
75  instance();
76 
77  rc = (hackrf_error) hackrf_device_list_open(hackrf_devices, sequence, &hackrf_ptr);
78 
79  if (rc == HACKRF_SUCCESS)
80  {
81  return hackrf_ptr;
82  }
83  else
84  {
85  qCritical("DeviceHackRF::open_hackrf_from_sequence: error #%d: %s", (int) rc, hackrf_error_name(rc));
86  return 0;
87  }
88 }
89 
90 
91 
static DeviceHackRF & instance()
static hackrf_device * open_hackrf(int sequence)
static hackrf_device * open_hackrf_from_sequence(int sequence)