From 067c731f1637fc3856334b27eab2d12d5b0a3e81 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 3 Jun 2024 14:19:48 +0200 Subject: [PATCH] periodic MGM data looks good --- satrs-example/src/acs/mgm.rs | 7 +++++-- satrs-example/src/config.rs | 3 ++- satrs-example/src/eps/pcdu.rs | 12 +++++++++--- satrs-example/src/main.rs | 28 +++++++++++++++++++++++----- satrs-example/src/pus/hk.rs | 1 + satrs-minisim/src/controller.rs | 12 +++++++----- 6 files changed, 47 insertions(+), 16 deletions(-) diff --git a/satrs-example/src/acs/mgm.rs b/satrs-example/src/acs/mgm.rs index b102225..b75e126 100644 --- a/satrs-example/src/acs/mgm.rs +++ b/satrs-example/src/acs/mgm.rs @@ -19,7 +19,7 @@ use satrs::mode::{ }; use satrs::pus::{EcssTmSender, PusTmVariant}; use satrs::request::{GenericMessage, MessageMetadata, UniqueApidTargetId}; -use satrs_example::config::components::PUS_MODE_SERVICE; +use satrs_example::config::components::{NO_SENDER, PUS_MODE_SERVICE}; use crate::hk::PusHkHelper; use crate::pus::hk::{HkReply, HkReplyVariant}; @@ -421,9 +421,12 @@ impl< self.mode_helpers.target = None; self.announce_mode(requestor, false); if let Some(requestor) = requestor { + if requestor.sender_id() == NO_SENDER { + return Ok(()); + } if requestor.sender_id() != PUS_MODE_SERVICE.id() { log::warn!( - "can not send back mode reply to sender {}", + "can not send back mode reply to sender {:x}", requestor.sender_id() ); } else { diff --git a/satrs-example/src/config.rs b/satrs-example/src/config.rs index 63aee09..5608bf3 100644 --- a/satrs-example/src/config.rs +++ b/satrs-example/src/config.rs @@ -122,7 +122,7 @@ pub mod mode_err { } pub mod components { - use satrs::request::UniqueApidTargetId; + use satrs::{request::UniqueApidTargetId, ComponentId}; use strum::EnumIter; #[derive(Copy, Clone, PartialEq, Eq, EnumIter)] @@ -184,6 +184,7 @@ pub mod components { UniqueApidTargetId::new(Apid::Tmtc as u16, TmtcId::UdpServer as u32); pub const TCP_SERVER: UniqueApidTargetId = UniqueApidTargetId::new(Apid::Tmtc as u16, TmtcId::TcpServer as u32); + pub const NO_SENDER: ComponentId = ComponentId::MAX; } pub mod pool { diff --git a/satrs-example/src/eps/pcdu.rs b/satrs-example/src/eps/pcdu.rs index 0d30e3d..908bfb2 100644 --- a/satrs-example/src/eps/pcdu.rs +++ b/satrs-example/src/eps/pcdu.rs @@ -15,7 +15,10 @@ use satrs::{ request::{GenericMessage, MessageMetadata, UniqueApidTargetId}, spacepackets::ByteConversionError, }; -use satrs_example::{config::components::PUS_MODE_SERVICE, DeviceMode, TimestampHelper}; +use satrs_example::{ + config::components::{NO_SENDER, PUS_MODE_SERVICE}, + DeviceMode, TimestampHelper, +}; use satrs_minisim::{ eps::{ PcduReply, PcduRequest, PcduSwitch, SwitchMap, SwitchMapBinaryWrapper, SwitchMapWrapper, @@ -60,9 +63,9 @@ impl SerialInterface for SerialInterfaceToSim { type Error = (); fn send(&self, data: &[u8]) -> Result<(), Self::Error> { - let request: SimRequest = serde_json::from_slice(data).unwrap(); + let request: PcduRequest = serde_json::from_slice(data).expect("expected a PCDU request"); self.sim_request_tx - .send(request) + .send(SimRequest::new_with_epoch_time(request)) .expect("failed to send request to simulation"); Ok(()) } @@ -437,6 +440,9 @@ impl ModeRequestHandler ) -> Result<(), Self::Error> { self.announce_mode(requestor, false); if let Some(requestor) = requestor { + if requestor.sender_id() == NO_SENDER { + return Ok(()); + } if requestor.sender_id() != PUS_MODE_SERVICE.id() { log::warn!( "can not send back mode reply to sender {}", diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index 1782bb6..317e3f0 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -22,13 +22,14 @@ use pus::test::create_test_service_dynamic; use satrs::hal::std::tcp_server::ServerConfig; use satrs::hal::std::udp_server::UdpTcServer; use satrs::pus::HandlingStatus; -use satrs::request::GenericMessage; +use satrs::request::{GenericMessage, MessageMetadata}; use satrs::tmtc::{PacketSenderWithSharedPool, SharedPacketPool}; use satrs_example::config::pool::{create_sched_tc_pool, create_static_pools}; use satrs_example::config::tasks::{ FREQ_MS_AOCS, FREQ_MS_PUS_STACK, FREQ_MS_UDP_TMTC, SIM_CLIENT_IDLE_DELAY_MS, }; use satrs_example::config::{OBSW_SERVER_ADDR, PACKET_ID_VALIDATOR, SERVER_PORT}; +use satrs_example::DeviceMode; use crate::acs::mgm::{ MgmHandlerLis3Mdl, MpscModeLeafInterface, SpiDummyInterface, SpiSimInterface, @@ -46,10 +47,12 @@ use crate::pus::scheduler::{create_scheduler_service_dynamic, create_scheduler_s use crate::pus::test::create_test_service_static; use crate::pus::{PusTcDistributor, PusTcMpscRouter}; use crate::requests::{CompositeRequest, GenericRequestRouter}; -use satrs::mode::ModeRequest; +use satrs::mode::{Mode, ModeAndSubmode, ModeRequest}; use satrs::pus::event_man::EventRequestWithToken; use satrs::spacepackets::{time::cds::CdsTime, time::TimeWriter}; -use satrs_example::config::components::{MGM_HANDLER_0, PCDU_HANDLER, TCP_SERVER, UDP_SERVER}; +use satrs_example::config::components::{ + MGM_HANDLER_0, NO_SENDER, PCDU_HANDLER, TCP_SERVER, UDP_SERVER, +}; use std::net::{IpAddr, SocketAddr}; use std::sync::{mpsc, Mutex}; use std::sync::{Arc, RwLock}; @@ -98,7 +101,7 @@ fn static_tmtc_pool_main() { .insert(PCDU_HANDLER.id(), pcdu_handler_composite_tx); request_map .mode_router_map - .insert(PCDU_HANDLER.id(), pcdu_handler_mode_tx); + .insert(PCDU_HANDLER.id(), pcdu_handler_mode_tx.clone()); // This helper structure is used by all telecommand providers which need to send telecommands // to the TC source. @@ -272,6 +275,7 @@ fn static_tmtc_pool_main() { } else { SerialSimInterfaceWrapper::Dummy(SerialInterfaceDummy::default()) }; + let mut pcdu_handler = PcduHandler::new( PCDU_HANDLER, "PCDU", @@ -283,6 +287,13 @@ fn static_tmtc_pool_main() { pcdu_serial_interface, shared_switch_set, ); + // The PCDU is a critical component which should be in normal mode immediately. + pcdu_handler_mode_tx + .send(GenericMessage::new( + MessageMetadata::new(0, NO_SENDER), + ModeRequest::SetMode(ModeAndSubmode::new(DeviceMode::Normal as Mode, 0)), + )) + .expect("sending initial mode request failed"); info!("Starting TMTC and UDP task"); let jh_udp_tmtc = thread::Builder::new() @@ -420,7 +431,7 @@ fn dyn_tmtc_pool_main() { .insert(PCDU_HANDLER.id(), pcdu_handler_composite_tx); request_map .mode_router_map - .insert(PCDU_HANDLER.id(), pcdu_handler_mode_tx); + .insert(PCDU_HANDLER.id(), pcdu_handler_mode_tx.clone()); // Create event handling components // These sender handles are used to send event requests, for example to enable or disable @@ -583,6 +594,13 @@ fn dyn_tmtc_pool_main() { pcdu_serial_interface, shared_switch_set, ); + // The PCDU is a critical component which should be in normal mode immediately. + pcdu_handler_mode_tx + .send(GenericMessage::new( + MessageMetadata::new(0, NO_SENDER), + ModeRequest::SetMode(ModeAndSubmode::new(DeviceMode::Normal as Mode, 0)), + )) + .expect("sending initial mode request failed"); info!("Starting TMTC and UDP task"); let jh_udp_tmtc = thread::Builder::new() diff --git a/satrs-example/src/pus/hk.rs b/satrs-example/src/pus/hk.rs index 2796151..c0d21bf 100644 --- a/satrs-example/src/pus/hk.rs +++ b/satrs-example/src/pus/hk.rs @@ -33,6 +33,7 @@ pub struct HkReply { } #[derive(Clone, PartialEq, Debug)] +#[allow(dead_code)] pub enum HkReplyVariant { Ack, Failed(ResultU16), diff --git a/satrs-minisim/src/controller.rs b/satrs-minisim/src/controller.rs index b5404d8..4fe1495 100644 --- a/satrs-minisim/src/controller.rs +++ b/satrs-minisim/src/controller.rs @@ -16,10 +16,12 @@ use crate::{ eps::PcduModel, }; -const SIM_CTRL_REQ_WIRETAPPING: bool = true; -const MGM_REQ_WIRETAPPING: bool = true; -const PCDU_REQ_WIRETAPPING: bool = true; -const MGT_REQ_WIRETAPPING: bool = true; +const WARNING_FOR_STALE_DATA: bool = false; + +const SIM_CTRL_REQ_WIRETAPPING: bool = false; +const MGM_REQ_WIRETAPPING: bool = false; +const PCDU_REQ_WIRETAPPING: bool = false; +const MGT_REQ_WIRETAPPING: bool = false; // The simulation controller processes requests and drives the simulation. pub struct SimController { @@ -72,7 +74,7 @@ impl SimController { loop { match self.request_receiver.try_recv() { Ok(request) => { - if request.timestamp < old_timestamp { + if request.timestamp < old_timestamp && WARNING_FOR_STALE_DATA { log::warn!("stale data with timestamp {:?} received", request.timestamp); } if let Err(e) = match request.component() {