GNU Radio's TEST Package
hackrf_common.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2020 Clayton Smith <argilo@gmail.com>
4 *
5 * gr-osmosdr is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3, or (at your option)
8 * any later version.
9 *
10 * gr-osmosdr is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with gr-osmosdr; see the file COPYING. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street,
18 * Boston, MA 02110-1301, USA.
19 */
20#ifndef INCLUDED_HACKRF_COMMON_H
21#define INCLUDED_HACKRF_COMMON_H
22
23#include <map>
24#include <memory>
25#include <mutex>
26#include <string>
27#include <vector>
28
29#include <boost/format.hpp>
30
31#include <osmosdr/ranges.h>
32#include <libhackrf/hackrf.h>
33
34#define BUF_LEN (16 * 32 * 512) /* must be multiple of 512 */
35#define BUF_NUM 15
36
37#define BYTES_PER_SAMPLE 2 /* HackRF device produces/consumes 8 bit signed IQ data */
38
39#define HACKRF_FORMAT_ERROR(ret, msg) \
40 boost::str( boost::format(msg " (%1%) %2%") \
41 % ret % hackrf_error_name((enum hackrf_error)ret) )
42
43#define HACKRF_THROW_ON_ERROR(ret, msg) \
44 if ( ret != HACKRF_SUCCESS ) \
45 { \
46 throw std::runtime_error( HACKRF_FORMAT_ERROR(ret, msg) ); \
47 }
48
49#define HACKRF_FUNC_STR(func, arg) \
50 boost::str(boost::format(func "(%1%)") % arg) + " has failed"
51
52typedef std::shared_ptr<hackrf_device> hackrf_sptr;
53
55{
56public:
57 hackrf_common(const std::string &args);
58
59protected:
60 static std::vector< std::string > get_devices();
61
63 double set_sample_rate( double rate );
64 double get_sample_rate( void );
65
67 double set_center_freq( double freq, size_t chan = 0 );
68 double get_center_freq( size_t chan = 0 );
69 double set_freq_corr( double ppm, size_t chan = 0 );
70 double get_freq_corr( size_t chan = 0 );
71
72 bool set_gain_mode( bool automatic, size_t chan = 0 );
73 bool get_gain_mode( size_t chan = 0 );
74 double set_gain( double gain, size_t chan = 0 );
75 double get_gain( size_t chan = 0 );
76
77 std::vector< std::string > get_antennas( size_t chan = 0 );
78 std::string set_antenna( const std::string & antenna, size_t chan = 0 );
79 std::string get_antenna( size_t chan = 0 );
80
81 double set_bandwidth( double bandwidth, size_t chan = 0 );
82 double get_bandwidth( size_t chan = 0 );
84
85 bool set_bias( bool bias );
86 bool get_bias();
87
88 void start();
89 void stop();
90
91 hackrf_sptr _dev;
92
93private:
94 static void close(void *dev);
95
96 static int _usage;
97 static std::mutex _usage_mutex;
98
99 static std::map<std::string, std::weak_ptr<hackrf_device>> _devs;
100 static std::mutex _devs_mutex;
101
102 double _sample_rate;
103 double _center_freq;
104 double _freq_corr;
105 bool _auto_gain;
106 double _amp_gain;
107 double _requested_bandwidth;
108 double _bandwidth;
109 bool _bias;
110 bool _started;
111};
112
113#endif /* INCLUDED_HACKRF_COMMON_H */
Definition: hackrf_common.h:55
hackrf_common(const std::string &args)
std::string set_antenna(const std::string &antenna, size_t chan=0)
std::vector< std::string > get_antennas(size_t chan=0)
double set_sample_rate(double rate)
double get_center_freq(size_t chan=0)
bool set_bias(bool bias)
osmosdr::meta_range_t get_sample_rates(void)
double get_freq_corr(size_t chan=0)
double get_bandwidth(size_t chan=0)
double set_freq_corr(double ppm, size_t chan=0)
double set_bandwidth(double bandwidth, size_t chan=0)
double set_center_freq(double freq, size_t chan=0)
std::string get_antenna(size_t chan=0)
static std::vector< std::string > get_devices()
bool set_gain_mode(bool automatic, size_t chan=0)
double get_gain(size_t chan=0)
double get_sample_rate(void)
bool get_gain_mode(size_t chan=0)
double set_gain(double gain, size_t chan=0)
hackrf_sptr _dev
Definition: hackrf_common.h:91
osmosdr::freq_range_t get_freq_range(size_t chan=0)
osmosdr::freq_range_t get_bandwidth_range(size_t chan=0)
Definition: ranges.h:75