From 8adda9187304d8f06f907bfebc93e47207fa4796 Mon Sep 17 00:00:00 2001 From: FreeArtMan <=> Date: Sat, 19 Sep 2015 20:28:13 +0100 Subject: Added few rtlsdr tests. List all devices. Try to read sample. --- test/read_samples.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/read_samples.c (limited to 'test/read_samples.c') diff --git a/test/read_samples.c b/test/read_samples.c new file mode 100644 index 0000000..4ecf7be --- /dev/null +++ b/test/read_samples.c @@ -0,0 +1,73 @@ +#include +#include + +//r820t +#include + +void read_samples( uint32_t dev_index ) +{ + const uint32_t SAMPLE_RATE = 2048000; + const int DEFAULT_BUF_LENGTH = (16 * 16384); + + + uint8_t *buffer=NULL; + int ret, n_read; + static rtlsdr_dev_t *dev = NULL; + + //open tunner + ret = rtlsdr_open(&dev, (uint32_t)dev_index); + if ( ret < 0 ) + { + printf("Cannot open device %02d\n", dev_index ); + return; + } + + ret = rtlsdr_set_sample_rate(dev, SAMPLE_RATE); + if ( ret < 0 ) + { + printf("Coulnt set sample rate to %d\n", SAMPLE_RATE); + return; + } + + ret = rtlsdr_reset_buffer(dev); + if ( ret < 0 ) + { + printf("Couldnt reset buffer\n"); + return; + } + + buffer = malloc(DEFAULT_BUF_LENGTH * sizeof(uint8_t)); + ret = rtlsdr_read_sync( dev, buffer, DEFAULT_BUF_LENGTH, &n_read ); + if (ret < 0) + { + printf("sync read failed\n"); + return; + } + free( buffer ); + + + //close tunner + rtlsdr_close( dev ); + + printf(" SUCESFULL read\n"); +} + +int main() +{ + int i; + uint32_t dev_num; + + dev_num = rtlsdr_get_device_count(); + printf("Found %d device(s)\n", dev_num ); + + printf("List device names:\n"); + for (i=0; i