diff --git a/satrs-core/Cargo.toml b/satrs-core/Cargo.toml index f4fcde8..3c5606a 100644 --- a/satrs-core/Cargo.toml +++ b/satrs-core/Cargo.toml @@ -7,11 +7,14 @@ edition = "2021" [dependencies] delegate = "0.8" -hashbrown = "0.13" paste = "1.0" dyn-clone = "1.0" embed-doc-image = "0.1" +[dependencies.hashbrown] +version = "0.13" +optional = true + [dependencies.heapless] version = "0.7" optional = true @@ -55,7 +58,7 @@ version = "1.0" [features] default = ["std"] std = ["downcast-rs/std", "alloc", "bus", "postcard/use-std", "crossbeam-channel/std", "serde/std", "spacepackets/std"] -alloc = ["serde/alloc", "spacepackets/alloc"] +alloc = ["serde/alloc", "spacepackets/alloc", "hashbrown"] serde = ["dep:serde", "spacepackets/serde"] crossbeam = ["crossbeam-channel"] heapless = ["dep:heapless"] diff --git a/satrs-core/src/event_man.rs b/satrs-core/src/event_man.rs index 794ce28..5d2db19 100644 --- a/satrs-core/src/event_man.rs +++ b/satrs-core/src/event_man.rs @@ -63,6 +63,7 @@ use alloc::vec; #[cfg(feature = "alloc")] use alloc::vec::Vec; use core::slice::Iter; +#[cfg(feature = "alloc")] use hashbrown::HashMap; #[cfg(feature = "std")] diff --git a/satrs-core/src/pus/event_man.rs b/satrs-core/src/pus/event_man.rs index 380cbc8..611add8 100644 --- a/satrs-core/src/pus/event_man.rs +++ b/satrs-core/src/pus/event_man.rs @@ -3,7 +3,9 @@ use crate::events::{EventU32, GenericEvent, Severity}; use crate::events::{EventU32TypedSev, HasSeverity}; #[cfg(feature = "alloc")] use alloc::boxed::Box; +#[cfg(feature = "alloc")] use core::hash::Hash; +#[cfg(feature = "alloc")] use hashbrown::HashSet; #[cfg(feature = "alloc")] @@ -38,43 +40,6 @@ pub trait PusEventMgmtBackendProvider { fn disable_event_reporting(&mut self, event: &Provider) -> Result; } -/// Default backend provider which uses a hash set as the event reporting status container -/// like mentioned in the example of the [PusEventMgmtBackendProvider] documentation. -/// -/// This provider is a good option for host systems or larger embedded systems where -/// the expected occasional memory allocation performed by the [HashSet] is not an issue. -pub struct DefaultPusMgmtBackendProvider { - disabled: HashSet, -} - -/// Safety: All contained field are [Send] as well -unsafe impl Send for DefaultPusMgmtBackendProvider {} - -impl Default for DefaultPusMgmtBackendProvider { - fn default() -> Self { - Self { - disabled: HashSet::default(), - } - } -} - -impl - PusEventMgmtBackendProvider for DefaultPusMgmtBackendProvider -{ - type Error = (); - fn event_enabled(&self, event: &Provider) -> bool { - !self.disabled.contains(event) - } - - fn enable_event_reporting(&mut self, event: &Provider) -> Result { - Ok(self.disabled.remove(event)) - } - - fn disable_event_reporting(&mut self, event: &Provider) -> Result { - Ok(self.disabled.insert(*event)) - } -} - #[cfg(feature = "heapless")] pub mod heapless_mod { use super::*; @@ -145,6 +110,43 @@ impl From> for EventManError { pub mod alloc_mod { use super::*; + /// Default backend provider which uses a hash set as the event reporting status container + /// like mentioned in the example of the [PusEventMgmtBackendProvider] documentation. + /// + /// This provider is a good option for host systems or larger embedded systems where + /// the expected occasional memory allocation performed by the [HashSet] is not an issue. + pub struct DefaultPusMgmtBackendProvider { + disabled: HashSet, + } + + /// Safety: All contained field are [Send] as well + unsafe impl Send for DefaultPusMgmtBackendProvider {} + + impl Default for DefaultPusMgmtBackendProvider { + fn default() -> Self { + Self { + disabled: HashSet::default(), + } + } + } + + impl + PusEventMgmtBackendProvider for DefaultPusMgmtBackendProvider + { + type Error = (); + fn event_enabled(&self, event: &Provider) -> bool { + !self.disabled.contains(event) + } + + fn enable_event_reporting(&mut self, event: &Provider) -> Result { + Ok(self.disabled.remove(event)) + } + + fn disable_event_reporting(&mut self, event: &Provider) -> Result { + Ok(self.disabled.insert(*event)) + } + } + pub struct PusEventDispatcher { reporter: EventReporter, backend: Box>, diff --git a/satrs-core/src/pus/verification.rs b/satrs-core/src/pus/verification.rs index 1f6c6da..0e54fdf 100644 --- a/satrs-core/src/pus/verification.rs +++ b/satrs-core/src/pus/verification.rs @@ -95,7 +95,7 @@ pub use alloc_mod::{ }; use crate::seq_count::SequenceCountProvider; -#[cfg(feature = "crossbeam")] +#[cfg(all(feature = "crossbeam", feature = "std"))] pub use stdmod::CrossbeamVerifSender; #[cfg(feature = "std")] pub use stdmod::{ diff --git a/satrs-core/tests/pus_verification.rs b/satrs-core/tests/pus_verification.rs index dac580a..66f414e 100644 --- a/satrs-core/tests/pus_verification.rs +++ b/satrs-core/tests/pus_verification.rs @@ -1,3 +1,4 @@ +// TODO: Refactor this to also test the STD impl using mpsc #[cfg(feature = "crossbeam")] pub mod crossbeam_test { use hashbrown::HashMap;