-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSettings.cpp
470 lines (389 loc) · 15.5 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
// Copyright [2018] <Alexander Hurd>"
#include "SoapySidekiq.hpp"
std::vector<SoapySDR::Kwargs> SoapySidekiq::sidekiq_devices;
bool SoapySidekiq::rx_running;
SoapySidekiq::SoapySidekiq(const SoapySDR::Kwargs &args) {
// rx defaults
rx_sample_rate = 2048000;
rx_bandwidth = 2048000;
rx_center_frequency = 100000000;
// tx defaults
tx_sample_rate = 2048000;
tx_bandwidth = 2048000;
tx_center_frequency = 100000000;
iq_swap = false;
// this may change later according to format
shortsPerWord = 1;
bufferLength = bufferElems * elementsPerSample * shortsPerWord;
bufferedElems = 0;
_currentBuff = 0;
resetBuffer = false;
rx_running = true;
useShort = true;
if (args.count("card") != 0) {
try {
card = std::stoi(args.at("card"));
}
catch (const std::invalid_argument &) {
}
SoapySDR_logf(SOAPY_SDR_DEBUG, "Found Sidekiq Device using device index parameter 'card' = %d", card);
}
// Handle (TODO add to args)
rx_hdl = skiq_rx_hdl_A1;
tx_hdl = skiq_tx_hdl_A1;
skiq_xport_type_t type = skiq_xport_type_auto;
skiq_xport_init_level_t level = skiq_xport_init_level_full;
SoapySDR_logf(SOAPY_SDR_DEBUG, "Sidekiq opening card %d", card);
/* init sidekiq */
if (skiq_init(type, level, &card, 1) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_init (card %d)", card);
}
}
SoapySidekiq::~SoapySidekiq(void) {
if (skiq_exit() != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_exit", card);
}
}
/*******************************************************************
* Identification API
******************************************************************/
std::string SoapySidekiq::getDriverKey(void) const {
return "Sidekiq";
}
std::string SoapySidekiq::getHardwareKey(void) const {
return "Sidekiq";
}
SoapySDR::Kwargs SoapySidekiq::getHardwareInfo(void) const {
// key/value pairs for any useful information
// this also gets printed in --probe
SoapySDR::Kwargs args;
args["origin"] = "https://github.com/pothosware/SoapySidekiq";
args["card"] = std::to_string(card);
return args;
}
/*******************************************************************
* Channels API
******************************************************************/
size_t SoapySidekiq::getNumChannels(const int dir) const {
return 1;
}
/*******************************************************************
* Antenna API
******************************************************************/
std::vector<std::string> SoapySidekiq::listAntennas(const int direction, const size_t channel) const {
std::vector<std::string> antennas;
antennas.push_back("RX");
antennas.push_back("TX");
return antennas;
}
void SoapySidekiq::setAntenna(const int direction, const size_t channel, const std::string &name) {
SoapySDR::Device::setAntenna(direction, channel, name);
}
std::string SoapySidekiq::getAntenna(const int direction, const size_t channel) const {
return SoapySDR::Device::getAntenna(direction, channel);
}
/*******************************************************************
* Frontend corrections API
******************************************************************/
bool SoapySidekiq::hasDCOffsetMode(const int direction, const size_t channel) const {
return direction == SOAPY_SDR_RX;
}
void SoapySidekiq::setDCOffsetMode(const int direction, const size_t channel, const bool automatic) {
if (direction == SOAPY_SDR_RX) {
if (skiq_write_rx_dc_offset_corr(card, rx_hdl, automatic) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_write_rx_dc_offset_corr (card %d, enable %d)", card, automatic);
}
}
}
bool SoapySidekiq::getDCOffsetMode(const int direction, const size_t channel) const {
bool enable;
if (direction == SOAPY_SDR_RX) {
if (skiq_read_rx_dc_offset_corr(card, rx_hdl, &enable) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_rx_dc_offset_corr (card %d)", card);
}
return enable;
}
return SoapySDR::Device::getDCOffsetMode(direction, channel);
}
/*******************************************************************
* Gain API
******************************************************************/
std::vector<std::string> SoapySidekiq::listGains(const int direction, const size_t channel) const {
// list available gain elements,
std::vector<std::string> results;
return results;
}
bool SoapySidekiq::hasGainMode(const int direction, const size_t channel) const {
return true;
}
void SoapySidekiq::setGainMode(const int direction, const size_t channel, const bool automatic) {
if (direction == SOAPY_SDR_RX) {
SoapySDR_logf(SOAPY_SDR_DEBUG,
"Setting Sidekiq RX Gain Mode: %s",
automatic ? "skiq_rx_gain_auto" : "skiq_rx_gain_manual");
skiq_rx_gain_t mode = automatic ? skiq_rx_gain_auto : skiq_rx_gain_manual;
if (skiq_write_rx_gain_mode(card, rx_hdl, mode) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_write_rx_gain_mode (card %d, mode %d)", card, mode);
}
}
}
bool SoapySidekiq::getGainMode(const int direction, const size_t channel) const {
if (direction == SOAPY_SDR_RX) {
skiq_rx_gain_t p_gain_mode;
if (skiq_read_rx_gain_mode(card, rx_hdl, &p_gain_mode) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_rx_gain_mode (card %d)", card);
}
return p_gain_mode == skiq_rx_gain_auto;
}
return SoapySDR::Device::getGainMode(direction, channel);
}
void SoapySidekiq::setGain(const int direction, const size_t channel, const double value) {
if (direction == SOAPY_SDR_RX) {
if (skiq_write_rx_gain(card, rx_hdl, value) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_write_rx_gain (card %d, value %d)", card, value);
}
}
}
double SoapySidekiq::getGain(const int direction, const size_t channel) const {
if (direction == SOAPY_SDR_RX) {
uint8_t gain_index;
if (skiq_read_rx_gain(card, rx_hdl, &gain_index) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_rx_gain (card %d)", card);
}
return static_cast<double>(gain_index);
}
return SoapySDR::Device::getGain(direction, channel);
}
SoapySDR::Range SoapySidekiq::getGainRange(const int direction, const size_t channel, const std::string &name) const {
if (direction == SOAPY_SDR_RX) {
uint8_t gain_index_min;
uint8_t gain_index_max;
if (skiq_read_rx_gain_index_range(card, rx_hdl, &gain_index_min, &gain_index_max) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_rx_gain_index_range (card %d)", card);
}
return SoapySDR::Range(gain_index_max, gain_index_max);
}
return SoapySDR::Device::getGainRange(direction, channel, name);
}
/*******************************************************************
* Frequency API
******************************************************************/
void SoapySidekiq::setFrequency(const int direction,
const size_t channel,
const std::string &name,
const double frequency,
const SoapySDR::Kwargs &args) {
if (direction == SOAPY_SDR_RX && name == "RF") {
rx_center_frequency = (uint64_t) frequency;
resetBuffer = true;
SoapySDR_logf(SOAPY_SDR_DEBUG, "Setting rx center freq: %d", rx_center_frequency);
if (skiq_write_rx_LO_freq(card, rx_hdl, rx_center_frequency) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR,
"Failure: skiq_write_rx_LO_freq (card %d, frequency %d)",
card,
rx_center_frequency);
}
}
if (direction == SOAPY_SDR_TX && name == "RF") {
tx_center_frequency = (uint64_t) frequency;
resetBuffer = true;
SoapySDR_logf(SOAPY_SDR_DEBUG, "Setting tx center freq: %d", tx_center_frequency);
if (skiq_write_tx_LO_freq(card, tx_hdl, tx_center_frequency) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR,
"Failure: skiq_write_tx_LO_freq (card %d, frequency %d)",
card,
tx_center_frequency);
}
}
}
double SoapySidekiq::getFrequency(const int direction, const size_t channel, const std::string &name) const {
if (direction == SOAPY_SDR_RX && name == "RF") {
uint64_t freq;
double tuned_freq;
if (skiq_read_rx_LO_freq(card, rx_hdl, &freq, &tuned_freq) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_rx_LO_freq (card %d)", card);
}
return static_cast<double>(freq);
}
if (direction == SOAPY_SDR_TX && name == "RF") {
uint64_t freq;
double tuned_freq;
if (skiq_read_tx_LO_freq(card, tx_hdl, &freq, &tuned_freq) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_tx_LO_freq (card %d)", card);
}
return static_cast<double>(freq);
}
return 0;
}
std::vector<std::string> SoapySidekiq::listFrequencies(const int direction, const size_t channel) const {
std::vector<std::string> names;
names.push_back("RF");
return names;
}
SoapySDR::RangeList SoapySidekiq::getFrequencyRange(const int direction,
const size_t channel,
const std::string &name) const {
SoapySDR::RangeList results;
uint64_t max;
uint64_t min;
if (direction == SOAPY_SDR_RX && name == "RF") {
if (skiq_read_rx_LO_freq_range(card, &max, &min) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_rx_LO_freq_range (card %d)", card);
}
results.push_back(SoapySDR::Range(min, max));
}
if (direction == SOAPY_SDR_TX && name == "RF") {
if (skiq_read_tx_LO_freq_range(card, &max, &min) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_tx_LO_freq_range (card %d)", card);
}
results.push_back(SoapySDR::Range(min, max));
}
return results;
}
SoapySDR::ArgInfoList SoapySidekiq::getFrequencyArgsInfo(const int direction, const size_t channel) const {
SoapySDR::ArgInfoList freqArgs;
// TODO: frequency arguments
return freqArgs;
}
/*******************************************************************
* Sample Rate API
******************************************************************/
void SoapySidekiq::setSampleRate(const int direction, const size_t channel, const double rate) {
if (direction == SOAPY_SDR_RX) {
rx_sample_rate = (uint32_t) rate;
resetBuffer = true;
SoapySDR_logf(SOAPY_SDR_DEBUG, "Setting rx sample rate: %d", rx_sample_rate);
if (skiq_write_rx_sample_rate_and_bandwidth(card, rx_hdl, rx_sample_rate, rx_bandwidth) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR,
"Failure: skiq_write_rx_sample_rate_and_bandwidth (card %d, sample_rate %d, bandwidth %d)",
card,
rx_sample_rate,
rx_bandwidth);
}
}
if (direction == SOAPY_SDR_TX) {
tx_sample_rate = (uint32_t) rate;
resetBuffer = true;
SoapySDR_logf(SOAPY_SDR_DEBUG, "Setting tx sample rate: %d", tx_sample_rate);
if (skiq_write_tx_sample_rate_and_bandwidth(card, tx_hdl, tx_sample_rate, tx_bandwidth) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR,
"Failure: skiq_write_tx_sample_rate_and_bandwidth (card %d, sample_rate %d, bandwidth %d)",
card,
tx_sample_rate,
tx_bandwidth);
}
}
}
double SoapySidekiq::getSampleRate(const int direction, const size_t channel) const {
uint32_t rate;
double actual_rate;
if (direction == SOAPY_SDR_RX) {
if (skiq_read_rx_sample_rate(card, rx_hdl, &rate, &actual_rate) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_rx_sample_rate (card %d)", card);
}
return static_cast<double>(rate);
}
if (direction == SOAPY_SDR_TX) {
if (skiq_read_tx_sample_rate(card, tx_hdl, &rate, &actual_rate) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_tx_sample_rate (card %d)", card);
}
return static_cast<double>(rate);
}
return SoapySDR::Device::getSampleRate(direction, channel);
}
std::vector<double> SoapySidekiq::listSampleRates(const int direction, const size_t channel) const {
std::vector<double> results;
uint32_t min_sample_rate;
if (skiq_read_min_sample_rate(card, &min_sample_rate) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_min_sample_rate (card %d)", card);
}
uint32_t max_sample_rate;
if (skiq_read_max_sample_rate(card, &max_sample_rate) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_min_sample_rate (card %d)", card);
}
// iterate through all sample rates
uint32_t sample_rate = min_sample_rate;
while (sample_rate <= max_sample_rate) {
results.push_back(sample_rate);
sample_rate += 250000;
}
return results;
}
void SoapySidekiq::setBandwidth(const int direction, const size_t channel, const double bw) {
if (direction == SOAPY_SDR_RX) {
rx_bandwidth = (uint32_t) bw;
if (skiq_write_rx_sample_rate_and_bandwidth(card, rx_hdl, rx_sample_rate, rx_bandwidth) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR,
"Failure: skiq_write_rx_sample_rate_and_bandwidth (card %d, sample_rate %d, bandwidth %d)",
card,
rx_sample_rate,
rx_bandwidth);
}
}
if (direction == SOAPY_SDR_TX) {
tx_bandwidth = (uint32_t) bw;
if (skiq_write_tx_sample_rate_and_bandwidth(card, tx_hdl, tx_sample_rate, tx_bandwidth) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR,
"Failure: skiq_write_tx_sample_rate_and_bandwidth (card %d, sample_rate %d, bandwidth %d)",
card,
tx_sample_rate,
tx_bandwidth);
}
}
}
double SoapySidekiq::getBandwidth(const int direction, const size_t channel) const {
uint32_t rate;
double actual_rate;
uint32_t bandwidth;
uint32_t actual_bandwidth;
if (direction == SOAPY_SDR_RX) {
if (skiq_read_rx_sample_rate_and_bandwidth(card, rx_hdl, &rate, &actual_rate, &bandwidth, &actual_bandwidth) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_rx_sample_rate_and_bandwidth (card %d)", card);
}
}
if (direction == SOAPY_SDR_TX) {
if (skiq_read_tx_sample_rate_and_bandwidth(card, tx_hdl, &rate, &actual_rate, &bandwidth, &actual_bandwidth) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_tx_sample_rate_and_bandwidth (card %d)", card);
}
}
return bandwidth;
}
std::vector<double> SoapySidekiq::listBandwidths(const int direction, const size_t channel) const {
std::vector<double> bandwidths;
bandwidths.push_back(200000);
bandwidths.push_back(300000);
bandwidths.push_back(600000);
bandwidths.push_back(1536000);
bandwidths.push_back(5000000);
bandwidths.push_back(6000000);
bandwidths.push_back(7000000);
bandwidths.push_back(8000000);
return bandwidths;
}
/*******************************************************************
* Settings API
******************************************************************/
SoapySDR::ArgInfoList SoapySidekiq::getSettingInfo(void) const {
SoapySDR::ArgInfoList setArgs;
SoapySDR::ArgInfo iqSwapArg;
iqSwapArg.key = "iq_swap";
iqSwapArg.value = "false";
iqSwapArg.name = "I/Q Swap";
iqSwapArg.description = "I/Q Swap Mode";
iqSwapArg.type = SoapySDR::ArgInfo::BOOL;
setArgs.push_back(iqSwapArg);
return setArgs;
}
void SoapySidekiq::writeSetting(const std::string &key, const std::string &value) {
if (key == "iq_swap") {
iq_swap = ((value == "true") ? true : false);
SoapySDR_logf(SOAPY_SDR_DEBUG, "I/Q swap: %s", iq_swap ? "true" : "false");
}
}
std::string SoapySidekiq::readSetting(const std::string &key) const {
if (key == "iq_swap") {
return iq_swap ? "true" : "false";
}
SoapySDR_logf(SOAPY_SDR_WARNING, "Unknown setting '%s'", key.c_str());
return "";
}