summaryrefslogtreecommitdiff
path: root/test/dump_eeprom.c
blob: b32e74e9c2942803206dcdeca28b172a6e6b0c26 (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
74
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

//rtlsdr
#include <rtl-sdr.h>
#include <hw/sdr.h>
#include <hw/hw.h>
#include <hw/hw_eeprom.h>

int print_dump( uint8_t *data, uint16_t size )
{
	int i;
	const int line_sz = 32;
	for (i=0; i<size;i++)
	{
		printf("%02x ", data[i]);
		if (i % 32 == 31)
		{
			printf("\n");
		}
	}
	for (i=0; i<size;i++)
	{
		if ( isprint(data[i]) )
		{
			printf("%c", data[i]);
		} else
		{
			printf(".");
		}
		if (i % 32 == 31)
		{
			printf("\n");
		}
	}
	return 0;
}

int main(  )
{
	int i;
	uint32_t dev_num;
	rtlsdr_dev_t *dev=NULL;
	int ret;

	const int buf_size = 256;
	uint8_t buf[buf_size];

	memset(buf, 0, buf_size );

	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++)
	{
		hw_open( &dev, i );

		ret = dump_eeprom( dev, buf, buf_size );
		if (ret != 0)
		{
			printf("Couldnt dump eeprom\n");
		} else
		{
			printf("Dumped device %d\n",i);
		}
		print_dump( buf, buf_size );

		hw_close( dev );
	}

	return 0;
}