-
Notifications
You must be signed in to change notification settings - Fork 42
/
sdrplayd.c
1570 lines (1429 loc) · 60.1 KB
/
sdrplayd.c
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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Read from SDRplay SDR using SDRplay API version 3.x
// Accept control commands from UDP socket
// Written by K4VZ July 2020, adapted from existing KA9Q SDR handler programs
#define _GNU_SOURCE 1
#include <assert.h>
#include <pthread.h>
#include <string.h>
#if defined(linux)
#include <bsd/string.h>
#endif
#include <complex.h>
#include <math.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <signal.h>
#include <locale.h>
#include <sys/time.h>
#include <sdrplay_api.h>
#include <sys/resource.h>
#include <errno.h>
#include <syslog.h>
#include <sys/stat.h>
#include <getopt.h>
#include <iniparser.h>
#include "conf.h"
#include "misc.h"
#include "multicast.h"
#include "decimate.h"
#include "status.h"
#include "config.h"
// Configurable parameters
// decibel limits for power
float const AGC_upper = -20;
float const AGC_lower = -50;
int const Bufsize = 65536; // should pick more deterministically
#define BUFFERSIZE (1<<21) // Upcalls seem to be 256KB; don't make too big or we may blow out of the cache
// Global variables set by config file options
char const *Iface;
char *Locale;
int RTP_ttl;
int Status_ttl;
int IP_tos;
const char *App_path;
int Verbose;
static int Terminate;
// SDRplay device status
enum sdrplay_status {
NOT_INITIALIZED = 0,
SDRPLAY_API_OPEN = 1,
DEVICE_API_LOCKED = 2,
DEVICE_SELECTED = 4,
DEVICE_STREAMING = 8
};
struct sdrstate {
sdrplay_api_DeviceT device;
sdrplay_api_DeviceParamsT *device_params;
sdrplay_api_RxChannelParamsT *rx_channel_params;
enum sdrplay_status device_status;
char const *description;
// Tuning
int frequency_lock;
char *frequency_file; // Local file to store frequency in case we restart
// Sample statistics
uint64_t sample_count;
uint64_t event_count;
int clips; // Sample clips since last reset (???)
float power; // Running estimate of A/D signal power (???)
unsigned int next_sample_num;
int blocksize;// Number of samples per packet
complex int16_t *samples; // samples buffer
FILE *status; // Real-time display in /run (currently unused)
// Multicast I/O
char const *metadata_dest;
struct sockaddr_storage output_metadata_dest_address;
uint64_t output_metadata_packets;
int status_sock; // Socket handle for outgoing status messages
int nctl_sock; // Socket handle for incoming commands (same socket as status)
uint64_t commands; // Command counter
uint32_t command_tag; // Last received command tag
char const *data_dest;
struct sockaddr_storage output_data_source_address; // Multicast output socket
struct sockaddr_storage output_data_dest_address; // Multicast output socket
int data_sock; // Socket handle for sending real time stream
struct rtp_state rtp; // Real time protocol (RTP) state
int rtp_type; // RTP type to indicate sample rate, etc (should be rethought)
pthread_t display_thread;
pthread_t ncmd_thread;
};
static struct option Options[] =
{
{"verbose", no_argument, NULL, 'v'},
{"config",required_argument,NULL,'f'},
{NULL, 0, NULL, 0},
};
static char const Optstring[] = "f:v";
// SDRplay specific constants, data structures, and functions
static const sdrplay_api_DbgLvl_t dbgLvl = sdrplay_api_DbgLvl_Disable;
//static const sdrplay_api_DbgLvl_t dbgLvl = sdrplay_api_DbgLvl_Verbose;
static const double MIN_SAMPLE_RATE = 2e6;
static const double MAX_SAMPLE_RATE = 10.66e6;
static const int MAX_DECIMATION = 32;
// Taken from SDRplay API Specification Guide (Gain Reduction Tables)
uint8_t rsp1_0_420_lna_states[] = { 0, 24, 19, 43 };
uint8_t rsp1_420_1000_lna_states[] = { 0, 7, 19, 26 };
uint8_t rsp1_1000_2000_lna_states[] = { 0, 5, 19, 24 };
uint8_t rsp1a_0_60_lna_states[] = { 0, 6, 12, 18, 37, 42, 61 };
uint8_t rsp1a_60_420_lna_states[] = { 0, 6, 12, 18, 20, 26, 32, 38, 57, 62 };
uint8_t rsp1a_420_1000_lna_states[] = { 0, 7, 13, 19, 20, 27, 33, 39, 45, 64 };
uint8_t rsp1a_1000_2000_lna_states[] = { 0, 6, 12, 20, 26, 32, 38, 43, 62 };
uint8_t rsp2_0_420_lna_states[] = { 0, 10, 15, 21, 24, 34, 39, 45, 64 };
uint8_t rsp2_420_1000_lna_states[] = { 0, 7, 10, 17, 22, 41 };
uint8_t rsp2_1000_2000_lna_states[] = { 0, 5, 21, 15, 15, 34 };
uint8_t rsp2_0_60_hiz_lna_states[] = { 0, 6, 12, 18, 37 };
uint8_t rspduo_0_60_lna_states[] = { 0, 6, 12, 18, 37, 42, 61 };
uint8_t rspduo_60_420_lna_states[] = { 0, 6, 12, 18, 20, 26, 32, 38, 57, 62 };
uint8_t rspduo_420_1000_lna_states[] = { 0, 7, 13, 19, 20, 27, 33, 39, 45, 64 };
uint8_t rspduo_1000_2000_lna_states[] = { 0, 6, 12, 20, 26, 32, 38, 43, 62 };
uint8_t rspduo_0_60_hiz_lna_states[] = { 0, 6, 12, 18, 37 };
uint8_t rspdx_0_2_hdr_lna_states[] = { 0, 3, 6, 9, 12, 15, 18, 21, 24, 25, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60 };
uint8_t rspdx_0_12_lna_states[] = { 0, 3, 6, 9, 12, 15, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60 };
uint8_t rspdx_12_60_lna_states[] = { 0, 3, 6, 9, 12, 15, 18, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60 };
uint8_t rspdx_60_250_lna_states[] = { 0, 3, 6, 9, 12, 15, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84 };
uint8_t rspdx_250_420_lna_states[] = { 0, 3, 6, 9, 12, 15, 18, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84 };
uint8_t rspdx_420_1000_lna_states[] = { 0, 7, 10, 13, 16, 19, 22, 25, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61, 64, 67 };
uint8_t rspdx_1000_2000_lna_states[] = { 0, 5, 8, 11, 14, 17, 20, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62, 65 };
// SDRplay specific functions
static int init_api(struct sdrstate *sdr);
static int find_rsp(struct sdrstate *sdr,char const *sn);
static int set_rspduo_mode(struct sdrstate *sdr,char const *mode,char const *antenna);
static int select_device(struct sdrstate *sdr);
static int set_center_freq(struct sdrstate *sdr,double const frequency);
static int set_ifreq(struct sdrstate *sdr,int const ifreq);
static int set_bandwidth(struct sdrstate *sdr,int const bandwidth,double const samprate);
static int set_samplerate(struct sdrstate *sdr,double const samprate);
static double get_samplerate(struct sdrstate *sdr);
static int set_antenna(struct sdrstate *sdr,char const *antenna);
static int set_rf_gain(struct sdrstate *sdr,int const lna_state,int const rf_att,int const rf_gr,double const frequency);
static int set_if_gain(struct sdrstate *sdr,int const if_att,int const if_gr,int const if_agc,int const if_agc_rate,int const if_agc_setPoint_dBfs,int const if_agc_attack_ms,int const if_agc_decay_ms,int const if_agc_decay_delay_ms,int const if_agc_decay_threshold_dB);
static int set_dc_offset_iq_imbalance_correction(struct sdrstate *sdr,int const dc_offset_corr,int const iq_imbalance_corr);
static int set_bulk_transfer_mode(struct sdrstate *sdr,int const transfer_mode_bulk);
static int set_notch_filters(struct sdrstate *sdr,int const rf_notch,int const dab_notch,int const am_notch);
static int set_biasT(struct sdrstate *sdr,int const biasT);
static int start_streaming(struct sdrstate *sdr);
static void rx_callback(int16_t *xi,int16_t *xq,sdrplay_api_StreamCbParamsT *params,unsigned int numSamples,unsigned int reset,void *cbContext);
static void event_callback(sdrplay_api_EventT eventId,sdrplay_api_TunerSelectT tuner,sdrplay_api_EventParamsT *params,void *cbContext);
static void show_device_params(struct sdrstate *sdr);
static void close_and_exit(struct sdrstate *sdr,int exit_code);
static void set_terminate(int a);
// handle commands, display status, and ka9q-radio related functions
static void decode_sdrplay_commands(struct sdrstate *,uint8_t *,int);
static void send_sdrplay_status(struct sdrstate *,int);
static void *display(void *);
static void *ncmd(void *);
dictionary *Dictionary;
char const *Name;
char const *Conf_file;
int main(int argc,char *argv[]){
App_path = argv[0];
umask(02);
#if 0
// Dump environment variables
extern char **environ;
for(int i=0;;i++){
if(environ[i])
printf("environ[%'d]: %s\n",i,environ[i]);
else
break;
}
#endif
struct sdrstate * const sdr = (struct sdrstate *)calloc(1,sizeof(struct sdrstate));
sdr->device_status = NOT_INITIALIZED;
sdr->samples = NULL;
sdr->rtp_type = IQ_PT;
Locale = getenv("LANG");
if(Locale == NULL || strlen(Locale) == 0)
Locale = "en_US.UTF-8";
setlocale(LC_ALL,Locale);
setlinebuf(stdout);
int c;
double init_frequency = 0;
while((c = getopt_long(argc,argv,Optstring,Options,NULL)) != -1){
switch(c){
case 'f':
Conf_file = optarg;
break;
case 'v':
Verbose++;
break;
default:
case '?':
fprintf(stdout,"Unknown argument %c\n",c);
break;
}
}
if(optind >= argc){
fprintf(stdout,"Name missing\n");
fprintf(stdout,"Usage: %s [-v] [-f config_file] instance_name\n",argv[0]);
exit(1);
}
Name = argv[optind];
// Process config files
if(Conf_file){
// If this fails, don't fall back to any of the defaults
if((Dictionary = iniparser_load(Conf_file)) == NULL){
fprintf(stdout,"Can't load config file %s\n",Conf_file);
exit(1);
}
if(iniparser_find_entry(Dictionary,Name) != 1){
fprintf(stdout,"No section %s found in %s\n",Name,Conf_file);
iniparser_freedict(Dictionary);
exit(1);
}
} else if((Dictionary = iniparser_load("/etc/radio/sdrplayd.conf")) != NULL){
if(iniparser_find_entry(Dictionary,Name) == 1){
printf("Using config file /etc/radio/sdrplayd.conf\n");
} else {
iniparser_freedict(Dictionary);
Dictionary = NULL;
}
}
if(Dictionary == NULL){
// Search everything under /etc/radio/sdrplayd.conf.d
char const *subdir = "/etc/radio/sdrplayd.conf.d";
DIR *dir = opendir(subdir);
if(dir != NULL){
struct dirent const *dp;
while((dp = readdir(dir)) != NULL){
if(dp->d_type != DT_REG)
continue;
int len = strlen(dp->d_name);
if(len < 5)
continue;
if(strcmp(&dp->d_name[len-5],".conf") != 0)
continue; // Name doesn't end in .conf
char path[PATH_MAX];
// Checking the return value suppresses a (bogus) gcc warning
// about possibly truncating the target. We know it can't
// beecause dp->d_name is 256 chars
int ret = snprintf(path,sizeof(path),"%s/%s",subdir,dp->d_name);
if(ret > sizeof(path))
continue; // bogus entry?
if((Dictionary = iniparser_load(path)) != NULL){
if(iniparser_find_entry(Dictionary,Name) == 1){
printf("Using config file %s section %s\n",path,Name);
break;
} else {
iniparser_freedict(Dictionary);
Dictionary = NULL;
}
}
}
closedir(dir);
dir = NULL;
}
}
if(Dictionary == NULL){
fprintf(stdout,"section %s not found in any config file\n",Name);
exit(1);
}
if(init_api(sdr) == -1)
close_and_exit(sdr,1);
char const *sn = config_getstring(Dictionary,Name,"serial",NULL);
if(sn == NULL){
fprintf(stdout,"'serial' not defined in section %s\n",Name);
close_and_exit(sdr,1);
}
// Serial number specified, find that one
if(find_rsp(sdr,sn) == -1)
close_and_exit(sdr,1);
if(sdr->device.hwVer == SDRPLAY_RSPduo_ID){
char const *mode = config_getstring(Dictionary,Name,"rspduo-mode",NULL);
char const *antenna = config_getstring(Dictionary,Name,"antenna",NULL);
if(set_rspduo_mode(sdr,mode,antenna) == -1)
close_and_exit(sdr,1);
}
if(select_device(sdr) == -1)
close_and_exit(sdr,1);
int const ifreq = config_getint(Dictionary,Name,"ifreq",-1);
if(set_ifreq(sdr,ifreq) == -1)
close_and_exit(sdr,1);
// Default sample rate to 2Msps
int const bandwidth = config_getint(Dictionary,Name,"bandwidth",-1);
double const samprate = config_getdouble(Dictionary,Name,"samprate",MIN_SAMPLE_RATE);
if(set_bandwidth(sdr,bandwidth,samprate) == -1)
close_and_exit(sdr,1);
fprintf(stdout,"Set sample rate %'f Hz\n",samprate);
if(set_samplerate(sdr,samprate) == -1)
close_and_exit(sdr,1);
{
// Multicast output interface for both data and status
Iface = config_getstring(Dictionary,Name,"iface",NULL);
sdr->data_dest = config_getstring(Dictionary,Name,"data",NULL);
// Set up output sockets
if(sdr->data_dest == NULL){
// Construct from serial number
// Technically creates a memory leak since we never free it, but it's only once per run
char *cp;
int ret = asprintf(&cp,"sdrplay-%s-pcm.local",sdr->device.SerNo);
if(ret == -1)
close_and_exit(sdr,1);
sdr->data_dest = cp;
}
sdr->metadata_dest = config_getstring(Dictionary,Name,"status",NULL);
if(sdr->metadata_dest == NULL){
// Construct from serial number
// Technically creates a memory leak since we never free it, but it's only once per run
char *cp;
int ret = asprintf(&cp,"sdrplay-%s-status.local",sdr->device.SerNo);
if(ret == -1)
close_and_exit(sdr,1);
sdr->metadata_dest = cp;
}
}
// Need to know the initial frequency beforehand because of RF att/LNA state
init_frequency = config_getdouble(Dictionary,Name,"frequency",0);
if(init_frequency != 0)
sdr->frequency_lock = 1;
if(asprintf(&sdr->frequency_file,"%s/tune-sdrplay.%s",VARDIR,sdr->device.SerNo) == -1)
close_and_exit(sdr,1);
if(init_frequency == 0){
// If not set on command line, load saved frequency
FILE *fp = fopen(sdr->frequency_file,"r+");
if(fp == NULL)
fprintf(stderr,"Can't open tuner state file %s: %s\n",sdr->frequency_file,strerror(errno));
else {
fprintf(stderr,"Using tuner state file %s\n",sdr->frequency_file);
int r;
if((r = fscanf(fp,"%lf",&init_frequency)) < 0)
fprintf(stderr,"Can't read stored freq. r = %'d: %s\n",r,strerror(errno));
fclose(fp);
}
}
if(init_frequency == 0){
// Not set on command line, and not read from file. Use fallback to cover 2m
init_frequency = 149e6; // Fallback default
fprintf(stderr,"Fallback default frequency %'.3lf Hz\n",init_frequency);
}
// Hardware device settings
{
char const *antenna = config_getstring(Dictionary,Name,"antenna",NULL);
if(set_antenna(sdr,antenna) == -1)
close_and_exit(sdr,1);
int const lna_state = config_getint(Dictionary,Name,"lna-state",-1);
int const rf_att = config_getint(Dictionary,Name,"rf-att",-1);
int const rf_gr = config_getint(Dictionary,Name,"rf-gr",-1);
if(set_rf_gain(sdr,lna_state,rf_att,rf_gr,init_frequency) == -1)
close_and_exit(sdr,1);
int const if_att = config_getint(Dictionary,Name,"if-att",-1);
int const if_gr = config_getint(Dictionary,Name,"if-gr",-1);
int const if_agc = config_getboolean(Dictionary,Name,"if-agc",0); // default off
int const if_agc_rate = config_getint(Dictionary,Name,"if-agc-rate",-1);
int const if_agc_setPoint_dBfs = config_getint(Dictionary,Name,"if-agc-setpoint-dbfs",-60);
int const if_agc_attack_ms = config_getint(Dictionary,Name,"if-agc-attack-ms",0);
int const if_agc_decay_ms = config_getint(Dictionary,Name,"if-agc-decay-ms",0);
int const if_agc_decay_delay_ms = config_getint(Dictionary,Name,"if-agc-decay-delay-ms",0);
int const if_agc_decay_threshold_dB = config_getint(Dictionary,Name,"if-agc-decay-threshold-db",0);
if(set_if_gain(sdr,if_att,if_gr,if_agc,if_agc_rate,if_agc_setPoint_dBfs,if_agc_attack_ms,if_agc_decay_ms,if_agc_decay_delay_ms,if_agc_decay_threshold_dB) == -1)
close_and_exit(sdr,1);
fprintf(stdout,"RF LNA state %d, IF att %d, IF AGC %d, IF AGC setPoint %d\n",
(int)(sdr->rx_channel_params->tunerParams.gain.LNAstate),
sdr->rx_channel_params->tunerParams.gain.gRdB,
sdr->rx_channel_params->ctrlParams.agc.enable,
sdr->rx_channel_params->ctrlParams.agc.setPoint_dBfs);
int const dc_offset_corr = config_getboolean(Dictionary,Name,"dc-offset-corr",1); // default on
int const iq_imbalance_corr = config_getboolean(Dictionary,Name,"iq-imbalance-corr",1); // default on
if(set_dc_offset_iq_imbalance_correction(sdr,dc_offset_corr,iq_imbalance_corr) == -1)
close_and_exit(sdr,1);
int const transfer_mode_bulk = config_getboolean(Dictionary,Name,"bulk-transfer-mode",0); // default isochronous
if(set_bulk_transfer_mode(sdr,transfer_mode_bulk) == -1)
close_and_exit(sdr,1);
int const rf_notch = config_getboolean(Dictionary,Name,"rf-notch",0);
int const dab_notch = config_getboolean(Dictionary,Name,"dab-notch",0);
int const am_notch = config_getboolean(Dictionary,Name,"am-notch",0);
if(set_notch_filters(sdr,rf_notch,dab_notch,am_notch) == -1)
close_and_exit(sdr,1);
int const biasT = config_getboolean(Dictionary,Name,"bias-t",0);
if(set_biasT(sdr,biasT) == -1)
close_and_exit(sdr,1);
}
// When the IP TTL is 0, we're not limited by the Ethernet hardware MTU so select a much larger packet size
// unless one has been set explicitly
// IPv4 packets are limited to 64KB, IPv6 can go larger with the Jumbo Payload option
RTP_ttl = config_getint(Dictionary,Name,"data-ttl",0); // Default to TTL=0
Status_ttl = config_getint(Dictionary,Name,"status-ttl",1); // Default 1 for status; much lower bandwidth
{
int x = config_getint(Dictionary,Name,"blocksize",-1);
if(x != -1){
sdr->blocksize = x;
} else if(RTP_ttl == 0)
sdr->blocksize = 2048;
else
sdr->blocksize = 960;
}
sdr->description = config_getstring(Dictionary,Name,"description",NULL);
{
time_t tt;
time(&tt);
sdr->rtp.ssrc = config_getint(Dictionary,Name,"ssrc",tt);
}
// Default is AF12 left shifted 2 bits
IP_tos = config_getint(Dictionary,Name,"tos",48);
fprintf(stdout,"Status TTL %d, Data TTL %d, blocksize %'d samples, %'lu bytes\n",
Status_ttl,RTP_ttl,sdr->blocksize,(long unsigned)(sdr->blocksize * sizeof(complex float)));
{
// Start Avahi client that will maintain our mDNS registrations
// Service name, if present, must be unique
// Description, if present becomes TXT record if present
char service_name[1024];
snprintf(service_name,sizeof(service_name),"%s (%s)",sdr->description,sdr->metadata_dest);
uint32_t addr = make_maddr(sdr->metadata_dest);
avahi_start(service_name,"_ka9q-ctl._udp",5006,sdr->metadata_dest,addr,sdr->description);
snprintf(service_name,sizeof(service_name),"%s (%s)",sdr->description,sdr->data_dest);
addr = make_maddr(sdr->data_dest);
avahi_start(service_name,"_rtp._udp",5004,sdr->data_dest,addr,sdr->description);
}
{
char iface[1024];
resolve_mcast(sdr->data_dest,&sdr->output_data_dest_address,DEFAULT_RTP_PORT,iface,sizeof(iface));
if(strlen(iface) == 0 && Iface != NULL)
strlcpy(iface,Iface,sizeof(iface));
sdr->data_sock = connect_mcast(&sdr->output_data_dest_address,iface,RTP_ttl,IP_tos);
if(sdr->data_sock == -1){
fprintf(stderr,"Can't create multicast socket to %s: %s\n",sdr->data_dest,strerror(errno));
exit(1);
}
socklen_t len = sizeof(sdr->output_data_source_address);
getsockname(sdr->data_sock,(struct sockaddr *)&sdr->output_data_source_address,&len);
resolve_mcast(sdr->metadata_dest,&sdr->output_metadata_dest_address,DEFAULT_STAT_PORT,iface,sizeof(iface));
if(strlen(iface) == 0 && Iface != NULL)
strlcpy(iface,Iface,sizeof(iface));
sdr->status_sock = connect_mcast(&sdr->output_metadata_dest_address,iface,Status_ttl,IP_tos);
if(sdr->status_sock <= 0){
fprintf(stderr,"Can't create multicast status socket to %s: %s\n",sdr->metadata_dest,strerror(errno));
exit(1);
}
// Set up new control socket on port 5006
sdr->nctl_sock = listen_mcast(&sdr->output_metadata_dest_address,iface);
if(sdr->nctl_sock <= 0){
fprintf(stderr,"Can't create multicast command socket from %s: %s\n",sdr->metadata_dest,strerror(errno));
exit(1);
}
}
fprintf(stderr,"Setting initial frequency %'.3lf Hz, %s\n",init_frequency,sdr->frequency_lock ? "locked" : "not locked");
set_center_freq(sdr,init_frequency);
signal(SIGPIPE,SIG_IGN);
signal(SIGINT,set_terminate);
signal(SIGKILL,set_terminate);
signal(SIGQUIT,set_terminate);
signal(SIGTERM,set_terminate);
if(sdr->status)
pthread_create(&sdr->display_thread,NULL,display,sdr);
pthread_create(&sdr->ncmd_thread,NULL,ncmd,sdr);
sdr->samples = malloc(sdr->blocksize * sizeof(complex int16_t));
if(start_streaming(sdr) == -1)
close_and_exit(sdr,1);
send_sdrplay_status(sdr,1); // Tell the world we're alive
// Periodically poll status to ensure device hasn't reset
uint64_t prev_sample_count = 0;
while(true){
sleep(1);
if(Terminate){
fprintf(stderr,"Terminating as requsted by user\n");
close_and_exit(sdr,Terminate-1);
}
uint64_t curr_sample_count = sdr->sample_count;
if(!(curr_sample_count > prev_sample_count))
break; // Device seems to have bombed. Exit and let systemd restart us
prev_sample_count = curr_sample_count;
}
fprintf(stderr,"Device is no longer streaming, exiting\n");
close(sdr->data_sock);
close_and_exit(sdr,0);
}
// Thread to send metadata and process commands
void *ncmd(void *arg){
// Send status, process commands
pthread_setname("sdrplay-cmd");
assert(arg != NULL);
struct sdrstate * const sdr = arg;
if(sdr->status_sock == -1 || sdr->nctl_sock == -1)
return NULL; // Nothing to do
while(true){
uint8_t buffer[Bufsize];
int const length = recv(sdr->nctl_sock,buffer,sizeof(buffer),0);
if(length > 0){
// Parse entries
if((enum pkt_type)buffer[0] != CMD)
continue; // Ignore our own status messages
sdr->commands++;
decode_sdrplay_commands(sdr,buffer+1,length-1);
send_sdrplay_status(sdr,1);
}
}
}
// Status display thread
void *display(void *arg){
assert(arg != NULL);
struct sdrstate *sdr = (struct sdrstate *)arg;
pthread_setname("sdrplay-disp");
fprintf(sdr->status,"Frequency Output clips\n");
off_t stat_point = ftello(sdr->status);
// End lines with return when writing to terminal, newlines when writing to status file
char const eol = stat_point == -1 ? '\r' : '\n';
while(true){
float powerdB = power2dB(sdr->power);
if(stat_point != -1)
fseeko(sdr->status,stat_point,SEEK_SET);
fprintf(sdr->status,"%'-14.0lf%'7.1f%'10d %c",
sdr->rx_channel_params->tunerParams.rfFreq.rfHz,
powerdB,
sdr->clips,
eol);
fflush(sdr->status);
usleep(100000); // 10 Hz
}
return NULL;
}
#if 0
// Status display thread
void *display(void *arg){
assert(arg != NULL);
struct sdrstate *sdr = (struct sdrstate *)arg;
pthread_setname("sdrplay-disp");
fprintf(sdr->status," |-----Gains dB-- ---| |----Levels dB --| clips\n");
fprintf(sdr->status,"Frequency step LNA mixer bband RF A/D Out\n");
fprintf(sdr->status,"Hz dBFS dBFS\n");
off_t stat_point = ftello(sdr->status);
// End lines with return when writing to terminal, newlines when writing to status file
char eol = stat_point == -1 ? '\r' : '\n';
while(true){
if(stat_point != -1)
fseeko(sdr->status,stat_point,SEEK_SET);
fprintf(sdr->status,"%'-15.0lf%4d%4d%7d%6d%c",
sdr->frequency,
sdr->gainstep,
sdr->lna_gain,
sdr->mixer_gain,
sdr->if_gain,
eol);
fflush(sdr->status);
usleep(100000); // 10 Hz
}
return NULL;
}
#endif
void decode_sdrplay_commands(struct sdrstate *sdr,uint8_t *buffer,int length){
uint8_t *cp = buffer;
while(cp - buffer < length){
int ret __attribute__((unused)); // Won't be used when asserts are disabled
enum status_type const type = *cp++; // increment cp to length field
if(type == EOL)
break; // End of list
unsigned int optlen = *cp++;
if(optlen & 0x80){
// length is >= 128 bytes; fetch actual length from next N bytes, where N is low 7 bits of optlen
int length_of_length = optlen & 0x7f;
optlen = 0;
while(length_of_length > 0){
optlen <<= 8;
optlen |= *cp++;
length_of_length--;
}
}
if(cp - buffer + optlen >= length)
break; // Invalid length
switch(type){
case EOL: // Shouldn't get here
break;
case COMMAND_TAG:
sdr->command_tag = decode_int(cp,optlen);
break;
case RADIO_FREQUENCY:
if(!sdr->frequency_lock){
double const f = decode_double(cp,optlen);
set_center_freq(sdr,f);
}
break;
case LNA_GAIN:
{
int lna_gain = decode_int(cp,optlen);
if(lna_gain >= 0){ // LNA gain >= 0 -> LNA state
set_rf_gain(sdr,lna_gain,-1,-1,sdr->rx_channel_params->tunerParams.rfFreq.rfHz);
} else { // LNA gain < 0 -> RF attenuation
set_rf_gain(sdr,-1,-lna_gain,-1,sdr->rx_channel_params->tunerParams.rfFreq.rfHz);
}
}
break;
case IF_GAIN:
{
int if_gain = decode_int(cp,optlen);
if(if_gain == 0){
// IF gain == 0 -> enable AGC
set_if_gain(sdr,-1,-1,1,-1,-60,0,0,0,0);
} else if(-if_gain >= sdrplay_api_NORMAL_MIN_GR && -if_gain <= MAX_BB_GR){
// IF gain in [-20,-59] -> set IF GR
set_if_gain(sdr,-if_gain,-1,0,0,-60,0,0,0,0);
}
}
break;
default: // Ignore all others
break;
}
cp += optlen;
}
}
void send_sdrplay_status(struct sdrstate *sdr,int full){
uint8_t packet[2048];
uint8_t *bp = packet;
sdr->output_metadata_packets++;
*bp++ = 0; // Command/response = response
encode_int32(&bp,COMMAND_TAG,sdr->command_tag);
encode_int64(&bp,CMD_CNT,sdr->commands);
encode_int64(&bp,GPS_TIME,gps_time_ns());
if(sdr->description)
encode_string(&bp,DESCRIPTION,sdr->description,strlen(sdr->description));
double samprate = get_samplerate(sdr);
// Source address we're using to send data
encode_socket(&bp,OUTPUT_DATA_SOURCE_SOCKET,&sdr->output_data_source_address);
// Where we're sending output
encode_socket(&bp,OUTPUT_DATA_DEST_SOCKET,&sdr->output_data_dest_address);
encode_int32(&bp,OUTPUT_SSRC,sdr->rtp.ssrc);
encode_byte(&bp,OUTPUT_TTL,RTP_ttl);
encode_int32(&bp,INPUT_SAMPRATE,(int)samprate);
encode_int64(&bp,OUTPUT_DATA_PACKETS,sdr->rtp.packets);
encode_int64(&bp,OUTPUT_METADATA_PACKETS,sdr->output_metadata_packets);
// Front end
encode_byte(&bp,LNA_GAIN,sdr->rx_channel_params->tunerParams.gain.LNAstate);
encode_int32(&bp,IF_GAIN,sdr->rx_channel_params->tunerParams.gain.gRdB);
encode_double(&bp,GAIN,sdr->rx_channel_params->tunerParams.gain.gainVals.curr);
// Tuning
encode_double(&bp,RADIO_FREQUENCY,sdr->rx_channel_params->tunerParams.rfFreq.rfHz);
encode_int32(&bp,LOCK,sdr->frequency_lock);
encode_byte(&bp,DEMOD_TYPE,0); // actually LINEAR_MODE
encode_int32(&bp,OUTPUT_SAMPRATE,(int)samprate);
encode_int32(&bp,OUTPUT_CHANNELS,2);
double bandwidth = min(1000.0 * sdr->rx_channel_params->tunerParams.bwType, samprate);
encode_float(&bp,HIGH_EDGE,+0.43 * bandwidth); // empirical for sdrplay
encode_float(&bp,LOW_EDGE,-0.43 * bandwidth); // Should look at the actual filter curves
encode_eol(&bp);
int const len = bp - packet;
assert(len < sizeof(packet));
send(sdr->status_sock,packet,len,0);
}
// SDRplay specific functions
static int init_api(struct sdrstate *sdr){
sdrplay_api_ErrT err;
err = sdrplay_api_Open();
if(err != sdrplay_api_Success){
fprintf(stdout,"sdrplay_api_Open() failed: %s\n",sdrplay_api_GetErrorString(err));
return -1;
}
sdr->device_status |= SDRPLAY_API_OPEN;
float ver;
err = sdrplay_api_ApiVersion(&ver);
if(err != sdrplay_api_Success){
fprintf(stdout,"sdrplay_api_ApiVersion() failed: %s\n",sdrplay_api_GetErrorString(err));
return -1;
}
if(ver != SDRPLAY_API_VERSION){
fprintf(stdout,"SDRplay API version mismatch: found %.2f, expecting %.2f\n",ver,SDRPLAY_API_VERSION);
return -1;
}
err = sdrplay_api_DebugEnable(NULL,dbgLvl);
if(err != sdrplay_api_Success){
fprintf(stdout,"sdrplay_api_DebugEnable() failed: %s\n",sdrplay_api_GetErrorString(err));
return -1;
}
return 0;
}
static int find_rsp(struct sdrstate *sdr,char const *sn){
sdrplay_api_ErrT err;
err = sdrplay_api_LockDeviceApi();
if(err != sdrplay_api_Success){
fprintf(stdout,"sdrplay_api_LockDeviceApi() failed: %s\n",sdrplay_api_GetErrorString(err));
return -1;
}
sdr->device_status |= DEVICE_API_LOCKED;
unsigned int ndevices = SDRPLAY_MAX_DEVICES;
sdrplay_api_DeviceT devices[SDRPLAY_MAX_DEVICES];
err = sdrplay_api_GetDevices(devices,&ndevices,ndevices);
if(err != sdrplay_api_Success){
fprintf(stdout,"sdrplay_api_GetDevices() failed: %s\n",sdrplay_api_GetErrorString(err));
return -1;
}
int found = 0;
for(int i = 0; i < ndevices; i++){
if(strcmp(devices[i].SerNo, sn) == 0){
sdr->device = devices[i];
found = 1;
break;
}
}
if(!found){
fprintf(stdout,"sdrplay device %s not found or unavailable\n",sn);
return -1;
}
return 0;
}
static int set_rspduo_mode(struct sdrstate *sdr,char const *mode,char const *antenna){
// RSPduo mode
int valid_mode = 1;
if(mode == NULL){
if(sdr->device.rspDuoMode & sdrplay_api_RspDuoMode_Single_Tuner)
sdr->device.rspDuoMode = sdrplay_api_RspDuoMode_Single_Tuner;
} else if(strcmp(mode,"single-tuner") == 0 || strcmp(mode,"Single Tuner") == 0){
if(sdr->device.rspDuoMode & sdrplay_api_RspDuoMode_Single_Tuner)
sdr->device.rspDuoMode = sdrplay_api_RspDuoMode_Single_Tuner;
else
valid_mode = 0;
} else if(strcmp(mode,"dual-tuner") == 0 || strcmp(mode,"Dual Tuner") == 0){
if(sdr->device.rspDuoMode & sdrplay_api_RspDuoMode_Dual_Tuner){
sdr->device.rspDuoMode = sdrplay_api_RspDuoMode_Dual_Tuner;
sdr->device.rspDuoSampleFreq = 6e6;
} else
valid_mode = 0;
} else if(strcmp(mode,"master") == 0 || strcmp(mode,"Master") == 0){
if(sdr->device.rspDuoMode & sdrplay_api_RspDuoMode_Master){
sdr->device.rspDuoMode = sdrplay_api_RspDuoMode_Master;
sdr->device.rspDuoSampleFreq = 6e6;
} else
valid_mode = 0;
} else if(strcmp(mode,"master-8msps") == 0 || strcmp(mode,"Master (SR=8MHz)") == 0){
if(sdr->device.rspDuoMode & sdrplay_api_RspDuoMode_Master){
sdr->device.rspDuoMode = sdrplay_api_RspDuoMode_Master;
sdr->device.rspDuoSampleFreq = 8e6;
} else
valid_mode = 0;
} else if(strcmp(mode,"slave") == 0 || strcmp(mode,"Slave") == 0){
if(!(sdr->device.rspDuoMode == sdrplay_api_RspDuoMode_Slave))
valid_mode = 0;
} else
valid_mode = 0;
if(!valid_mode){
fprintf(stdout,"sdrplay - RSPduo mode %s is invalid or not available\n",mode);
return -1;
}
// RSPduo tuner
int valid_tuner = 1;
if(antenna == NULL){
if(sdr->device.rspDuoMode == sdrplay_api_RspDuoMode_Single_Tuner ||
sdr->device.rspDuoMode == sdrplay_api_RspDuoMode_Master)
sdr->device.tuner = sdrplay_api_Tuner_A;
} else if(strcmp(antenna,"tuner1-50ohm") == 0 || strcmp(antenna,"Tuner 1 50ohm") == 0 || strcmp(antenna,"high-z") == 0 || strcmp(antenna,"High Z") == 0){
if(sdr->device.rspDuoMode != sdrplay_api_RspDuoMode_Dual_Tuner && sdr->device.tuner & sdrplay_api_Tuner_A)
sdr->device.tuner = sdrplay_api_Tuner_A;
else
valid_tuner = 0;
} else if(strcmp(antenna,"tuner2-50ohm") == 0 || strcmp(antenna,"Tuner 2 50ohm") == 0){
if(sdr->device.rspDuoMode != sdrplay_api_RspDuoMode_Dual_Tuner && sdr->device.tuner & sdrplay_api_Tuner_B)
sdr->device.tuner = sdrplay_api_Tuner_B;
else
valid_tuner = 0;
} else
valid_tuner = 0;
if(!valid_tuner){
fprintf(stdout,"sdrplay - antenna %s is invalid or not available\n",antenna);
return -1;
}
return 0;
}
static int select_device(struct sdrstate *sdr){
sdrplay_api_ErrT err;
err = sdrplay_api_SelectDevice(&sdr->device);
if(err != sdrplay_api_Success){
fprintf(stdout,"sdrplay_api_SelectDevice() failed: %s\n",sdrplay_api_GetErrorString(err));
return -1;
}
sdr->device_status |= DEVICE_SELECTED;
err = sdrplay_api_UnlockDeviceApi();
sdr->device_status &= ~DEVICE_API_LOCKED;
if(err != sdrplay_api_Success){
fprintf(stdout,"sdrplay_api_UnlockDeviceApi() failed: %s\n",sdrplay_api_GetErrorString(err));
return -1;
}
err = sdrplay_api_DebugEnable(sdr->device.dev,dbgLvl);
if(err != sdrplay_api_Success){
fprintf(stdout,"sdrplay_api_DebugEnable() failed: %s\n",sdrplay_api_GetErrorString(err));
return -1;
}
err = sdrplay_api_GetDeviceParams(sdr->device.dev,&sdr->device_params);
if(err != sdrplay_api_Success){
fprintf(stdout,"sdrplay_api_GetDeviceParams() failed: %s\n",sdrplay_api_GetErrorString(err));
return -1;
}
if(sdr->device.tuner == sdrplay_api_Tuner_A){
sdr->rx_channel_params = sdr->device_params->rxChannelA;
} else if(sdr->device.tuner == sdrplay_api_Tuner_B){
sdr->rx_channel_params = sdr->device_params->rxChannelB;
} else {
fprintf(stdout,"sdrplay - invalid tuner: %d\n",sdr->device.tuner);
return -1;
}
return 0;
}
static int set_center_freq(struct sdrstate *sdr,double const frequency){
sdr->rx_channel_params->tunerParams.rfFreq.rfHz = frequency;
if(sdr->device_status & DEVICE_STREAMING){
sdrplay_api_ErrT err;
err = sdrplay_api_Update(sdr->device.dev,sdr->device.tuner,sdrplay_api_Update_Tuner_Frf,sdrplay_api_Update_Ext1_None);
if(err != sdrplay_api_Success){
fprintf(stdout,"sdrplay_api_Update(Tuner_Frf) failed: %s\n",sdrplay_api_GetErrorString(err));
return -1;
}
}
return 0;
}
static int set_ifreq(struct sdrstate *sdr,int const ifreq){
int valid_if = 1;
if(sdr->device.hwVer == SDRPLAY_RSPduo_ID && (sdr->device.rspDuoMode == sdrplay_api_RspDuoMode_Dual_Tuner || sdr->device.rspDuoMode == sdrplay_api_RspDuoMode_Master || sdr->device.rspDuoMode == sdrplay_api_RspDuoMode_Slave)){
if(sdr->device.rspDuoSampleFreq == 6e6 && (ifreq == -1 || ifreq == 1620))
sdr->rx_channel_params->tunerParams.ifType = sdrplay_api_IF_1_620;
else if(sdr->device.rspDuoSampleFreq == 8e6 && (ifreq == -1 || ifreq == 2048))
sdr->rx_channel_params->tunerParams.ifType = sdrplay_api_IF_2_048;
else
valid_if = 0;
} else {
if(ifreq == -1 || ifreq == 0){
sdr->rx_channel_params->tunerParams.ifType = sdrplay_api_IF_Zero;
} else if(ifreq == 450){
sdr->rx_channel_params->tunerParams.ifType = sdrplay_api_IF_0_450;
} else if(ifreq == 1620){
sdr->rx_channel_params->tunerParams.ifType = sdrplay_api_IF_1_620;
} else if(ifreq == 2048){
sdr->rx_channel_params->tunerParams.ifType = sdrplay_api_IF_2_048;
} else
valid_if = 0;
}
if(!valid_if){
fprintf(stdout,"sdrplay - IF=%d is invalid\n",ifreq);
return -1;
}
return 0;
}
static int set_bandwidth(struct sdrstate *sdr,int const bandwidth,double const samprate){
double samprate_kHz = samprate / 1000.0;
int valid_bandwidth = 1;
if(bandwidth == sdrplay_api_BW_0_200 || (bandwidth == -1 && samprate_kHz < sdrplay_api_BW_0_300)){
sdr->rx_channel_params->tunerParams.bwType = sdrplay_api_BW_0_200;
} else if(bandwidth == sdrplay_api_BW_0_300 || (bandwidth == -1 && samprate_kHz < sdrplay_api_BW_0_600)){
sdr->rx_channel_params->tunerParams.bwType = sdrplay_api_BW_0_300;
} else if(bandwidth == sdrplay_api_BW_0_600 || (bandwidth == -1 && samprate_kHz < sdrplay_api_BW_1_536)){
sdr->rx_channel_params->tunerParams.bwType = sdrplay_api_BW_0_600;
} else if(bandwidth == sdrplay_api_BW_1_536 || (bandwidth == -1 && samprate_kHz < sdrplay_api_BW_5_000)){
sdr->rx_channel_params->tunerParams.bwType = sdrplay_api_BW_1_536;
} else if(bandwidth == sdrplay_api_BW_5_000 || (bandwidth == -1 && samprate_kHz < sdrplay_api_BW_6_000)){
sdr->rx_channel_params->tunerParams.bwType = sdrplay_api_BW_5_000;
} else if(bandwidth == sdrplay_api_BW_6_000 || (bandwidth == -1 && samprate_kHz < sdrplay_api_BW_7_000)){
sdr->rx_channel_params->tunerParams.bwType = sdrplay_api_BW_6_000;
} else if(bandwidth == sdrplay_api_BW_7_000 || (bandwidth == -1 && samprate_kHz < sdrplay_api_BW_8_000)){
sdr->rx_channel_params->tunerParams.bwType = sdrplay_api_BW_7_000;
} else if(bandwidth == sdrplay_api_BW_8_000 || (bandwidth == -1 && samprate_kHz >= sdrplay_api_BW_8_000)){
sdr->rx_channel_params->tunerParams.bwType = sdrplay_api_BW_8_000;
} else
valid_bandwidth = 0;
if(!valid_bandwidth){
fprintf(stdout,"sdrplay - Bandwidth=%d is invalid\n",bandwidth);
return -1;
}
return 0;
}
static int set_samplerate(struct sdrstate *sdr,double const samprate){
// get actual sample rate and decimation
double actual_sample_rate;
int decimation;
for(decimation = 1; decimation <= MAX_DECIMATION; decimation *= 2){
actual_sample_rate = samprate * decimation;
if(actual_sample_rate >= MIN_SAMPLE_RATE)
break;
}
if(!(actual_sample_rate >= MIN_SAMPLE_RATE && actual_sample_rate <= MAX_SAMPLE_RATE)){
fprintf(stdout,"sdrplay - sample_rate=%f is invalid\n",samprate);
return -1;
}
if(sdr->device.hwVer == SDRPLAY_RSPduo_ID && (sdr->device.rspDuoMode == sdrplay_api_RspDuoMode_Dual_Tuner || sdr->device.rspDuoMode == sdrplay_api_RspDuoMode_Master || sdr->device.rspDuoMode == sdrplay_api_RspDuoMode_Slave)){
if(actual_sample_rate == MIN_SAMPLE_RATE){
if(sdr->device_params->devParams)
sdr->device_params->devParams->fsFreq.fsHz = sdr->device.rspDuoSampleFreq;
} else {
fprintf(stdout,"sdrplay - sample_rate=%f is invalid\n",samprate);
return -1;
}
} else {
sdr->device_params->devParams->fsFreq.fsHz = actual_sample_rate;
}
if(decimation > 1){