From 782f6c39364a529a6e565708da7e21258533ca21 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 24 Sep 2026 15:41:48 +0200 Subject: [PATCH] periodic HK support for MGMs --- satrs-example/client/src/main.rs | 38 +++++++++++++++++++++----------- satrs-example/src/acs/mgm.rs | 6 +++-- satrs-example/types/src/lib.rs | 4 ++-- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/satrs-example/client/src/main.rs b/satrs-example/client/src/main.rs index 9a46051..f301d2c 100644 --- a/satrs-example/client/src/main.rs +++ b/satrs-example/client/src/main.rs @@ -1,4 +1,4 @@ -use anyhow::bail; +use anyhow::{Context as _, bail}; use arbitrary_int::u11; use clap::Parser as _; use satrs_example::config::{OBSW_SERVER_ADDR, SERVER_PORT}; @@ -116,6 +116,14 @@ enum FaultKind { Permanent, } +#[derive(Debug, PartialEq, Eq, Clone, Copy, clap::ValueEnum)] +enum HkSelect { + OneShot, + EnablePeriodic, + DisablePeriodic, + ModifyInterval, +} + #[derive(Debug, PartialEq, Eq, Clone, Copy, clap::ValueEnum)] enum HealthStateSelect { Healthy, @@ -141,14 +149,15 @@ impl From for satrs::health::HealthState { struct MgmArgs { #[arg(short, long)] ping: bool, + /// Housekeeping request for the sensor data set. + #[arg(long, value_enum)] + hk: Option, + /// Periodic HK interval. Required for `modify-interval`, optional for `enable-periodic`. #[arg(long)] - request_hk: bool, + hk_interval_ms: Option, #[arg(short, long)] mode: Option, /// Inject (or clear) an SPI bus failure on the simulated device, bypassing the OBSW. - /// - /// Only takes effect for MGM0: minisim always routes this fault to the MGM0 model - /// regardless of which MGM the request names (a pre-existing minisim limitation). #[arg(long, value_enum)] fault: Option, /// Whether a power cycle clears the injected SPI fault. @@ -225,13 +234,22 @@ fn handle_mgm_command( let request_packet = request.to_vec(); client.send_to(&request_packet, addr).unwrap(); } - if args.request_hk { + if let Some(hk) = args.hk { + let opt_interval = args.hk_interval_ms.map(Duration::from_millis); + let req_type = match hk { + HkSelect::OneShot => types::HkRequestType::OneShot, + HkSelect::EnablePeriodic => types::HkRequestType::EnablePeriodic(opt_interval), + HkSelect::DisablePeriodic => types::HkRequestType::DisablePeriodic, + HkSelect::ModifyInterval => types::HkRequestType::ModifyInterval( + opt_interval.context("--hk-interval-ms is required for modify-interval")?, + ), + }; let request = types::ccsds::CcsdsTcPacketOwned::new_with_request( SpacePacketHeader::new_from_apid(u11::new(Apid::Acs as u16)), TcHeader::new(target_id, types::MessageType::Hk), types::acs::mgm::request::Request::Hk(HkRequest { id: types::acs::mgm::request::HkId::Sensor, - req_type: types::HkRequestType::OneShot, + req_type, }), ); let sent_tc_id = CcsdsPacketIdAndPsc::new_from_ccsds_packet(&request.sp_header); @@ -585,12 +603,6 @@ fn handle_raw_tm_packet(data: &[u8]) -> anyhow::Result<()> { tm_header.sender_id, tc_id.raw() ); - } else { - log::info!( - "Received unsolicited TM with APID {} and from sender {:?}", - packet.apid(), - tm_header.sender_id, - ); } if tm_header.message_type == MessageType::Event { handle_event(tm_header.sender_id, remainder); diff --git a/satrs-example/src/acs/mgm.rs b/satrs-example/src/acs/mgm.rs index 14cc6ae..913a0ad 100644 --- a/satrs-example/src/acs/mgm.rs +++ b/satrs-example/src/acs/mgm.rs @@ -395,9 +395,11 @@ impl MgmHandlerLis3Mdl { HkRequestType::OneShot => { self.generate_hk(tc_id); } - HkRequestType::EnablePeriodic(duration) => { + HkRequestType::EnablePeriodic(opt_interval) => { self.hk_helper.enabled = true; - self.hk_helper.frequency = duration; + if let Some(interval) = opt_interval { + self.hk_helper.frequency = interval; + } } HkRequestType::DisablePeriodic => { self.hk_helper.enabled = false; diff --git a/satrs-example/types/src/lib.rs b/satrs-example/types/src/lib.rs index c760d7d..cd32071 100644 --- a/satrs-example/types/src/lib.rs +++ b/satrs-example/types/src/lib.rs @@ -224,8 +224,8 @@ impl FromStr for DeviceMode { #[non_exhaustive] pub enum HkRequestType { OneShot, - /// Enable periodic HK generation with a specified frequency. - EnablePeriodic(core::time::Duration), + /// Enable periodic HK generation. Without an interval, the current interval is kept. + EnablePeriodic(Option), DisablePeriodic, /// Modify periodic HK generation interval. ModifyInterval(core::time::Duration),