Add --direct option for rtlsdr direct sampling
This commit is contained in:
parent
1caabc5ad8
commit
2b00c05465
66
sdr_rtlsdr.c
66
sdr_rtlsdr.c
|
@ -57,6 +57,7 @@ static struct {
|
||||||
rtlsdr_dev_t *dev;
|
rtlsdr_dev_t *dev;
|
||||||
bool digital_agc;
|
bool digital_agc;
|
||||||
int ppm_error;
|
int ppm_error;
|
||||||
|
int direct_sampling;
|
||||||
|
|
||||||
iq_convert_fn converter;
|
iq_convert_fn converter;
|
||||||
struct converter_state *converter_state;
|
struct converter_state *converter_state;
|
||||||
|
@ -71,6 +72,7 @@ void rtlsdrInitConfig()
|
||||||
RTLSDR.dev = NULL;
|
RTLSDR.dev = NULL;
|
||||||
RTLSDR.digital_agc = false;
|
RTLSDR.digital_agc = false;
|
||||||
RTLSDR.ppm_error = 0;
|
RTLSDR.ppm_error = 0;
|
||||||
|
RTLSDR.direct_sampling = 0;
|
||||||
RTLSDR.converter = NULL;
|
RTLSDR.converter = NULL;
|
||||||
RTLSDR.converter_state = NULL;
|
RTLSDR.converter_state = NULL;
|
||||||
}
|
}
|
||||||
|
@ -142,6 +144,7 @@ void rtlsdrShowHelp()
|
||||||
printf("--device <index|serial> select device by index or serial number\n");
|
printf("--device <index|serial> select device by index or serial number\n");
|
||||||
printf("--enable-agc enable digital AGC (not tuner AGC!)\n");
|
printf("--enable-agc enable digital AGC (not tuner AGC!)\n");
|
||||||
printf("--ppm <correction> set oscillator frequency correction in PPM\n");
|
printf("--ppm <correction> set oscillator frequency correction in PPM\n");
|
||||||
|
printf("--direct <0|1|2> set direct sampling mode\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,6 +157,8 @@ bool rtlsdrHandleOption(int argc, char **argv, int *jptr)
|
||||||
RTLSDR.digital_agc = true;
|
RTLSDR.digital_agc = true;
|
||||||
} else if (!strcmp(argv[j], "--ppm") && more) {
|
} else if (!strcmp(argv[j], "--ppm") && more) {
|
||||||
RTLSDR.ppm_error = atoi(argv[++j]);
|
RTLSDR.ppm_error = atoi(argv[++j]);
|
||||||
|
} else if (!strcmp(argv[j], "--direct") && more) {
|
||||||
|
RTLSDR.direct_sampling = atoi(argv[++j]);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -196,39 +201,44 @@ bool rtlsdrOpen(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set gain, frequency, sample rate, and reset the device
|
// Set gain, frequency, sample rate, and reset the device
|
||||||
if (Modes.gain == MODES_AUTO_GAIN) {
|
if (RTLSDR.direct_sampling) {
|
||||||
fprintf(stderr, "rtlsdr: enabling tuner AGC\n");
|
fprintf(stderr, "rtlsdr: direct sampling from input %d\n", RTLSDR.direct_sampling);
|
||||||
rtlsdr_set_tuner_gain_mode(RTLSDR.dev, 0);
|
rtlsdr_set_direct_sampling(RTLSDR.dev, RTLSDR.direct_sampling);
|
||||||
} else {
|
} else {
|
||||||
int *gains;
|
if (Modes.gain == MODES_AUTO_GAIN) {
|
||||||
int numgains;
|
fprintf(stderr, "rtlsdr: enabling tuner AGC\n");
|
||||||
|
rtlsdr_set_tuner_gain_mode(RTLSDR.dev, 0);
|
||||||
|
} else {
|
||||||
|
int *gains;
|
||||||
|
int numgains;
|
||||||
|
|
||||||
numgains = rtlsdr_get_tuner_gains(RTLSDR.dev, NULL);
|
numgains = rtlsdr_get_tuner_gains(RTLSDR.dev, NULL);
|
||||||
if (numgains <= 0) {
|
if (numgains <= 0) {
|
||||||
fprintf(stderr, "rtlsdr: error getting tuner gains\n");
|
fprintf(stderr, "rtlsdr: error getting tuner gains\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
gains = malloc(numgains * sizeof(int));
|
gains = malloc(numgains * sizeof(int));
|
||||||
if (rtlsdr_get_tuner_gains(RTLSDR.dev, gains) != numgains) {
|
if (rtlsdr_get_tuner_gains(RTLSDR.dev, gains) != numgains) {
|
||||||
fprintf(stderr, "rtlsdr: error getting tuner gains\n");
|
fprintf(stderr, "rtlsdr: error getting tuner gains\n");
|
||||||
|
free(gains);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int target = (Modes.gain == MODES_MAX_GAIN ? 9999 : Modes.gain);
|
||||||
|
int closest = -1;
|
||||||
|
|
||||||
|
for (int i = 0; i < numgains; ++i) {
|
||||||
|
if (closest == -1 || abs(gains[i] - target) < abs(gains[closest] - target))
|
||||||
|
closest = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
rtlsdr_set_tuner_gain(RTLSDR.dev, gains[closest]);
|
||||||
free(gains);
|
free(gains);
|
||||||
return false;
|
|
||||||
|
fprintf(stderr, "rtlsdr: tuner gain set to %.1f dB\n",
|
||||||
|
rtlsdr_get_tuner_gain(RTLSDR.dev)/10.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int target = (Modes.gain == MODES_MAX_GAIN ? 9999 : Modes.gain);
|
|
||||||
int closest = -1;
|
|
||||||
|
|
||||||
for (int i = 0; i < numgains; ++i) {
|
|
||||||
if (closest == -1 || abs(gains[i] - target) < abs(gains[closest] - target))
|
|
||||||
closest = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
rtlsdr_set_tuner_gain(RTLSDR.dev, gains[closest]);
|
|
||||||
free(gains);
|
|
||||||
|
|
||||||
fprintf(stderr, "rtlsdr: tuner gain set to %.1f dB\n",
|
|
||||||
rtlsdr_get_tuner_gain(RTLSDR.dev)/10.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RTLSDR.digital_agc) {
|
if (RTLSDR.digital_agc) {
|
||||||
|
|
Loading…
Reference in a new issue