PUS event management backend provider
This commit is contained in:
parent
0f21203d27
commit
e99ce711a5
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -297,6 +297,7 @@ dependencies = [
|
|||||||
"delegate 0.8.0",
|
"delegate 0.8.0",
|
||||||
"downcast-rs",
|
"downcast-rs",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
|
"heapless",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"postcard",
|
"postcard",
|
||||||
|
@ -8,6 +8,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
delegate = "0.8"
|
delegate = "0.8"
|
||||||
hashbrown = "0.12"
|
hashbrown = "0.12"
|
||||||
|
heapless = "0.7"
|
||||||
|
|
||||||
[dependencies.num-traits]
|
[dependencies.num-traits]
|
||||||
version = "0.2"
|
version = "0.2"
|
||||||
@ -40,4 +41,4 @@ version = "1.0"
|
|||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = ["downcast-rs/std", "alloc", "bus", "postcard/use-std", "crossbeam-channel/std"]
|
std = ["downcast-rs/std", "alloc", "bus", "postcard/use-std", "crossbeam-channel/std"]
|
||||||
alloc = []
|
alloc = []
|
||||||
|
heapless = []
|
||||||
|
@ -7,7 +7,7 @@ pub type GroupId = u16;
|
|||||||
pub type UniqueId = u16;
|
pub type UniqueId = u16;
|
||||||
pub type EventRaw = u32;
|
pub type EventRaw = u32;
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
pub enum Severity {
|
pub enum Severity {
|
||||||
INFO = 1,
|
INFO = 1,
|
||||||
LOW = 2,
|
LOW = 2,
|
||||||
@ -29,7 +29,7 @@ impl TryFrom<u8> for Severity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct Event {
|
pub struct Event {
|
||||||
severity: Severity,
|
severity: Severity,
|
||||||
group_id: GroupId,
|
group_id: GroupId,
|
||||||
|
79
fsrc-core/src/pus/event_man.rs
Normal file
79
fsrc-core/src/pus/event_man.rs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
use crate::events::Event;
|
||||||
|
use hashbrown::HashSet;
|
||||||
|
|
||||||
|
#[cfg(feature = "heapless")]
|
||||||
|
pub use heapless_mod::*;
|
||||||
|
|
||||||
|
/// This trait allows the PUS event manager implementation to stay generic over various types
|
||||||
|
/// of backend containers. These backend containers keep track on whether a particular event
|
||||||
|
/// is enabled or disabled for reporting and also expose a simple API to enable or disable the event
|
||||||
|
/// reporting.
|
||||||
|
///
|
||||||
|
/// For example, a straight forward implementation for host systems could use a
|
||||||
|
/// [hash set](https://docs.rs/hashbrown/latest/hashbrown/struct.HashSet.html)
|
||||||
|
/// structure to track disabled events. A more primitive and embedded friendly
|
||||||
|
/// solution could track this information in a static or pre-allocated list which contains
|
||||||
|
/// the disabled events.
|
||||||
|
pub trait PusEventMgmtBackendProvider {
|
||||||
|
type Error;
|
||||||
|
|
||||||
|
fn event_enabled(&self, event: &Event) -> bool;
|
||||||
|
fn enable_event_reporting(&mut self, event: &Event) -> Result<bool, Self::Error>;
|
||||||
|
fn disable_event_reporting(&mut self, event: &Event) -> Result<bool, Self::Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct DefaultPusMgmtBackendProvider {
|
||||||
|
disabled: HashSet<Event>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PusEventMgmtBackendProvider for DefaultPusMgmtBackendProvider {
|
||||||
|
type Error = ();
|
||||||
|
fn event_enabled(&self, event: &Event) -> bool {
|
||||||
|
!self.disabled.contains(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn enable_event_reporting(&mut self, event: &Event) -> Result<bool, Self::Error> {
|
||||||
|
Ok(self.disabled.remove(event))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn disable_event_reporting(&mut self, event: &Event) -> Result<bool, Self::Error> {
|
||||||
|
Ok(self.disabled.insert(*event))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "heapless")]
|
||||||
|
pub mod heapless_mod {
|
||||||
|
use super::*;
|
||||||
|
use crate::events::EventRaw;
|
||||||
|
|
||||||
|
// TODO: After a new version of heapless is released which uses hash32 version 0.3, try using
|
||||||
|
// regular Event type again.
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct HeaplessPusMgmtBckendProvider<const N: usize> {
|
||||||
|
disabled: heapless::FnvIndexSet<EventRaw, N>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const N: usize> PusEventMgmtBackendProvider for HeaplessPusMgmtBckendProvider<N> {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn event_enabled(&self, event: &Event) -> bool {
|
||||||
|
self.disabled.contains(&event.raw())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn enable_event_reporting(&mut self, event: &Event) -> Result<bool, Self::Error> {
|
||||||
|
self.disabled.insert(event.raw()).map_err(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn disable_event_reporting(&mut self, event: &Event) -> Result<bool, Self::Error> {
|
||||||
|
Ok(self.disabled.remove(&event.raw()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PusEventManager {}
|
@ -10,6 +10,7 @@ use spacepackets::tm::PusTm;
|
|||||||
use spacepackets::{ByteConversionError, SizeMissmatch};
|
use spacepackets::{ByteConversionError, SizeMissmatch};
|
||||||
|
|
||||||
pub mod event;
|
pub mod event;
|
||||||
|
pub mod event_man;
|
||||||
pub mod verification;
|
pub mod verification;
|
||||||
|
|
||||||
/// Generic error type which is also able to wrap a user send error with the user supplied type E.
|
/// Generic error type which is also able to wrap a user send error with the user supplied type E.
|
||||||
|
1
fsrc-core/tests/pus_events.rs
Normal file
1
fsrc-core/tests/pus_events.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
Loading…
Reference in New Issue
Block a user