add granular event management control
This commit is contained in:
@@ -58,7 +58,9 @@ pub struct SensorData {
|
||||
pub z: f32,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
#[derive(strum::EnumDiscriminants, serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
#[strum_discriminants(derive(num_enum::IntoPrimitive))]
|
||||
#[repr(u16)]
|
||||
pub enum Event {
|
||||
/// The SPI fault counter exceeded its threshold, the component was marked faulty and
|
||||
/// commanded off.
|
||||
@@ -73,6 +75,12 @@ impl crate::Message for Event {
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::EventId for Event {
|
||||
fn event_id(&self) -> u16 {
|
||||
EventDiscriminants::from(self).into()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod response {
|
||||
use crate::{DeviceMode, Message, acs::mgm::SensorData};
|
||||
|
||||
|
||||
@@ -137,7 +137,9 @@ pub mod response {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
#[derive(strum::EnumDiscriminants, serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
#[strum_discriminants(derive(num_enum::IntoPrimitive))]
|
||||
#[repr(u16)]
|
||||
pub enum Event {
|
||||
/// A commanded or autonomous mode transition completed.
|
||||
ModeChanged(Mode),
|
||||
@@ -148,3 +150,9 @@ impl crate::Message for Event {
|
||||
crate::MessageType::Event
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::EventId for Event {
|
||||
fn event_id(&self) -> u16 {
|
||||
EventDiscriminants::from(self).into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use crate::Message;
|
||||
use crate::{EventId, Message};
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
#[derive(strum::EnumDiscriminants, serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
#[strum_discriminants(derive(num_enum::IntoPrimitive))]
|
||||
#[repr(u16)]
|
||||
pub enum Event {
|
||||
TestEvent,
|
||||
}
|
||||
@@ -11,6 +13,12 @@ impl Message for Event {
|
||||
}
|
||||
}
|
||||
|
||||
impl EventId for Event {
|
||||
fn event_id(&self) -> u16 {
|
||||
EventDiscriminants::from(self).into()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod request {
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
pub enum Request {
|
||||
@@ -37,3 +45,13 @@ pub mod response {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_event_id() {
|
||||
assert_eq!(Event::TestEvent.event_id(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
pub mod request {
|
||||
use crate::ComponentId;
|
||||
|
||||
/// Controls which events are converted to TM. Component and event filters are independent:
|
||||
/// re-enabling a component does not re-enable its individually disabled events.
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Request {
|
||||
EnableComponent(ComponentId),
|
||||
DisableComponent(ComponentId),
|
||||
EnableEvent {
|
||||
sender_id: ComponentId,
|
||||
event_id: u16,
|
||||
},
|
||||
DisableEvent {
|
||||
sender_id: ComponentId,
|
||||
event_id: u16,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub mod response {
|
||||
use crate::Message;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Response {
|
||||
Ok,
|
||||
}
|
||||
|
||||
impl Message for Response {
|
||||
fn message_type(&self) -> crate::MessageType {
|
||||
crate::MessageType::Verification
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use spacepackets::{
|
||||
pub mod acs;
|
||||
pub mod ccsds;
|
||||
pub mod control;
|
||||
pub mod event_manager;
|
||||
pub mod pcdu;
|
||||
pub mod tmtc;
|
||||
|
||||
@@ -66,6 +67,14 @@ impl Message for Event {
|
||||
}
|
||||
}
|
||||
|
||||
impl EventId for Event {
|
||||
fn event_id(&self) -> u16 {
|
||||
match self {
|
||||
Event::ControllerEvent(event) => event.event_id(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct TmHeader {
|
||||
@@ -158,6 +167,14 @@ pub trait Message {
|
||||
fn message_type(&self) -> MessageType;
|
||||
}
|
||||
|
||||
/// Stable, per-variant numeric identifier for an event, meant to be referenced from ground
|
||||
/// (e.g. to enable/disable TM generation for one specific event) and to stay the same across
|
||||
/// releases. Unlike [core::mem::discriminant], this can be constructed from a raw number
|
||||
/// received in a telecommand.
|
||||
pub trait EventId {
|
||||
fn event_id(&self) -> u16;
|
||||
}
|
||||
|
||||
/// Generic device mode which covers the requirements of most devices.
|
||||
///
|
||||
/// The states are related both to the physical and the logical state of the device. Some
|
||||
|
||||
@@ -56,7 +56,9 @@ pub enum SwitchStateBinary {
|
||||
On = 1,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
#[derive(strum::EnumDiscriminants, serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
#[strum_discriminants(derive(num_enum::IntoPrimitive))]
|
||||
#[repr(u16)]
|
||||
pub enum Event {
|
||||
/// Sending a request to the PCDU over the serial/simulator link failed.
|
||||
SerialCommError,
|
||||
@@ -68,6 +70,12 @@ impl crate::Message for Event {
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::EventId for Event {
|
||||
fn event_id(&self) -> u16 {
|
||||
EventDiscriminants::from(self).into()
|
||||
}
|
||||
}
|
||||
|
||||
pub type SwitchMapBinary = HashMap<SwitchId, SwitchStateBinary>;
|
||||
|
||||
pub struct SwitchMapBinaryWrapper(pub SwitchMapBinary);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use crate::{ComponentId, Message};
|
||||
use crate::{ComponentId, EventId, Message};
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
#[derive(strum::EnumDiscriminants, serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
#[strum_discriminants(derive(num_enum::IntoPrimitive))]
|
||||
#[repr(u16)]
|
||||
pub enum Event {
|
||||
/// A received CCSDS packet failed CRC or basic format validation.
|
||||
InvalidTcPacket,
|
||||
@@ -15,3 +17,9 @@ impl Message for Event {
|
||||
crate::MessageType::Event
|
||||
}
|
||||
}
|
||||
|
||||
impl EventId for Event {
|
||||
fn event_id(&self) -> u16 {
|
||||
EventDiscriminants::from(self).into()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user