diff --git a/src/rt/ppm.rs b/src/rt/ppm.rs index 2612fb1..010a70c 100644 --- a/src/rt/ppm.rs +++ b/src/rt/ppm.rs @@ -23,7 +23,7 @@ const CLIP_INDICATOR_WAIT_S: Duration = Duration::from_secs(4); const LEVEL_THRESHOLD_FOR_LOW_LEVEL: Flt = -50.; /// If the signal level falls below this value, we indicate that the signal level is low. -const LEVEL_THRESHOLD_FOR_HIGH_LEVEL: Flt = -5.; +const LEVEL_THRESHOLD_FOR_HIGH_LEVEL: Flt = -10.; type SharedPPMStatus = Arc>>; @@ -39,26 +39,28 @@ pub struct PPM { impl PPM { /// Initialize a new PPM meter. + /// + /// Args + /// + /// - `mgr`: Stream manager instance. pub fn new(mgr: &mut StreamMgr) -> Self { let (sender, rxmsg) = unbounded(); - let (tx, rxstream) = unbounded(); - - // Add queue sender part of queue to stream manager - mgr.addInQueue(tx); // Shared status object let status: SharedPPMStatus = Arc::new(Mutex::new(vec![])); // Start the thread that calculates PPM and clip values - Self::startThread(status.clone(), rxstream, rxmsg); + Self::startThread(status.clone(), mgr, rxmsg); PPM { status, sender } } - fn startThread( - status: SharedPPMStatus, - rxstream: Receiver, - rxmsg: Receiver, - ) { + fn startThread(status: SharedPPMStatus, mgr: &mut StreamMgr, rxmsg: Receiver) { + // Obtain messages from stream manager + let (tx, rxstream) = unbounded(); + + // Add queue sender part of queue to stream manager + mgr.addInQueue(tx); + rayon::spawn(move || { let mut slms: Vec = vec![]; @@ -108,7 +110,7 @@ impl PPM { } else if last_level > LEVEL_THRESHOLD_FOR_HIGH_LEVEL { ClipState::HighLevel } else if last_level < LEVEL_THRESHOLD_FOR_LOW_LEVEL { - ClipState::LowLevels + ClipState::LowLevel } else { ClipState::LevelFine } @@ -144,7 +146,7 @@ impl PPM { // Initialize levels at -300 dB, and clip state // at low levels s.push(PPMChannelStatus { - clip: ClipState::LowLevels, + clip: ClipState::LowLevel, level: -300., clip_time: None, }); @@ -158,7 +160,7 @@ impl PPM { // Loop over any messages coming in from main thread for msg in rxmsg.try_iter() { match msg { - PPMMessage::ResetClip {} => { + PPMMessage::ResetClip => { // Reset clip state to not clipped. let mut s = status.lock(); s.iter_mut().for_each(|c| c.clip = ClipState::LevelFine); @@ -201,7 +203,7 @@ impl Drop for PPM { pub enum ClipState { /// Level is rather low #[default] - LowLevels, + LowLevel, /// Default state, fine levels LevelFine, /// High levels: warning! diff --git a/src/rt/rtaps.rs b/src/rt/rtaps.rs index f1983e2..77ca460 100644 --- a/src/rt/rtaps.rs +++ b/src/rt/rtaps.rs @@ -1,4 +1,5 @@ use std::ops::Deref; +use crate::config::*; use std::thread::{self, JoinHandle}; use crate::daq::{InStreamMsg, StreamHandler, StreamMetaData, StreamMgr}; @@ -10,6 +11,7 @@ use parking_lot::Mutex; use rayon::ThreadPool; use std::sync::Arc; +#[derive(Debug)] enum RtApsComm { CommStopThread, NewResult(CPSResult),