diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/.gitignore | 3 | ||||
-rw-r--r-- | test/Makefile | 15 | ||||
-rw-r--r-- | test/get_device_list.c | 30 | ||||
-rw-r--r-- | test/read_samples.c | 73 |
4 files changed, 121 insertions, 0 deletions
diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..3fc1845 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,3 @@ +get_device_list +read_samples +*.o
\ No newline at end of file diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..8e36d37 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,15 @@ +CC=gcc +CFLAGS=-I../../r820t/include +LDFLAGS= `pkg-config --libs libusb` -L../../../r820t -lr820t -Wl,-rpath=../../../r820t + +SOURCE += $(wildcard *.c) +BIN = $(SOURCE:.c=) + +make: $(BIN) + @echo $< + +%: %.c + $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ + +clean: + rm -f $(BIN)
\ No newline at end of file diff --git a/test/get_device_list.c b/test/get_device_list.c new file mode 100644 index 0000000..f65c551 --- /dev/null +++ b/test/get_device_list.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +//rtlsdr +#include <rtl-sdr.h> + +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 ); + rtlsdr_get_device_usb_strings( i, manuf, product, serial ); + printf("\\ + Manufact:%s\n\\ + Product:%s\n\\ + Serial:%s\n", manuf, product, serial ); + } + + return 0; +}
\ No newline at end of file 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 |