X-Git-Url: https://code.octet-stream.net/m17rt/blobdiff_plain/608ca7e33ab51d812607ddcc3429bfa9aa3c34b0..16aaa4ac98d3719986e49623483c7f17306a4f95:/m17app/src/rtlsdr.rs diff --git a/m17app/src/rtlsdr.rs b/m17app/src/rtlsdr.rs index 33f8070..269769b 100644 --- a/m17app/src/rtlsdr.rs +++ b/m17app/src/rtlsdr.rs @@ -1,21 +1,12 @@ use std::{ io::Read, process::{Child, Command, Stdio}, - sync::{ - mpsc::{sync_channel, Receiver, SyncSender}, - Arc, Mutex, RwLock, - }, - time::{Duration, Instant}, -}; - -use cpal::{ - traits::{DeviceTrait, HostTrait, StreamTrait}, - SampleFormat, SampleRate, Stream, + sync::{mpsc::SyncSender, Mutex}, }; use crate::{ error::M17Error, - soundmodem::{InputSource, OutputBuffer, OutputSink, SoundmodemEvent}, + soundmodem::{InputSource, SoundmodemErrorSender, SoundmodemEvent}, }; pub struct RtlSdr { @@ -35,9 +26,8 @@ impl RtlSdr { } impl InputSource for RtlSdr { - fn start(&self, tx: SyncSender) { - // TODO: error handling - let mut cmd = Command::new("rtl_fm") + fn start(&self, tx: SyncSender, errors: SoundmodemErrorSender) { + let mut cmd = match Command::new("rtl_fm") .args([ "-E", "offset", @@ -50,7 +40,13 @@ impl InputSource for RtlSdr { ]) .stdout(Stdio::piped()) .spawn() - .unwrap(); + { + Ok(c) => c, + Err(e) => { + errors.send_error(e); + return; + } + }; let mut stdout = cmd.stdout.take().unwrap(); let mut buf = [0u8; 1024]; let mut leftover: Option = None; @@ -80,6 +76,7 @@ impl InputSource for RtlSdr { } } }); + *self.rtlfm.lock().unwrap() = Some(cmd); } fn close(&self) {