From 9498885af12546dd2cf181faa2900e0c5eae67dc Mon Sep 17 00:00:00 2001
From: Stephen D <webmaster@scd31.com>
Date: Fri, 23 Feb 2024 19:44:16 -0400
Subject: [PATCH] add bias-T config

---
 config.example.toml |  1 +
 src/config.rs       |  2 ++
 src/decoder/mod.rs  |  8 +++++++-
 src/decoder/rtl.rs  | 10 +++++++++-
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/config.example.toml b/config.example.toml
index e90621d..a662c67 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -1,6 +1,7 @@
 # rtl_fm parameters
 frequency = 430_500_000 # center frequency, Hz
 device_id = "0" # ID of your RTL-SDR; 0 is default
+bias_t = false
 # gain = 30.0 # dB. Uses AGC when not specified
 
 # if set to true:
diff --git a/src/config.rs b/src/config.rs
index fae5464..7c4a853 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -37,6 +37,8 @@ pub struct Config {
     pub frequency: u32,
     #[serde(default = "default_device_id")]
     pub device_id: String,
+    #[serde(default)]
+    pub bias_t: bool,
     pub gain: Option<f32>,
     #[serde(default)]
     pub use_stdin: bool,
diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs
index 3457fae..5f5e858 100644
--- a/src/decoder/mod.rs
+++ b/src/decoder/mod.rs
@@ -27,7 +27,13 @@ pub fn decode_forever(felinet_send: mpsc::Sender<SemiPacketIn>, config: &Config,
 
         Box::new(stdin.bytes().map(|x| x.expect("Could not read from stdin")))
     } else {
-        let rtl = RtlSdr::new(config.frequency, &config.device_id, config.gain).unwrap();
+        let rtl = RtlSdr::new(
+            config.frequency,
+            &config.device_id,
+            config.gain,
+            config.bias_t,
+        )
+        .unwrap();
         Box::new(rtl)
     };
 
diff --git a/src/decoder/rtl.rs b/src/decoder/rtl.rs
index 7e7bb07..060cd66 100644
--- a/src/decoder/rtl.rs
+++ b/src/decoder/rtl.rs
@@ -11,7 +11,12 @@ pub struct RtlSdr {
 }
 
 impl RtlSdr {
-    pub fn new(freq: u32, device_id: &str, gain: Option<f32>) -> anyhow::Result<Self> {
+    pub fn new(
+        freq: u32,
+        device_id: &str,
+        gain: Option<f32>,
+        bias_t: bool,
+    ) -> anyhow::Result<Self> {
         let freq = format!("{freq}");
         let mut args = vec![
             "rtl_fm", "-f", &freq, "-M", "raw", "-F9", "-p", "0", "-d", device_id, "-s", "48000",
@@ -22,6 +27,9 @@ impl RtlSdr {
             gain_s.push_str(&format!("{:.2}", g));
             args.push(&gain_s);
         }
+        if bias_t {
+            args.push("-T");
+        }
         let mut process = Popen::create(
             &args,
             PopenConfig {
-- 
GitLab