summaryrefslogtreecommitdiff
path: root/test/read_samples.c
blob: 4ecf7be5e76c4f2710d145e5f5831b739ee1e84a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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;
}