not exactly nice..

This commit is contained in:
Robin Mueller
2026-01-16 12:31:46 +01:00
parent a516eede9e
commit 55b8ecf2a6
2 changed files with 82 additions and 42 deletions
+20 -39
View File
@@ -22,6 +22,7 @@ use satrs::mode::{
use satrs::request::{GenericMessage, MessageMetadata};
use satrs_example::config::components::NO_SENDER;
use crate::eps::PowerSwitchHelper;
use crate::spi::SpiInterface;
use serde::{Deserialize, Serialize};
@@ -150,16 +151,13 @@ impl Default for ModeHelpers {
/// Example MGM device handler strongly based on the LIS3MDL MEMS device.
#[allow(clippy::too_many_arguments)]
pub struct MgmHandlerLis3Mdl<
ComInterface: SpiInterface,
SwitchHelper: PowerSwitchInfo<SwitchId> + PowerSwitcherCommandSender<SwitchId>,
> {
pub struct MgmHandlerLis3Mdl<ComInterface: SpiInterface> {
id: ComponentId,
dev_str: &'static str,
mode_node: ModeRequestHandlerMpscBounded,
tc_rx: mpsc::Receiver<CcsdsTcPacketOwned>,
tm_tx: mpsc::SyncSender<CcsdsTmPacketOwned>,
switch_helper: SwitchHelper,
switch_helper: PowerSwitchHelper,
pub com_interface: ComInterface,
shared_mgm_set: Arc<Mutex<MgmData>>,
//hk_helper: PusHkHelper,
@@ -168,18 +166,14 @@ pub struct MgmHandlerLis3Mdl<
stamp_helper: TimestampHelper,
}
impl<
ComInterface: SpiInterface,
SwitchHelper: PowerSwitchInfo<SwitchId> + PowerSwitcherCommandSender<SwitchId>,
> MgmHandlerLis3Mdl<ComInterface, SwitchHelper>
{
impl<ComInterface: SpiInterface> MgmHandlerLis3Mdl<ComInterface> {
pub fn new(
id: ComponentId,
dev_str: &'static str,
mode_node: ModeRequestHandlerMpscBounded,
tc_rx: mpsc::Receiver<CcsdsTcPacketOwned>,
tm_tx: mpsc::SyncSender<CcsdsTmPacketOwned>,
switch_helper: SwitchHelper,
switch_helper: PowerSwitchHelper,
com_interface: ComInterface,
shared_mgm_set: Arc<Mutex<MgmData>>,
) -> Self {
@@ -356,10 +350,7 @@ impl<
self.mode_helpers.transition_state = TransitionState::PowerSwitching;
}
if self.mode_helpers.transition_state == TransitionState::PowerSwitching
&& self
.switch_helper
.is_switch_on(SwitchId::Mgm0)
.expect("switch info error")
&& self.switch_helper.is_switch_on(SwitchId::Mgm0)
{
self.mode_helpers.transition_state = TransitionState::Done;
}
@@ -373,21 +364,13 @@ impl<
}
}
impl<
ComInterface: SpiInterface,
SwitchHelper: PowerSwitchInfo<SwitchId> + PowerSwitcherCommandSender<SwitchId>,
> ModeProvider for MgmHandlerLis3Mdl<ComInterface, SwitchHelper>
{
impl<ComInterface: SpiInterface> ModeProvider for MgmHandlerLis3Mdl<ComInterface> {
fn mode_and_submode(&self) -> ModeAndSubmode {
self.mode_helpers.current
}
}
impl<
ComInterface: SpiInterface,
SwitchHelper: PowerSwitchInfo<SwitchId> + PowerSwitcherCommandSender<SwitchId>,
> ModeRequestHandler for MgmHandlerLis3Mdl<ComInterface, SwitchHelper>
{
impl<ComInterface: SpiInterface> ModeRequestHandler for MgmHandlerLis3Mdl<ComInterface> {
type Error = ModeError;
fn start_transition(
@@ -472,21 +455,13 @@ impl<
}
}
impl<
ComInterface: SpiInterface,
SwitchHelper: PowerSwitchInfo<SwitchId> + PowerSwitcherCommandSender<SwitchId>,
> ModeNode for MgmHandlerLis3Mdl<ComInterface, SwitchHelper>
{
impl<ComInterface: SpiInterface> ModeNode for MgmHandlerLis3Mdl<ComInterface> {
fn id(&self) -> satrs::ComponentId {
self.id as u32
}
}
impl<
ComInterface: SpiInterface,
SwitchHelper: PowerSwitchInfo<SwitchId> + PowerSwitcherCommandSender<SwitchId>,
> ModeChild for MgmHandlerLis3Mdl<ComInterface, SwitchHelper>
{
impl<ComInterface: SpiInterface> ModeChild for MgmHandlerLis3Mdl<ComInterface> {
type Sender = mpsc::SyncSender<GenericMessage<ModeReply>>;
fn add_mode_parent(&mut self, id: satrs::ComponentId, reply_sender: Self::Sender) {
@@ -501,7 +476,7 @@ mod tests {
sync::{mpsc, Arc},
};
use models::ComponentId;
use models::{pcdu::SwitchRequest, ComponentId};
use satrs::{
mode::{ModeReply, ModeRequest},
mode_tree::ModeParent,
@@ -511,7 +486,7 @@ mod tests {
};
use satrs_minisim::acs::lis3mdl::MgmLis3RawValues;
use crate::eps::TestSwitchHelper;
use crate::eps::{pcdu::SharedSwitchSet, TestSwitchHelper};
use super::*;
@@ -541,9 +516,11 @@ mod tests {
pub mode_request_tx: mpsc::SyncSender<GenericMessage<ModeRequest>>,
pub mode_reply_rx_to_pus: mpsc::Receiver<GenericMessage<ModeReply>>,
pub mode_reply_rx_to_parent: mpsc::Receiver<GenericMessage<ModeReply>>,
pub shared_switch_set: SharedSwitchSet,
pub tc_tx: mpsc::SyncSender<CcsdsTcPacketOwned>,
pub tm_rx: mpsc::Receiver<PacketAsVec>,
pub handler: MgmHandlerLis3Mdl<TestSpiInterface, TestSwitchHelper>,
pub switch_rx: mpsc::Receiver<GenericMessage<SwitchRequest>>,
pub handler: MgmHandlerLis3Mdl<TestSpiInterface>,
}
#[derive(Default)]
@@ -595,14 +572,16 @@ mod tests {
let (tc_tx, tc_rx) = mpsc::sync_channel(10);
let (hk_reply_tx, _hk_reply_rx) = mpsc::sync_channel(10);
let (_tm_tx, tm_rx) = mpsc::sync_channel(10);
let (switcher_tx, switcher_rx) = mpsc::sync_channel(10);
let shared_mgm_set = Arc::default();
let shared_switch_set = SharedSwitchSet::default();
let mut handler = MgmHandlerLis3Mdl::new(
ComponentId::AcsMgm0,
"TEST_MGM",
mode_node,
tc_rx,
hk_reply_tx,
TestSwitchHelper::default(),
PowerSwitchHelper::new(switcher_tx, shared_switch_set.clone()),
TestSpiInterface::default(),
shared_mgm_set,
);
@@ -612,6 +591,8 @@ mod tests {
mode_request_tx: request_tx,
mode_reply_rx_to_pus: reply_rx_to_ground,
mode_reply_rx_to_parent: reply_rx_to_parent,
shared_switch_set,
switcher_rx,
handler,
tm_rx,
tc_tx,
+62 -3
View File
@@ -1,9 +1,8 @@
use derive_new::new;
use models::pcdu::{SwitchId, SwitchRequest, SwitchStateBinary};
use models::pcdu::{SwitchId, SwitchRequest, SwitchState, SwitchStateBinary};
use std::{cell::RefCell, collections::VecDeque, sync::mpsc, time::Duration};
use satrs::{
power::{PowerSwitchInfo, PowerSwitcherCommandSender, SwitchState},
queue::GenericSendError,
request::{GenericMessage, MessageMetadata},
};
@@ -36,10 +35,65 @@ pub enum SwitchInfoError {
SwitchSetInvalid,
}
impl PowerSwitchHelper {
pub fn send_switch_on_cmd(
&self,
requestor_info: satrs::request::MessageMetadata,
switch_id: SwitchId,
) -> Result<(), GenericSendError> {
self.switcher_tx.send(GenericMessage::new(
requestor_info,
SwitchRequest::new(switch_id, SwitchStateBinary::On),
))?;
Ok(())
}
pub fn send_switch_off_cmd(
&self,
requestor_info: satrs::request::MessageMetadata,
switch_id: SwitchId,
) -> Result<(), GenericSendError> {
self.switcher_tx.send(GenericMessage::new(
requestor_info,
SwitchRequest::new(switch_id, SwitchStateBinary::Off),
))?;
Ok(())
}
pub fn switch_state(&self, switch_id: SwitchId) -> Result<SwitchState, SwitchInfoError> {
let switch_set = self
.shared_switch_set
.lock()
.expect("failed to lock switch set");
if !switch_set.valid {
return Err(SwitchInfoError::SwitchSetInvalid);
}
if let Some(state) = switch_set.switch_map.get(&switch_id) {
return Ok(*state);
}
Err(SwitchInfoError::SwitchIdNotInMap(switch_id))
}
fn switch_delay_ms(&self) -> Duration {
// Here, we could set device specific switch delays theoretically. Set it to this value
// for now.
Duration::from_millis(1000)
}
pub fn is_switch_on(&self, switch_id: SwitchId) -> bool {
if let Ok(state) = self.switch_state(switch_id) {
state == SwitchState::On
} else {
false
}
}
}
/*
impl PowerSwitchInfo<SwitchId> for PowerSwitchHelper {
type Error = SwitchInfoError;
fn switch_state(&self, switch_id: SwitchId) -> Result<satrs::power::SwitchState, Self::Error> {
fn switch_state(&self, switch_id: SwitchId) -> Result<SwitchState, Self::Error> {
let switch_set = self
.shared_switch_set
.lock()
@@ -60,7 +114,9 @@ impl PowerSwitchInfo<SwitchId> for PowerSwitchHelper {
Duration::from_millis(1000)
}
}
*/
/*
impl PowerSwitcherCommandSender<SwitchId> for PowerSwitchHelper {
type Error = SwitchCommandingError;
@@ -88,6 +144,7 @@ impl PowerSwitcherCommandSender<SwitchId> for PowerSwitchHelper {
Ok(())
}
}
*/
#[allow(dead_code)]
#[derive(new)]
@@ -121,6 +178,7 @@ impl Default for TestSwitchHelper {
}
}
/*
impl PowerSwitchInfo<SwitchId> for TestSwitchHelper {
type Error = SwitchInfoError;
@@ -185,6 +243,7 @@ impl PowerSwitcherCommandSender<SwitchId> for TestSwitchHelper {
Ok(())
}
}
*/
#[allow(dead_code)]
impl TestSwitchHelper {