fix gain setting and update usage information for CLI tools

master
Dimitri Stolnikov 13 years ago
parent 6d34b04b42
commit b5beddca4f
  1. 30
      src/rtl_sdr.c
  2. 27
      src/rtl_tcp.c
  3. 8
      src/rtl_test.c

@ -42,16 +42,16 @@ static rtlsdr_dev_t *dev = NULL;
void usage(void) void usage(void)
{ {
#ifdef _WIN32 #ifdef _WIN32
fprintf(stderr,"rtl-sdr, an I/Q recorder for RTL2832 based USB-sticks\n\n" fprintf(stderr,"rtl_sdr, an I/Q recorder for RTL2832 based DVB-T receivers\n\n"
"Usage:\t rtl-sdr-win.exe [device_index] [samplerate in kHz] " "Usage:\t rtl_sdr.exe [device_index] [samplerate in kHz] "
"[gain] [frequency in Hz] [filename]\n"); "[gain (0 for auto)] [frequency in Hz] [filename]\n");
#else #else
fprintf(stderr, fprintf(stderr,
"rtl-sdr, an I/Q recorder for RTL2832 based DVB-T receivers\n\n" "rtl_sdr, an I/Q recorder for RTL2832 based DVB-T receivers\n\n"
"Usage:\t -f frequency_to_tune_to [Hz]\n" "Usage:\t -f frequency_to_tune_to [Hz]\n"
"\t[-s samplerate (default: 2048000 Hz)]\n" "\t[-s samplerate (default: 2048000 Hz)]\n"
"\t[-d device_index (default: 0)]\n" "\t[-d device_index (default: 0)]\n"
"\t[-g tuner_gain (default: -1dB)]\n" "\t[-g gain (default: 0 for auto)]\n"
"\t[-b output_block_size (default: 16 * 16384)]\n" "\t[-b output_block_size (default: 16 * 16384)]\n"
"\t[-S force sync output (default: async)]\n" "\t[-S force sync output (default: async)]\n"
"\tfilename (a '-' dumps samples to stdout)\n\n"); "\tfilename (a '-' dumps samples to stdout)\n\n");
@ -98,7 +98,7 @@ int main(int argc, char **argv)
char *filename = NULL; char *filename = NULL;
int n_read; int n_read;
int r, opt; int r, opt;
int i, gain = -10; // tenths of a dB int i, gain = 0;
int sync_mode = 0; int sync_mode = 0;
FILE *file; FILE *file;
uint8_t *buffer; uint8_t *buffer;
@ -118,7 +118,7 @@ int main(int argc, char **argv)
frequency = (uint32_t)atof(optarg); frequency = (uint32_t)atof(optarg);
break; break;
case 'g': case 'g':
gain = (int)(atof(optarg) * 10); gain = (int)(atof(optarg) * 10); /* tenths of a dB */
break; break;
case 's': case 's':
samp_rate = (uint32_t)atof(optarg); samp_rate = (uint32_t)atof(optarg);
@ -144,8 +144,8 @@ int main(int argc, char **argv)
if(argc < 6) if(argc < 6)
usage(); usage();
dev_index = atoi(argv[1]); dev_index = atoi(argv[1]);
samp_rate = atoi(argv[2])*1000; samp_rate = atoi(argv[2])*1000; /* kHz */
gain=(int)(atof(argv[3]) * 10); gain = (int)(atof(argv[3]) * 10); /* tenths of a dB */
frequency = atoi(argv[4]); frequency = atoi(argv[4]);
filename = argv[5]; filename = argv[5];
#endif #endif
@ -206,12 +206,24 @@ int main(int argc, char **argv)
else else
fprintf(stderr, "Tuned to %u Hz.\n", frequency); fprintf(stderr, "Tuned to %u Hz.\n", frequency);
if (0 == gain) {
/* Enable automatic gain */
r = rtlsdr_set_tuner_gain_mode(dev, 0);
if (r < 0)
fprintf(stderr, "WARNING: Failed to enable automatic gain.\n");
} else {
/* Enable manual gain */
r = rtlsdr_set_tuner_gain_mode(dev, 1);
if (r < 0)
fprintf(stderr, "WARNING: Failed to enable manual gain.\n");
/* Set the tuner gain */ /* Set the tuner gain */
r = rtlsdr_set_tuner_gain(dev, gain); r = rtlsdr_set_tuner_gain(dev, gain);
if (r < 0) if (r < 0)
fprintf(stderr, "WARNING: Failed to set tuner gain.\n"); fprintf(stderr, "WARNING: Failed to set tuner gain.\n");
else else
fprintf(stderr, "Tuner gain set to %f dB.\n", gain/10.0); fprintf(stderr, "Tuner gain set to %f dB.\n", gain/10.0);
}
if(strcmp(filename, "-") == 0) { /* Write samples to stdout */ if(strcmp(filename, "-") == 0) { /* Write samples to stdout */
file = stdout; file = stdout;

@ -76,15 +76,15 @@ static int do_exit = 0;
void usage(void) void usage(void)
{ {
#ifdef _WIN32 #ifdef _WIN32
printf("rtl-sdr, an I/Q recorder for RTL2832 based USB-sticks\n\n" printf("rtl_tcp, an I/Q spectrum server for RTL2832 based DVB-T receivers\n\n"
"Usage:\t rtl-sdr-win.exe [listen addr] [listen port] " "Usage:\t rtl_tcp.exe [listen addr] [listen port] "
"[samplerate in kHz] [frequency in Hz] [device index]\n"); "[samplerate in kHz] [frequency in Hz] [device index]\n");
#else #else
printf("rtl-sdr, an I/Q recorder for RTL2832 based USB-sticks\n\n" printf("rtl_tcp, an I/Q spectrum server for RTL2832 based DVB-T receivers\n\n"
"Usage:\t[-a listen address]\n" "Usage:\t[-a listen address]\n"
"\t[-p listen port (default: 1234)]\n" "\t[-p listen port (default: 1234)]\n"
"\t[-f frequency to tune to [Hz]]\n" "\t[-f frequency to tune to [Hz]]\n"
"\t[-g tuner_gain (default: -1dB)]\n" "\t[-g gain (default: 0 for auto)]\n"
"\t[-s samplerate in Hz (default: 2048000 Hz)]\n" "\t[-s samplerate in Hz (default: 2048000 Hz)]\n"
"\t[-d device index (default: 0)]\n"); "\t[-d device index (default: 0)]\n");
#endif #endif
@ -311,7 +311,7 @@ int main(int argc, char **argv)
struct sockaddr_in local, remote; struct sockaddr_in local, remote;
int device_count; int device_count;
uint32_t dev_index = 0; uint32_t dev_index = 0;
int gain = -10; // tenths of a dB int gain = 0;
struct llist *curelem,*prev; struct llist *curelem,*prev;
pthread_attr_t attr; pthread_attr_t attr;
void *status; void *status;
@ -335,7 +335,7 @@ int main(int argc, char **argv)
frequency = (uint32_t)atof(optarg); frequency = (uint32_t)atof(optarg);
break; break;
case 'g': case 'g':
gain = (int)(atof(optarg) * 10); gain = (int)(atof(optarg) * 10); /* tenths of a dB */
break; break;
case 's': case 's':
samp_rate = (uint32_t)atof(optarg); samp_rate = (uint32_t)atof(optarg);
@ -359,7 +359,7 @@ int main(int argc, char **argv)
usage(); usage();
dev_index = atoi(argv[5]); dev_index = atoi(argv[5]);
frequency = atoi(argv[4]); frequency = atoi(argv[4]);
samp_rate = atoi(argv[3])*1000; samp_rate = atoi(argv[3])*1000; /* kHz */
port = atoi(argv[2]); port = atoi(argv[2]);
addr = argv[1]; addr = argv[1];
#endif #endif
@ -400,11 +400,24 @@ int main(int argc, char **argv)
else else
fprintf(stderr, "Tuned to %i Hz.\n", frequency); fprintf(stderr, "Tuned to %i Hz.\n", frequency);
if (0 == gain) {
/* Enable automatic gain */
r = rtlsdr_set_tuner_gain_mode(dev, 0);
if (r < 0)
fprintf(stderr, "WARNING: Failed to enable automatic gain.\n");
} else {
/* Enable manual gain */
r = rtlsdr_set_tuner_gain_mode(dev, 1);
if (r < 0)
fprintf(stderr, "WARNING: Failed to enable manual gain.\n");
/* Set the tuner gain */
r = rtlsdr_set_tuner_gain(dev, gain); r = rtlsdr_set_tuner_gain(dev, gain);
if (r < 0) if (r < 0)
fprintf(stderr, "WARNING: Failed to set tuner gain.\n"); fprintf(stderr, "WARNING: Failed to set tuner gain.\n");
else else
fprintf(stderr, "Tuner gain set to %f dB.\n", gain/10.0); fprintf(stderr, "Tuner gain set to %f dB.\n", gain/10.0);
}
/* Reset endpoint before we start reading from it (mandatory) */ /* Reset endpoint before we start reading from it (mandatory) */
r = rtlsdr_reset_buffer(dev); r = rtlsdr_reset_buffer(dev);

@ -44,12 +44,12 @@ static rtlsdr_dev_t *dev = NULL;
void usage(void) void usage(void)
{ {
#ifdef _WIN32 #ifdef _WIN32
fprintf(stderr,"rtl-sdr, an I/Q recorder for RTL2832 based USB-sticks\n\n" fprintf(stderr,"rtl_test, a benchmark tool for RTL2832 based DVB-T receivers\n\n"
"Usage:\t rtl-test-win.exe [device_index] [samplerate in kHz] [e4k test mode]\n" "Usage:\t rtl_test.exe [device_index] [samplerate in kHz] [e4k test mode]\n"
"\ti.e. rtl-test-win.exe 0 2048 1\n"); "\ti.e. rtl_test.exe 0 2048 1\n");
#else #else
fprintf(stderr, fprintf(stderr,
"rtl_test, librtlsdr test tool\n\n" "rtl_test, a benchmark tool for RTL2832 based DVB-T receivers\n\n"
"Usage:\n" "Usage:\n"
"\t[-s samplerate (default: 2048000 Hz)]\n" "\t[-s samplerate (default: 2048000 Hz)]\n"
"\t[-d device_index (default: 0)]\n" "\t[-d device_index (default: 0)]\n"

Loading…
Cancel
Save