From a4fb29bee94d68b8956158f603b0366af98507e9 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Sun, 18 Apr 2021 15:13:39 +0300 Subject: Move tuner into USB handle --- src/lib.rs | 68 ++------------------------------------------------------------ 1 file changed, 2 insertions(+), 66 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 413b790..06af1c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,7 @@ extern crate rusb; mod tuners; mod usb; -use log::{error, info, trace, warn}; -use tuners::*; +use log::{info, trace}; use usb::RtlSdrDeviceHandle; const INTERFACE_ID: u8 = 0; @@ -16,24 +15,15 @@ const KNOWN_DEVICES: [(u16, u16, &str); 2] = [ (0x0bda, 0x2838, "Generic RTL2832U OEM"), ]; -const KNOWN_TUNERS: [TunerInfo; 2] = [r820t::TUNER_INFO, fc0013::TUNER_INFO]; - pub struct RtlSdr { handle: RtlSdrDeviceHandle, - tuner: Box, } impl RtlSdr { pub fn new() -> RtlSdr { pretty_env_logger::init(); - let handle = Self::open_device().unwrap(); - let tuner = Self::open_tuner(&handle).unwrap(); - - RtlSdr { - handle: handle, - tuner: tuner, - } + RtlSdr { handle: handle } } pub fn open_device() -> Option { @@ -66,60 +56,6 @@ impl RtlSdr { return None; } - fn open_tuner(handle: &RtlSdrDeviceHandle) -> Option> { - let tuner_id = match Self::search_tuner(&handle) { - Some(tid) => { - info!("Got tuner ID {}", tid); - tid - } - None => { - error!("Could not find a value tuner, aborting."); - return None; - } - }; - - let tuner: Option> = match tuner_id { - r820t::TUNER_ID => Some(Box::new(r820t::R820T::new(&handle))), - fc0013::TUNER_ID => Some(Box::new(fc0013::FC0013::new(&handle))), - _ => { - error!("Could not find any valid tuner, aborting."); - return None; - } - }; - - // info!("Found tuner {}", self.tuner.unwrap().display()); - return tuner; - } - - /// Probe all known tuners at their I2C addresses - /// and search for expected return values - fn search_tuner(handle: &RtlSdrDeviceHandle) -> Option<&str> { - for tuner_info in KNOWN_TUNERS.iter() { - let regval = handle.i2c_read_reg(tuner_info.i2c_addr, tuner_info.check_addr); - trace!( - "Probing I2C address {:#02x} checking address {:#02x}", - tuner_info.i2c_addr, - tuner_info.check_addr, - ); - match regval { - Ok(val) => { - trace!( - "Expecting value {:#02x}, got value {:#02x}", - tuner_info.check_val, - val - ); - if val == tuner_info.check_val { - return Some(tuner_info.id); - } - } - Err(_) => { - warn!("Reading failed, continuing"); - } - }; - } - None - } - pub fn set_sample_rate(&self, samp_rate: u32) { self.handle.set_sample_rate(samp_rate); } -- cgit v1.3.1