-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdrvSDR_Settings.cpp
593 lines (488 loc) · 15.4 KB
/
AdrvSDR_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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
#include "SoapyAdrvSDR.hpp"
SoapyAdrvSDR::SoapyAdrvSDR( const SoapySDR::Kwargs &args ): rx_stream(nullptr), tx_stream(nullptr)
{
if (args.count("label") != 0)
SoapySDR_logf(SOAPY_SDR_INFO, "Opening %s...", args.at("label").c_str());
try
{
udpc = UDPClient::findServer(stoi(args.at("cmdport")),stoi(args.at("strport")),args.at("hostname"),stoi(args.at("rxbuffersize"))*4,stoi(args.at("txbuffersize"))*4);
}
catch(runtime_error& re)
{
SoapySDR_logf(SOAPY_SDR_ERROR, re.what());
throw re;
}
phandler = (pluto_handler_t*) malloc(sizeof(pluto_handler_t));
bzero(phandler, sizeof(pluto_handler_t));
}
SoapyAdrvSDR::~SoapyAdrvSDR(void)
{
if(udpc)
{
delete(udpc);
udpc = nullptr;
}
if(phandler)
{
free(phandler);
phandler = NULL;
}
}
/*******************************************************************
* Identification API
******************************************************************/
std::string SoapyAdrvSDR::getDriverKey( void ) const
{
return "UDP";
}
std::string SoapyAdrvSDR::getHardwareKey( void ) const
{
return "ADRV9361-UDP";
}
SoapySDR::Kwargs SoapyAdrvSDR::getHardwareInfo( void ) const
{
SoapySDR::Kwargs info;
return info;
}
/*******************************************************************
* Channels API
******************************************************************/
size_t SoapyAdrvSDR::getNumChannels( const int dir ) const
{
return 1;
}
bool SoapyAdrvSDR::getFullDuplex( const int direction, const size_t channel ) const
{
return false;
}
/*******************************************************************
* Settings API
******************************************************************/
SoapySDR::ArgInfoList SoapyAdrvSDR::getSettingInfo(void) const
{
SoapySDR::ArgInfoList setArgs;
return setArgs;
}
void SoapyAdrvSDR::writeSetting(const std::string &key, const std::string &value)
{
return;
}
std::string SoapyAdrvSDR::readSetting(const std::string &key) const
{
std::string info;
return info;
}
/*******************************************************************
* Antenna API
******************************************************************/
std::vector<std::string> SoapyAdrvSDR::listAntennas( const int direction, const size_t channel ) const
{
std::vector<std::string> options;
if(direction == SOAPY_SDR_RX)
{
options.push_back( "A_BALANCED" );
options.push_back( "B_BALANCED" );
}
if(direction == SOAPY_SDR_TX)
{
options.push_back( "A" );
options.push_back( "B" );
}
return(options);
}
void SoapyAdrvSDR::setAntenna( const int direction, const size_t channel, const string &name )
{
string res;
if (direction == SOAPY_SDR_RX)
{
std::lock_guard<pluto_spin_mutex> lock(rx_device_mutex);
string req = string("set rx antenna ") + name;
res = udpc->sendCommand(req);
}
else if (direction == SOAPY_SDR_TX)
{
std::lock_guard<pluto_spin_mutex> lock(tx_device_mutex);
string req = string("set tx antenna ") + name;
res = udpc->sendCommand(req);
}
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
}
std::string SoapyAdrvSDR::getAntenna( const int direction, const size_t channel ) const
{
string res;
if (direction == SOAPY_SDR_RX)
{
string req = "get rx antenna";
res = udpc->sendCommand(req);
}
else if (direction == SOAPY_SDR_TX)
{
string req = "get tx antenna";
res = udpc->sendCommand(req);
}
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
return res;
}
/*******************************************************************
* Frontend corrections API
******************************************************************/
bool SoapyAdrvSDR::hasDCOffsetMode( const int direction, const size_t channel ) const
{
return true;
}
/*******************************************************************
* Gain API
******************************************************************/
std::vector<std::string> SoapyAdrvSDR::listGains( const int direction, const size_t channel ) const
{
std::vector<std::string> options;
options.push_back("PGA");
return options;
}
bool SoapyAdrvSDR::hasGainMode(const int direction, const size_t channel) const
{
if (direction == SOAPY_SDR_RX)
return true;
return false;
}
void SoapyAdrvSDR::setGainMode( const int direction, const size_t channel, const bool automatic )
{
string res;
if(direction==SOAPY_SDR_RX)
{
std::lock_guard<pluto_spin_mutex> lock(rx_device_mutex);
if (automatic)
{
string req = "set rx gainmode fast_attack";
res = udpc->sendCommand(req);
}
else
{
string req = "set rx gainmode manual";
res = udpc->sendCommand(req);
}
}
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
}
bool SoapyAdrvSDR::getGainMode(const int direction, const size_t channel) const
{
string res;
if (direction == SOAPY_SDR_RX)
{
string req = "get rx gainmode";
res = udpc->sendCommand(req);
}
else if (direction == SOAPY_SDR_TX)
{
string req = "get tx gainmode";
res = udpc->sendCommand(req);
}
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
if(res != "manual")
return true;
else
return false;
}
void SoapyAdrvSDR::setGain( const int direction, const size_t channel, const double value )
{
return;
string res;
int valueInt = (int)value;
if (direction == SOAPY_SDR_RX)
{
std::lock_guard<pluto_spin_mutex> lock(rx_device_mutex);
string req = string("set rx gain ") + to_string(valueInt);
res = udpc->sendCommand(req);
}
else if (direction == SOAPY_SDR_TX)
{
std::lock_guard<pluto_spin_mutex> lock(tx_device_mutex);
string req = string("set tx gain ") + to_string(valueInt-89);
res = udpc->sendCommand(req);
}
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
}
void SoapyAdrvSDR::setGain( const int direction, const size_t channel, const std::string &name, const double value )
{
this->setGain(direction,channel,value);
}
double SoapyAdrvSDR::getGain( const int direction, const size_t channel, const std::string &name ) const
{
return 50;
string res;
double gain;
if (direction == SOAPY_SDR_RX)
{
string req = "get rx gain";
res = udpc->sendCommand(req);
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
gain = double(stoi(res));
}
else if (direction == SOAPY_SDR_TX)
{
string req = "get tx gain";
res = udpc->sendCommand(req);
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
gain = double(stoi(res)+89);
}
return gain;
}
SoapySDR::Range SoapyAdrvSDR::getGainRange( const int direction, const size_t channel, const std::string &name ) const
{
if(direction==SOAPY_SDR_RX)
return(SoapySDR::Range(0, 73));
return(SoapySDR::Range(0,89));
}
/*******************************************************************
* Frequency API
******************************************************************/
void SoapyAdrvSDR::setFrequency( const int direction, const size_t channel, const std::string &name, const double frequency, const SoapySDR::Kwargs &args )
{
string res;
if (direction == SOAPY_SDR_RX)
{
// manual CFO compensation RX
// double frequencyn = frequency;
double frequencyn = frequency;
std::lock_guard<pluto_spin_mutex> lock(rx_device_mutex);
string req = string("set rx frequency ") + to_string((long long)frequencyn);
res = udpc->sendCommand(req);
}
else if (direction == SOAPY_SDR_TX)
{
// manual CFO compensation TX
//double frequencyn = frequency + 13000;
double frequencyn = frequency;
std::lock_guard<pluto_spin_mutex> lock(tx_device_mutex);
string req = string("set tx frequency ") + to_string((long long)frequencyn);
res = udpc->sendCommand(req);
}
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
}
double SoapyAdrvSDR::getFrequency( const int direction, const size_t channel, const std::string &name ) const
{
string res;
if (direction == SOAPY_SDR_RX)
{
string req = "get rx frequency";
res = udpc->sendCommand(req);
}
else if (direction == SOAPY_SDR_TX)
{
string req = "get tx frequency";
res = udpc->sendCommand(req);
}
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
return double(stoll(res));
}
SoapySDR::ArgInfoList SoapyAdrvSDR::getFrequencyArgsInfo(const int direction, const size_t channel) const
{
SoapySDR::ArgInfoList freqArgs;
return freqArgs;
}
std::vector<std::string> SoapyAdrvSDR::listFrequencies( const int direction, const size_t channel ) const
{
std::vector<std::string> names;
names.push_back( "RF" );
return(names);
}
SoapySDR::RangeList SoapyAdrvSDR::getFrequencyRange( const int direction, const size_t channel, const std::string &name ) const
{
return(SoapySDR::RangeList( 1, SoapySDR::Range( 70000000, 6000000000ull ) ) );
}
/*******************************************************************
* Hardware Timer API
******************************************************************/
void SoapyAdrvSDR::setTimerOffset(int64_t offset)
{
stringstream gstream;
gstream << offset;
string offset_str = gstream.str();
string req = "set tx timeroffset " + offset_str;
string res = udpc->sendCommand(req);
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
}
uint64_t SoapyAdrvSDR::getHWTimestamp() const
{
uint64_t val = 0;
string req = "get tx hwtimestamp";
string res = udpc->sendCommand(req);
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
istringstream iss(res);
iss >> val;
return val;
}
/*******************************************************************
* Sample Rate API
******************************************************************/
void SoapyAdrvSDR::setSampleRate( const int direction, const size_t channel, const double samplerate )
{
// manual SFO compensation
//double samplerateN = samplerate + 34;
double samplerateN = samplerate;
string res;
if(direction==SOAPY_SDR_RX)
{
std::lock_guard<pluto_spin_mutex> lock(rx_device_mutex);
if (samplerate<(25e6 / 48))
{
if (samplerate * 8 < (25e6 / 48))
SoapySDR_logf(SOAPY_SDR_ERROR, "sample rate is not supported.");
}
// FIXME
//string req = string("set rx samplerate ") + to_string((long long)samplerate);
//res = udpc->sendCommand(req);
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
phandler->rxSamplingFrequency = samplerate;
printf("[SoapyAdrv][setSampleRate] RX SamplingRate set to %llu \n",samplerate);
}
else if(direction==SOAPY_SDR_TX)
{
std::lock_guard<pluto_spin_mutex> lock(tx_device_mutex);
if (samplerate<(25e6 / 48))
{
if (samplerate * 8 < (25e6 / 48))
{
SoapySDR_logf(SOAPY_SDR_ERROR, "sample rate is not supported.");
}
}
// FIXME
//string req = string("set tx samplerate ") + to_string((long long)samplerateN);
//res = udpc->sendCommand(req);
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
phandler->txSamplingFrequency = samplerate;
printf("[SoapyAdrv][setSampleRate] TX SamplingRate set to %llu \n",samplerate);
}
// FIXME
// if(ad9361_set_bb_rate(dev,(unsigned long)samplerate))
// SoapySDR_logf(SOAPY_SDR_ERROR, "Unable to set BB rate.");
}
double SoapyAdrvSDR::getSampleRate( const int direction, const size_t channel ) const
{
return 1920000.0;
string res;
if (direction == SOAPY_SDR_RX)
{
string req = "get rx samplerate";
res = udpc->sendCommand(req);
}
else if (direction == SOAPY_SDR_TX)
{
string req = "get tx samplerate";
res = udpc->sendCommand(req);
}
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
return double(stoll(res));
}
std::vector<double> SoapyAdrvSDR::listSampleRates( const int direction, const size_t channel ) const
{
std::vector<double> options;
return(options);
}
/*******************************************************************
* Bandwidth API
******************************************************************/
void SoapyAdrvSDR::setBandwidth( const int direction, const size_t channel, const double bw )
{
string res;
if (direction == SOAPY_SDR_RX)
{
std::lock_guard<pluto_spin_mutex> lock(rx_device_mutex);
string req = string("set rx bandwidth ") + to_string((long long)bw);
res = udpc->sendCommand(req);
printf("[SoapyADRV][setBandwidth] RX bandwidth set to %llu \n",(long long)bw);
}
else if (direction == SOAPY_SDR_TX)
{
std::lock_guard<pluto_spin_mutex> lock(tx_device_mutex);
string req = string("set tx bandwidth ") + to_string((long long)bw);
res = udpc->sendCommand(req);
printf("[SoapyADRV][setBandwidth] TX bandwidth set to %llu \n",(long long)bw);
}
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
}
double SoapyAdrvSDR::getBandwidth( const int direction, const size_t channel ) const
{
string res;
if (direction == SOAPY_SDR_RX)
{
string req = "get rx bandwidth";
res = udpc->sendCommand(req);
}
else if (direction == SOAPY_SDR_TX)
{
string req = "get tx bandwidth";
res = udpc->sendCommand(req);
}
if(res.find("error") != string::npos)
{
SoapySDR_logf(SOAPY_SDR_ERROR, res.c_str());
throw runtime_error(res);
}
return double(stoll(res));
}
std::vector<double> SoapyAdrvSDR::listBandwidths( const int direction, const size_t channel ) const
{
std::vector<double> options;
return(options);
}