cosmetic fixes/cleanup

Signed-off-by: Steve Markgraf <steve@steve-m.de>
master
Steve Markgraf 13 years ago
parent 542533c229
commit ffea5061f0
  1. 13
      src/main.c
  2. 22
      src/rtl-sdr.c

@ -100,15 +100,13 @@ int main(int argc, char **argv)
/* Set the sample rate */ /* Set the sample rate */
r = rtlsdr_set_sample_rate(dev, samp_rate); r = rtlsdr_set_sample_rate(dev, samp_rate);
if (r < 0) { if (r < 0)
fprintf(stderr, "WARNING: Failed to set sample rate.\n"); fprintf(stderr, "WARNING: Failed to set sample rate.\n");
}
/* Set the frequency */ /* Set the frequency */
r = rtlsdr_set_center_freq(dev, frequency); r = rtlsdr_set_center_freq(dev, frequency);
if (r < 0) { if (r < 0)
fprintf(stderr, "WARNING: Failed to set center freq.\n"); fprintf(stderr, "WARNING: Failed to set center freq.\n");
}
file = fopen(filename, "wb"); file = fopen(filename, "wb");
@ -119,16 +117,15 @@ int main(int argc, char **argv)
/* Reset endpoint before we start reading from it */ /* Reset endpoint before we start reading from it */
r = rtlsdr_reset_buffer(dev); r = rtlsdr_reset_buffer(dev);
if (r < 0) { if (r < 0)
fprintf(stderr, "WARNING: Failed to reset buffers.\n"); fprintf(stderr, "WARNING: Failed to reset buffers.\n");
}
printf("Reading samples...\n"); printf("Reading samples...\n");
while (!do_exit) { while (!do_exit) {
r = rtlsdr_read_sync(dev, buffer, READLEN, &n_read); r = rtlsdr_read_sync(dev, buffer, READLEN, &n_read);
if (r < 0) { if (r < 0)
fprintf(stderr, "WARNING: sync read failed.\n"); fprintf(stderr, "WARNING: sync read failed.\n");
}
fwrite(buffer, n_read, 1, file); fwrite(buffer, n_read, 1, file);

@ -48,6 +48,7 @@ int fc0013_tune(void *dev, int freq) {
//fc0013_GetBandwidthMode(dev, &bw); // FIXME: missing //fc0013_GetBandwidthMode(dev, &bw); // FIXME: missing
return FC0013_SetFrequency(dev, freq/1000, bw & 0xff); return FC0013_SetFrequency(dev, freq/1000, bw & 0xff);
} }
int fc0013_set_bw(void *dev, int bw) { int fc0013_set_bw(void *dev, int bw) {
/* read frequency to reapply it */ /* read frequency to reapply it */
unsigned long freq = 0; unsigned long freq = 0;
@ -82,11 +83,11 @@ struct rtlsdr_device {
uint16_t vid; uint16_t vid;
uint16_t pid; uint16_t pid;
} devices[] = { } devices[] = {
{ 0x0bda, 0x2832, /*RTLSDR_TUNER_E4000,*/ }, /* default RTL2832U vid/pid (eg. hama nano) */ { 0x0bda, 0x2832 }, /* default RTL2832U vid/pid (eg. hama nano) */
{ 0x0bda, 0x2838, /*RTLSDR_TUNER_E4000,*/ }, /* ezcap USB 2.0 DVB-T/DAB/FM stick */ { 0x0bda, 0x2838 }, /* ezcap USB 2.0 DVB-T/DAB/FM stick */
{ 0x0ccd, 0x00b3, /*RTLSDR_TUNER_FC0013,*/ }, /* Terratec NOXON DAB/DAB+ USB-Stick */ { 0x0ccd, 0x00b3 }, /* Terratec NOXON DAB/DAB+ USB-Stick */
{ 0x1f4d, 0xb803, /*RTLSDR_TUNER_FC0012,*/ }, /* GTek T803 */ { 0x1f4d, 0xb803 }, /* GTek T803 */
{ 0x1b80, 0xd3a4, /*RTLSDR_TUNER_FC0013,*/ }, /* Twintech UT-40 */ { 0x1b80, 0xd3a4 }, /* Twintech UT-40 */
}; };
typedef struct { typedef struct {
@ -311,15 +312,10 @@ int rtlsdr_set_center_freq(rtlsdr_dev_t *dev, uint32_t freq)
if (dev->tuner) { if (dev->tuner) {
dev->tuner->freq = freq; dev->tuner->freq = freq;
double f = (double) freq; double f = (double) freq;
f *= 1.0 + dev->tuner->corr / 1e6; f *= 1.0 + dev->tuner->corr / 1e6;
dev->tuner->tune((void *)dev, (int) f); dev->tuner->tune((void *)dev, (int) f);
printf("Tuned to %i Hz\n", freq); printf("Tuned to %i Hz\n", freq);
} }
rtlsdr_set_i2c_repeater(dev, 0); rtlsdr_set_i2c_repeater(dev, 0);
@ -408,11 +404,10 @@ uint32_t rtlsdr_get_device_count(void)
libusb_get_device_descriptor(list[i], &dd); libusb_get_device_descriptor(list[i], &dd);
for (j = 0; j < sizeof(devices)/sizeof(struct rtlsdr_device); j++ ) { for (j = 0; j < sizeof(devices)/sizeof(struct rtlsdr_device); j++ ) {
if ( devices[j].vid == dd.idVendor && devices[j].pid == dd.idProduct ) { if (devices[j].vid == dd.idVendor && devices[j].pid == dd.idProduct)
device_count++; device_count++;
} }
} }
}
libusb_free_device_list(list, 0); libusb_free_device_list(list, 0);
@ -460,7 +455,6 @@ rtlsdr_dev_t *rtlsdr_open(int index)
for (j = 0; j < sizeof(devices)/sizeof(struct rtlsdr_device); j++ ) { for (j = 0; j < sizeof(devices)/sizeof(struct rtlsdr_device); j++ ) {
if ( devices[j].vid == dd.idVendor && devices[j].pid == dd.idProduct ) { if ( devices[j].vid == dd.idVendor && devices[j].pid == dd.idProduct ) {
device_count++; device_count++;
if (index == device_count - 1) if (index == device_count - 1)
break; break;
} }
@ -514,9 +508,7 @@ err:
int rtlsdr_close(rtlsdr_dev_t *dev) int rtlsdr_close(rtlsdr_dev_t *dev)
{ {
libusb_release_interface(dev->devh, 0); libusb_release_interface(dev->devh, 0);
libusb_close(dev->devh); libusb_close(dev->devh);
free(dev); free(dev);
return 0; return 0;

Loading…
Cancel
Save