-
Notifications
You must be signed in to change notification settings - Fork 2
/
Settings.cpp
270 lines (221 loc) · 6.89 KB
/
Settings.cpp
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include "SoapyRX888.hpp"
#include <SoapySDR/Time.hpp>
#include <SoapySDR/Types.hpp>
#include <algorithm>
SoapyRX888::SoapyRX888(const SoapySDR::Kwargs &args):
deviceId(-1),
dev(nullptr),
rxFormat(RX888_RX_FORMAT_INT16),
sampleRate(64000000),
numBuffers(DEFAULT_NUM_BUFFERS)
{
if (args.count("label") != 0) SoapySDR_logf(SOAPY_SDR_INFO, "Opening %s...", args.at("label").c_str());
//if a serial is not present, then findRX888 had zero devices enumerated
if (args.count("serial") == 0) throw std::runtime_error("No RX888 devices found!");
const auto serial = args.at("serial");
deviceId = rx888_get_index_by_serial(serial.c_str());
if (deviceId < 0) throw std::runtime_error("rx888_get_index_by_serial("+serial+") - " + std::to_string(deviceId));
SoapySDR_logf(SOAPY_SDR_DEBUG, "RX888 opening device %d", deviceId);
if (rx888_open(&dev, deviceId) != 0) {
throw std::runtime_error("Unable to open RX888 device");
}
}
SoapyRX888::~SoapyRX888(void)
{
//cleanup device handles
rx888_close(dev);
}
/*******************************************************************
* Identification API
******************************************************************/
std::string SoapyRX888::getDriverKey(void) const
{
return "RX888";
}
std::string SoapyRX888::getHardwareKey(void) const
{
return "RX888";
}
SoapySDR::Kwargs SoapyRX888::getHardwareInfo(void) const
{
//key/value pairs for any useful information
//this also gets printed in --probe
SoapySDR::Kwargs args;
args["origin"] = "https://github.com/cozycactus/SoapyRX888";
args["index"] = std::to_string(deviceId);
return args;
}
/*******************************************************************
* Channels API
******************************************************************/
size_t SoapyRX888::getNumChannels(const int dir) const
{
return (dir == SOAPY_SDR_RX) ? 1 : 0;
}
bool SoapyRX888::getFullDuplex(const int direction, const size_t channel) const
{
(void)direction;
(void)channel;
return false;
}
/*******************************************************************
* Antenna API
******************************************************************/
std::vector<std::string> SoapyRX888::listAntennas(const int direction, const size_t channel) const
{
(void)direction;
(void)channel;
std::vector<std::string> antennas;
antennas.push_back("RX");
return antennas;
}
void SoapyRX888::setAntenna(const int direction, const size_t channel, const std::string &name)
{
(void)channel;
(void)name;
if (direction != SOAPY_SDR_RX)
{
throw std::runtime_error("setAntena failed: RX888 only supports RX");
}
}
std::string SoapyRX888::getAntenna(const int direction, const size_t channel) const
{
(void)channel;
(void)direction;
return "RX";
}
/*******************************************************************
* Frontend corrections API
******************************************************************/
bool SoapyRX888::hasDCOffsetMode(const int direction, const size_t channel) const
{
(void)direction;
(void)channel;
return false;
}
bool SoapyRX888::hasFrequencyCorrection(const int direction, const size_t channel) const
{
(void)direction;
(void)channel;
return false;
}
/*******************************************************************
* Gain API
******************************************************************/
std::vector<std::string> SoapyRX888::listGains(const int direction, const size_t channel) const
{
(void)direction;
(void)channel;
std::vector<std::string> gains;
gains.push_back("RF");
return gains;
}
bool SoapyRX888::hasGainMode(const int direction, const size_t channel) const
{
(void)direction;
(void)channel;
return false;
}
void SoapyRX888::setGain(const int direction, const size_t channel, const std::string &name, const double value)
{
(void)direction;
(void)channel;
if (name == "RF")
{
rx888_set_hf_attenuation(dev, value);
}
}
SoapySDR::Range SoapyRX888::getGainRange(const int direction, const size_t channel, const std::string &name) const
{
(void)direction;
(void)channel;
if (name == "RF")
{
return SoapySDR::Range(-20.0, 0, 10.0);
} else {
return SoapySDR::Range(0, 0);
}
return SoapySDR::Range(0, 0);
}
SoapySDR::ArgInfoList SoapyRX888::getFrequencyArgsInfo(const int direction, const size_t channel) const
{
(void)direction;
(void)channel;
SoapySDR::ArgInfoList freqArgs;
// TODO: frequency arguments
return freqArgs;
}
/*******************************************************************
* Sample Rate API
******************************************************************/
void SoapyRX888::setSampleRate(const int direction, const size_t channel, const double rate)
{
(void)direction;
(void)channel;
long long ns = SoapySDR::ticksToTimeNs(ticks, sampleRate);
sampleRate = rate;
resetBuffer = true;
SoapySDR_logf(SOAPY_SDR_DEBUG, "Setting sample rate: %d", sampleRate);
int r = rx888_set_sample_rate(dev, sampleRate);
if (r == -EINVAL)
{
throw std::runtime_error("setSampleRate failed: RX888 does not support this sample rate");
}
if (r != 0)
{
throw std::runtime_error("setSampleRate failed");
}
sampleRate = rx888_get_sample_rate(dev);
ticks = SoapySDR::timeNsToTicks(ns, sampleRate);
}
double SoapyRX888::getSampleRate(const int direction, const size_t channel) const
{
(void)direction;
(void)channel;
return sampleRate;
}
std::vector<double> SoapyRX888::listSampleRates(const int direction, const size_t channel) const
{
(void)direction;
(void)channel;
std::vector<double> results;
results.push_back(250000);
results.push_back(500000);
results.push_back(1000000);
results.push_back(2000000);
results.push_back(4000000);
results.push_back(8000000);
results.push_back(16000000);
results.push_back(32000000);
results.push_back(64000000);
results.push_back(128000000);
results.push_back(150000000);
return results;
}
/*******************************************************************
* Time API
******************************************************************/
std::vector<std::string> SoapyRX888::listTimeSources(void) const
{
std::vector<std::string> results;
results.push_back("sw_ticks");
return results;
}
std::string SoapyRX888::getTimeSource(void) const
{
return "sw_ticks";
}
bool SoapyRX888::hasHardwareTime(const std::string &what) const
{
return what == "" || what == "sw_ticks";
}
long long SoapyRX888::getHardwareTime(const std::string &what) const
{
(void)what;
return SoapySDR::ticksToTimeNs(ticks, sampleRate);
}
void SoapyRX888::setHardwareTime(const long long timeNs, const std::string &what)
{
(void)what;
ticks = SoapySDR::timeNsToTicks(timeNs, sampleRate);
}