1fn main() -> rtlsdr::Result<()> {
2 let devices = rtlsdr::get_devices();
3 println!("Found {} device(s)", devices.len());
4
5 let mut device = devices[0];
6 device.open()?;
7
8 let (manufacturer, product, serial) = device.get_usb_device_strings()?;
10 println!("Device: {manufacturer} {product} {serial}");
11
12 device.set_center_freq(101_700_000)?; device.set_direct_sampling(rtlsdr::DirectSampling::Disabled)?;
15 device.set_tuner_bandwidth(0)?;
16 device.set_agc_mode(true)?;
17 device.set_tuner_gain_mode(false)?;
18 device.reset_buffer()?;
19
20 let mut buf = [0u8; 1024];
22 let n_read = device.read(&mut buf)?;
23 println!("Read {} bytes of data", n_read);
24
25 println!("Starting asynchronous reading for 3 seconds...");
27 let start = std::time::Instant::now();
28 device.start_reading(
29 |data| {
30 let avg = data.iter().map(|&b| b as u32).sum::<u32>() as f32 / data.len() as f32;
31
32 println!(
33 "Received {} bytes of data, average value: {:.2}",
34 data.len(),
35 avg
36 );
37
38 start.elapsed().as_secs_f32() >= 3.0
40 },
41 0,
42 0,
43 )?;
44
45 println!("Finished asynchronous reading.");
46
47 Ok(())
48}