-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoapyLeecher.hpp
132 lines (84 loc) · 4.24 KB
/
SoapyLeecher.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <SoapySDR/Device.hpp>
#include <SoapySDR/Registry.hpp>
#include <unistd.h>
#include <cstring> // memcpy
#include <clocale>
#include <complex>
#include <stdexcept>
#include <iostream>
#include <string>
#include <memory> // unique_ptr
#include <chrono>
#include <liquid/liquid.h>
#include "TimestampedSharedRingBuffer.hpp"
#include "SimpleSharedRingBuffer.hpp"
/***********************************************************************
* Device interface
**********************************************************************/
class SoapyLeecher : public SoapySDR::Device
{
public:
SoapyLeecher(const SoapySDR::Kwargs &args);
~SoapyLeecher();
void update_converter();
std::string getDriverKey(void) const;
std::string getHardwareKey(void) const;
SoapySDR::Kwargs getHardwareInfo(void) const;
size_t getNumChannels(const int dir) const;
bool getFullDuplex(const int direction, const size_t channel) const;
std::vector<std::string> getStreamFormats(const int direction, const size_t channel) const;
std::string getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const;
SoapySDR::Stream* setupStream(const int direction, const std::string &format,
const std::vector<size_t> &channels = std::vector<size_t>(),
const SoapySDR::Kwargs &args=SoapySDR::Kwargs());
void closeStream(SoapySDR::Stream *stream);
int activateStream(SoapySDR::Stream *stream, const int flags=0, const long long timeNs=0, const size_t numElems=0);
int deactivateStream(SoapySDR::Stream *stream, const int flags=0, const long long timeNs=0);
int readStream(SoapySDR::Stream *stream, void *const *buffs, const size_t numElems, int &flags, long long &timeNs, const long timeoutUs=100000);
int writeStream(SoapySDR::Stream *stream, const void *const *buffs, const size_t numElems, int &flags, const long long timeNs=0, const long timeoutUs=100000);
int readStreamStatus(SoapySDR::Stream *stream, size_t &chanMask, int &flags, long long &timeNs, const long timeoutUs=100000);
std::vector<std::string> listAntennas(const int direction, const size_t channel) const;
void setAntenna(const int direction, const size_t channel, const std::string &name);
std::string getAntenna(const int direction, const size_t channel) const;
void setFrequency(const int direction, const size_t channel, const double frequency, const SoapySDR::Kwargs &args=SoapySDR::Kwargs());
double getFrequency(const int direction, const size_t channel) const;
void setSampleRate(const int direction, const size_t channel, const double rate);
double getSampleRate(const int direction, const size_t channel) const;
SoapySDR::RangeList getSampleRateRange(const int direction, const size_t channel) const;
std::vector<double> listSampleRates(const int direction, const size_t channel) const;
void setBandwidth(const int direction, const size_t channel, const double bw);
double getBandwidth(const int direction, const size_t channel) const;
std::vector<double> listBandwidths(const int direction, const size_t channel) const;
SoapySDR::RangeList getBandwidthRange(const int direction, const size_t channel) const;
private:
int mix(void* const dst, const void* src, size_t numElems, size_t maxpro);
int resampledReadStream(SoapySDR::Stream *stream, void *const *buffs, const size_t numElems, int &flags, long long &timeNs, const long timeoutUs=100000);
void update_resampler();
void update_mixer();
std::string shm; // Shared memory buffer name
/*
* Args for receiving
*/
std::unique_ptr<SharedRingBuffer> rx_buffer;
double rx_frequency, rx_sample_rate;
double resampl_rate;
// DSP blocks
nco_crcf lo_nco;
resamp_crcf resampler;
/*
* Args for transmitting
*/
std::unique_ptr<SimpleSharedRingBuffer> tx_buffer;
double tx_frequency, tx_sample_rate;
};
/***********************************************************************
* Find available devices
**********************************************************************/
/*
* Try to find a shared memory buffer
*/
SoapySDR::KwargsList findLeecher(const SoapySDR::Kwargs &args);
/***********************************************************************
* Make device instance
**********************************************************************/
SoapySDR::Device *makeLeecher(const SoapySDR::Kwargs &args);