diff options
author | FreeArtMan <=> | 2015-09-19 20:28:13 +0100 |
---|---|---|
committer | FreeArtMan <=> | 2015-09-19 20:28:13 +0100 |
commit | 8adda9187304d8f06f907bfebc93e47207fa4796 (patch) | |
tree | 4bd55c6ee2147ee60a821ad96f9895e25b49d06c /test/read_samples.c | |
parent | 4d44686f727d65b82a7c43121b6e4290c8e3b7ec (diff) | |
download | radiola-8adda9187304d8f06f907bfebc93e47207fa4796.tar.gz radiola-8adda9187304d8f06f907bfebc93e47207fa4796.zip |
Added few rtlsdr tests. List all devices. Try to read sample.
Diffstat (limited to 'test/read_samples.c')
-rw-r--r-- | test/read_samples.c | 73 |
1 files changed, 73 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> + +//r820t +#include <rtl-sdr.h> + +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<dev_num; i++) + { + char manuf[256], product[256], serial[256]; + const char *dn = rtlsdr_get_device_name( i ); + printf(" %02d. Device Name: %s\n", i, dn ); + read_samples( i ); + } + + return 0; +}
\ No newline at end of file |