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.
deviceplutosdrbox.h
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 #ifndef DEVICES_PLUTOSDR_DEVICEPLUTOSDRBOX_H_
19 #define DEVICES_PLUTOSDR_DEVICEPLUTOSDRBOX_H_
20 
21 #include <sstream>
22 #include <stdint.h>
23 #include <sys/types.h>
24 #include "deviceplutosdrscan.h"
25 
26 #include "export.h"
27 
28 #if defined(_MSC_VER)
29 #include <BaseTsd.h>
30 typedef SSIZE_T ssize_t;
31 #endif
32 
34 {
35 public:
36  typedef enum
37  {
40  DEVICE_TX
41  } DeviceType;
42 
43  typedef enum
44  {
46  USE_TX
47  } DeviceUse;
48 
49  struct Sample {
52  };
53 
54  struct SampleRates {
61  };
62 
66  float m_lpfFIRBW;
70 
71  DevicePlutoSDRBox(const std::string& uri);
73  bool isValid() const { return m_valid; }
74  static bool probeURI(const std::string& uri);
75 
76  void set_params(DeviceType devType, const std::vector<std::string> &params);
77  bool get_param(DeviceType devType, const std::string &param, std::string &value);
78  bool openRx();
79  bool openTx();
80  void closeRx();
81  void closeTx();
82  struct iio_buffer *createRxBuffer(unsigned int size, bool cyclic);
83  struct iio_buffer *createTxBuffer(unsigned int size, bool cyclic);
84  void deleteRxBuffer();
85  void deleteTxBuffer();
86  ssize_t getRxSampleSize();
87  ssize_t getTxSampleSize();
88  struct iio_channel *getRxChannel0() { return m_chnRx0; }
89  struct iio_channel *getTxChannel0I() { return m_chnTx0i; }
90  struct iio_channel *getTxChannel0Q() { return m_chnTx0q; }
91  ssize_t rxBufferRefill();
92  ssize_t txBufferPush();
93  std::ptrdiff_t rxBufferStep();
94  char* rxBufferEnd();
95  char* rxBufferFirst();
96  std::ptrdiff_t txBufferStep();
97  char* txBufferEnd();
98  char* txBufferFirst();
99  void txChannelConvert(int16_t *dst, int16_t *src);
100  bool getRxSampleRates(SampleRates& sampleRates);
101  bool getTxSampleRates(SampleRates& sampleRates);
102  void setSampleRate(uint32_t sampleRate);
103  void setFIR(uint32_t sampleRate, uint32_t intdec, DeviceUse use, uint32_t bw, int gain);
104  void setFIREnable(bool enable);
105  void setLOPPMTenths(int ppmTenths);
106  bool getRxGain(int& gaindB, unsigned int chan);
107  bool getRxRSSI(std::string& rssiStr, unsigned int chan);
108  bool getTxRSSI(std::string& rssiStr, unsigned int chan);
109  void getRxLORange(uint64_t& minLimit, uint64_t& maxLimit);
110  void getTxLORange(uint64_t& minLimit, uint64_t& maxLimit);
111  void getbbLPRxRange(uint32_t& minLimit, uint32_t& maxLimit);
112  void getbbLPTxRange(uint32_t& minLimit, uint32_t& maxLimit);
113  bool fetchTemp();
114  float getTemp() const { return m_temp; }
115  bool getRateGovernors(std::string& rateGovernors);
116 
117 private:
118  struct iio_context *m_ctx;
119  struct iio_device *m_devPhy;
120  struct iio_device *m_devRx;
121  struct iio_device *m_devTx;
122  struct iio_channel *m_chnRx0;
123  struct iio_channel *m_chnTx0i;
124  struct iio_channel *m_chnTx0q;
125  struct iio_buffer *m_rxBuf;
126  struct iio_buffer *m_txBuf;
127  bool m_valid;
129  float m_temp;
130 
131  bool parseSampleRates(const std::string& rateStr, SampleRates& sampleRates);
132  void setFilter(const std::string& filterConfigStr);
133  void formatFIRHeader(std::ostringstream& str, uint32_t intdec);
134  void formatFIRCoefficients(std::ostringstream& str, uint32_t nbTaps, double normalizedBW);
135  void getXO();
136 };
137 
138 #endif /* DEVICES_PLUTOSDR_DEVICEPLUTOSDRBOX_H_ */
short int16_t
Definition: rtptypes_win.h:43
struct iio_device * m_devTx
uint32_t m_lpfFIRlog2Decim
digital lowpass FIR filter log2 of decimation factor (0..2)
float m_lpfFIRBW
digital lowpass FIR filter bandwidth (Hz)
struct iio_channel * m_chnTx0i
__int64 int64_t
Definition: rtptypes_win.h:47
#define DEVICES_API
Definition: export.h:76
uint32_t m_hb3Rate
Rate of the HB3/(DEC3 or INT3) filter (Rx: out, Tx: in) - this is the HB2 working sample rate...
struct iio_buffer * m_txBuf
unsigned int uint32_t
Definition: rtptypes_win.h:46
bool m_lpfFIREnable
enable digital lowpass FIR filter
struct iio_channel * getRxChannel0()
struct iio_context * m_ctx
struct iio_channel * getTxChannel0I()
class DEVICES_API DevicePlutoSDRBox
uint64_t m_devSampleRate
Host interface sample rate.
int int32_t
Definition: rtptypes_win.h:45
struct iio_device * m_devPhy
bool isValid() const
struct iio_buffer * m_rxBuf
uint32_t m_firRate
Rate of FIR filter (Rx: out, Tx: in) - this is the host/device communication sample rate...
uint32_t m_hb2Rate
Rate of the HB2 filter (Rx: out, Tx: in) - this is the HB1 working sample rate.
int32_t m_LOppmTenths
XO correction.
struct iio_device * m_devRx
int m_lpfFIRRxGain
digital lowpass FIR filter gain Rx side (dB)
struct iio_channel * m_chnTx0q
uint32_t m_hb1Rate
Rate of the HB1 filter (Rx: out, Tx: in) - this is the FIR working sample rate.
uint32_t m_bbRateHz
Baseband PLL rate (Hz) - used internally.
float getTemp() const
struct iio_channel * m_chnRx0
uint32_t m_addaConnvRate
A/D or D/A converter rat - this is the HB3 working sample rate.
int m_lpfFIRTxGain
digital lowpass FIR filter gain Tx side (dB)
struct iio_channel * getTxChannel0Q()
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48