GNU Radio's SDRPLAY Package
rsp_dev.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2018 HB9FXQ, Frank Werner-Krippendorf.
4  *
5  * This 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  * This software 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 this software; 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 
21 
22 #ifndef GR_SDRPLAY_RSP_DEV_H
23 #define GR_SDRPLAY_RSP_DEV_H
24 
25 #include <mirsdrapi-rsp.h>
26 #include <stdlib.h>
27 #include <string>
28 #include <vector>
29 #include <gnuradio/gr_complex.h>
30 #include <boost/thread/mutex.hpp>
31 #include <boost/thread/condition_variable.hpp>
32 
33 namespace gr {
34  namespace sdrplay {
35 
36  class rsp_dev {
37  public:
38  rsp_dev();
39 
40  ~rsp_dev();
41 
43 
44  double set_sample_rate(double rate);
45 
46  double get_sample_rate(void) const;
47 
48  double set_center_freq(double freq);
49 
50  double get_center_freq() const;
51 
52  bool set_gain_mode(bool automatic);
53 
54  bool get_gain_mode() const;
55 
56  double set_gain(double gain);
57 
58  double set_gain(double gain, const std::string &name);
59 
60  double get_gain() const;
61 
62  double get_gain(const std::string &name) const;
63 
64  std::string set_antenna(const std::string &antenna);
65 
66  std::string get_antenna() const;
67 
68  void set_dc_offset_mode(int mode);
69 
70  void set_iq_balance_mode(int mode);
71 
72  void set_debug_mode(int mode);
73 
74  double set_bandwidth(double bandwidth);
75 
76  double get_bandwidth() const;
77 
78  void startStreaming(void);
79 
80  void stopStreaming(void);
81 
82  int fetch_work_buffer(gr_complex *grWorkBuffer, int noutput_items);
83 
84  void set_if_type(int ifType);
85 
86  void set_lo_mode(int lo_mode);
87 
88  void set_biasT(bool biasT);
89 
90  void set_deviceIndexOrSerial(const std::string &deviceIndexOrSerial);
91 
92  private:
93  void reinitDevice(int reason);
94 
95  int checkLNA(int lna);
96 
97  void streamCallback(short *xi, short *xq, unsigned int firstSampleNum,
98  int grChanged, int rfChanged, int fsChanged,
99  unsigned int numSamples, unsigned int reset);
100 
101  void gainChangeCallback(unsigned int gRdB, unsigned int lnaGRdB);
102 
103  static void streamCallbackWrap(short *xi, short *xq, unsigned int firstSampleNum,
104  int grChanged, int rfChanged, int fsChanged,
105  unsigned int numSamples, unsigned int reset,
106  unsigned int hwRemoved, void *cbContext);
107 
108  static void gainChangeCallbackWrap(unsigned int gRdB, unsigned int lnaGRdB, void *cbContext);
109 
110  bool _auto_gain;
111  int _gRdB;
112  int _lna;
113  int _bcastNotch;
114  int _dabNotch;
115  double _fsHz;
116  int _decim;
117  double _rfHz;
118  mir_sdr_Bw_MHzT _bwType;
119  mir_sdr_If_kHzT _ifType;
120  mir_sdr_LoModeT _loMode;
121  int _samplesPerPacket;
122  bool _dcMode;
123  bool _iqMode;
124  bool _debug;
125  unsigned char _hwVer;
126  unsigned int _devIndex;
127  std::string _antenna;
128  int _biasT;
129  std::string _deviceIndexOrSerial;
130 
131  bool _streaming;
132  gr_complex *_buffer;
133  int _bufferOffset;
134  int _bufferSpaceRemaining;
135  boost::mutex _bufferMutex;
136  boost::condition_variable _bufferReady; // buffer is ready to move to other thread
137 
138  bool _reinit; // signal streamer to return after a reinit
139 
140  };
141  }
142 }
143 
144 
145 #endif //GR_SDRPLAY_RSP_DEV_H
void set_dc_offset_mode(int mode)
double set_sample_rate(double rate)
bool set_gain_mode(bool automatic)
double get_bandwidth() const
Definition: rsp_dev.h:36
void set_lo_mode(int lo_mode)
double get_sample_rate(void) const
double get_center_freq() const
std::string set_antenna(const std::string &antenna)
void set_iq_balance_mode(int mode)
void set_biasT(bool biasT)
double set_bandwidth(double bandwidth)
void set_deviceIndexOrSerial(const std::string &deviceIndexOrSerial)
Definition: rsp1_source.h:28
double set_gain(double gain)
int fetch_work_buffer(gr_complex *grWorkBuffer, int noutput_items)
double get_gain() const
void set_if_type(int ifType)
void stopStreaming(void)
void startStreaming(void)
std::string get_antenna() const
bool get_gain_mode() const
void list_available_rsp_devices()
double set_center_freq(double freq)