Compare commits

..

1 Commits

Author SHA1 Message Date
6a4417c954 added and scheduled MGM assembly 2025-05-19 16:18:31 +02:00
21 changed files with 242 additions and 57 deletions

View File

@@ -61,8 +61,6 @@ Each project has its own `CHANGELOG.md`.
packet protocol implementations. This repository is re-exported in the
[`satrs`](https://egit.irs.uni-stuttgart.de/rust/satrs/src/branch/main/satrs)
crate.
* [`cfdp`](https://egit.irs.uni-stuttgart.de/rust/cfdp): CCSDS File Delivery Protocol
(CFDP) high-level library components.
# Flight Heritage

View File

@@ -18,7 +18,7 @@ csv = "1"
num_enum = "0.7"
thiserror = "2"
lazy_static = "1"
strum = { version = "0.27", features = ["derive"] }
strum = { version = "0.26", features = ["derive"] }
derive-new = "0.7"
cfg-if = "1"
serde = { version = "1", features = ["derive"] }

View File

@@ -1 +1,175 @@
// TODO: Write the assembly
//
use std::sync::mpsc;
use satrs::{
dev_mgmt::{DevManagerCommandingHelper, DevManagerHelperResult, TransparentDevManagerHook},
mode::{
ModeAndSubmode, ModeError, ModeProvider, ModeReply, ModeReplyReceiver as _,
ModeReplySender as _, ModeRequest, ModeRequestHandler, ModeRequestReceiver as _,
ModeRequestorAndHandlerMpscBounded, UNKNOWN_MODE,
},
mode_tree::{ModeChild, ModeNode, ModeParent},
queue::GenericTargetedMessagingError,
request::{GenericMessage, MessageMetadata},
ComponentId,
};
use satrs_example::{ids, DeviceMode};
pub type RequestSenderType = mpsc::SyncSender<GenericMessage<ModeRequest>>;
pub type ReplySenderType = mpsc::SyncSender<GenericMessage<ModeReply>>;
// TODO: Needs to perform same functions as the integration test assembly, but also needs
// to track mode changes and health changes of children.
pub struct MgmAssembly {
pub mode_node: ModeRequestorAndHandlerMpscBounded,
pub mode_requestor_info: Option<MessageMetadata>,
pub mode_and_submode: ModeAndSubmode,
pub commanding_helper: DevManagerCommandingHelper<TransparentDevManagerHook>,
}
impl MgmAssembly {
pub fn new(mode_node: ModeRequestorAndHandlerMpscBounded) -> Self {
Self {
mode_node,
mode_requestor_info: None,
mode_and_submode: UNKNOWN_MODE,
commanding_helper: DevManagerCommandingHelper::new(TransparentDevManagerHook::default()),
}
}
pub const fn id() -> ComponentId {
ids::acs::MGM_ASSEMBLY.raw()
}
pub fn periodic_operation(&mut self) {
self.check_mode_requests().expect("mode messaging error");
self.check_mode_replies().expect("mode messaging error");
// TODO: perform target keeping, check whether children are in correct mode.
}
pub fn check_mode_requests(&mut self) -> Result<(), GenericTargetedMessagingError> {
while let Some(request) = self.mode_node.try_recv_mode_request()? {
self.handle_mode_request(request).unwrap();
}
Ok(())
}
pub fn check_mode_replies(&mut self) -> Result<(), ModeError> {
while let Some(reply_and_id) = self.mode_node.try_recv_mode_reply()? {
match self.commanding_helper.handle_mode_reply(&reply_and_id) {
Ok(result) => {
if let DevManagerHelperResult::ModeCommandingDone(context) = result {
// Complete the mode command.
self.mode_and_submode = context.target_mode;
self.handle_mode_reached(self.mode_requestor_info)?;
}
}
Err(err) => match err {
satrs::dev_mgmt::DevManagerHelperError::ChildNotInStore => todo!(),
},
}
}
Ok(())
}
}
impl ModeNode for MgmAssembly {
fn id(&self) -> ComponentId {
Self::id()
}
}
impl ModeParent for MgmAssembly {
type Sender = RequestSenderType;
fn add_mode_child(&mut self, id: ComponentId, request_sender: RequestSenderType) {
self.mode_node.add_request_target(id, request_sender);
self.commanding_helper.add_mode_child(id, UNKNOWN_MODE);
}
}
impl ModeChild for MgmAssembly {
type Sender = ReplySenderType;
fn add_mode_parent(&mut self, id: ComponentId, reply_sender: ReplySenderType) {
self.mode_node.add_reply_target(id, reply_sender);
}
}
impl ModeProvider for MgmAssembly {
fn mode_and_submode(&self) -> ModeAndSubmode {
self.mode_and_submode
}
}
impl ModeRequestHandler for MgmAssembly {
type Error = ModeError;
fn start_transition(
&mut self,
requestor: MessageMetadata,
mode_and_submode: ModeAndSubmode,
forced: bool,
) -> Result<(), Self::Error> {
// Always accept forced commands and commands to mode OFF.
if self.commanding_helper.target_mode().is_some()
&& !forced
&& mode_and_submode.mode() != DeviceMode::Off as u32
{
return Err(ModeError::Busy);
}
self.mode_requestor_info = Some(requestor);
self.commanding_helper.send_mode_cmd_to_all_children(
requestor.request_id(),
mode_and_submode,
forced,
&self.mode_node,
)?;
Ok(())
}
fn announce_mode(&self, requestor_info: Option<MessageMetadata>, recursive: bool) {
println!(
"TestAssembly: Announcing mode (recursively: {}): {:?}",
recursive, self.mode_and_submode
);
let request_id = requestor_info.map_or(0, |info| info.request_id());
self.commanding_helper
.send_announce_mode_cmd_to_children(request_id, &self.mode_node, recursive)
.expect("sending mode request failed");
// TODO: Send announce event.
log::info!(
"MGM assembly announcing mode: {:?}",
self.mode_and_submode()
);
}
fn handle_mode_reached(
&mut self,
mode_requestor: Option<MessageMetadata>,
) -> Result<(), Self::Error> {
if let Some(requestor) = mode_requestor {
self.send_mode_reply(requestor, ModeReply::ModeReply(self.mode_and_submode))?;
}
self.announce_mode(mode_requestor, false);
Ok(())
}
fn handle_mode_info(
&mut self,
requestor_info: MessageMetadata,
info: ModeAndSubmode,
) -> Result<(), Self::Error> {
// TODO: Perform mode keeping.
Ok(())
}
fn send_mode_reply(
&self,
requestor: MessageMetadata,
reply: ModeReply,
) -> Result<(), Self::Error> {
self.mode_node.send_mode_reply(requestor, reply)?;
Ok(())
}
}

View File

@@ -83,7 +83,7 @@ impl SpiInterface for SpiSimInterface {
.sim_request_tx
.send(SimRequest::new_with_epoch_time(mgm_sensor_request))
{
log::error!("failed to send MGM LIS3 request: {e}");
log::error!("failed to send MGM LIS3 request: {}", e);
}
match self.sim_reply_rx.recv_timeout(Duration::from_millis(50)) {
Ok(sim_reply) => {
@@ -97,7 +97,7 @@ impl SpiInterface for SpiSimInterface {
.copy_from_slice(&sim_reply_lis3.raw.z.to_le_bytes());
}
Err(e) => {
log::warn!("MGM LIS3 SIM reply timeout: {e}");
log::warn!("MGM LIS3 SIM reply timeout: {}", e);
}
}
Ok(())
@@ -400,6 +400,7 @@ impl<
}
fn announce_mode(&self, _requestor_info: Option<MessageMetadata>, _recursive: bool) {
// TODO: Event
log::info!(
"{} announcing mode: {:?}",
self.dev_str,
@@ -492,7 +493,7 @@ mod tests {
tmtc::PacketAsVec,
ComponentId,
};
use satrs_example::ids::{acs::ASSEMBLY, Apid};
use satrs_example::ids::{acs::MGM_ASSEMBLY, Apid};
use satrs_minisim::acs::lis3mdl::MgmLis3RawValues;
use crate::{eps::TestSwitchHelper, pus::hk::HkReply, requests::CompositeRequest};
@@ -593,7 +594,7 @@ mod tests {
shared_mgm_set,
);
handler.add_mode_parent(PUS_MODE.into(), reply_tx_to_pus);
handler.add_mode_parent(ASSEMBLY.into(), reply_tx_to_parent);
handler.add_mode_parent(MGM_ASSEMBLY.into(), reply_tx_to_parent);
Self {
mode_request_tx: request_tx,
mode_reply_rx_to_pus: reply_rx_to_pus,

View File

@@ -401,7 +401,7 @@ impl<ComInterface: SerialInterface> PcduHandler<ComInterface> {
}
}
}) {
log::warn!("receiving PCDU replies failed: {e:?}");
log::warn!("receiving PCDU replies failed: {:?}", e);
}
}
}

View File

@@ -15,15 +15,15 @@ pub mod acs {
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Id {
Subsystem = 1,
Assembly = 2,
MgmAssembly = 2,
Mgm0 = 3,
Mgm1 = 4,
}
pub const SUBSYSTEM: super::UniqueApidTargetId =
super::UniqueApidTargetId::new(super::Apid::Acs as u16, Id::Subsystem as u32);
pub const ASSEMBLY: super::UniqueApidTargetId =
super::UniqueApidTargetId::new(super::Apid::Acs as u16, Id::Assembly as u32);
pub const MGM_ASSEMBLY: super::UniqueApidTargetId =
super::UniqueApidTargetId::new(super::Apid::Acs as u16, Id::MgmAssembly as u32);
pub const MGM0: super::UniqueApidTargetId =
super::UniqueApidTargetId::new(super::Apid::Acs as u16, Id::Mgm0 as u32);
pub const MGM1: super::UniqueApidTargetId =

View File

@@ -24,7 +24,7 @@ pub fn create_sim_client(sim_request_rx: mpsc::Receiver<SimRequest>) -> Option<S
return Some(sim_client);
}
Err(e) => {
log::warn!("sim client creation error: {e}");
log::warn!("sim client creation error: {}", e);
}
}
None
@@ -116,7 +116,7 @@ impl SimClientUdp {
.udp_client
.send_to(request_json.as_bytes(), self.simulator_addr)
{
log::error!("error sending data to UDP SIM server: {e}");
log::error!("error sending data to UDP SIM server: {}", e);
break;
} else {
no_sim_requests_handled = false;
@@ -151,7 +151,7 @@ impl SimClientUdp {
}
}
Err(e) => {
log::warn!("failed to deserialize SIM reply: {e}");
log::warn!("failed to deserialize SIM reply: {}", e);
}
}
}
@@ -161,7 +161,7 @@ impl SimClientUdp {
{
break;
}
log::error!("error receiving data from UDP SIM server: {e}");
log::error!("error receiving data from UDP SIM server: {}", e);
break;
}
}

View File

@@ -31,7 +31,7 @@ impl SpacePacketValidator for SimplePacketValidator {
if self.valid_ids.contains(&sp_header.packet_id()) {
return SpValidity::Valid;
}
log::warn!("ignoring space packet with header {sp_header:?}");
log::warn!("ignoring space packet with header {:?}", sp_header);
// We could perform a CRC check.. but lets keep this simple and assume that TCP ensures
// data integrity.
SpValidity::Skip

View File

@@ -5,7 +5,10 @@ use std::{
time::Duration,
};
use acs::mgm::{MgmHandlerLis3Mdl, SpiDummyInterface, SpiSimInterface, SpiSimInterfaceWrapper};
use acs::{
assembly::MgmAssembly,
mgm::{MgmHandlerLis3Mdl, SpiDummyInterface, SpiSimInterface, SpiSimInterfaceWrapper},
};
use eps::{
pcdu::{PcduHandler, SerialInterfaceDummy, SerialInterfaceToSim, SerialSimInterfaceWrapper},
PowerSwitchHelper,
@@ -31,7 +34,10 @@ use pus::{
use requests::GenericRequestRouter;
use satrs::{
hal::std::{tcp_server::ServerConfig, udp_server::UdpTcServer},
mode::{Mode, ModeAndSubmode, ModeRequest, ModeRequestHandlerMpscBounded},
mode::{
Mode, ModeAndSubmode, ModeRequest, ModeRequestHandlerMpscBounded,
ModeRequestorAndHandlerMpscBounded,
},
mode_tree::connect_mode_nodes,
pus::{event_man::EventRequestWithToken, EcssTcInMemConverter, HandlingStatus},
request::{GenericMessage, MessageMetadata},
@@ -303,6 +309,15 @@ fn main() {
let (switch_request_tx, switch_request_rx) = mpsc::sync_channel(20);
let switch_helper = PowerSwitchHelper::new(switch_request_tx, shared_switch_set.clone());
let (mgm_assy_mode_req_tx, mgm_assy_mode_req_rx) = mpsc::sync_channel(20);
let (mgm_assy_mode_reply_tx, mgm_assy_mode_reply_rx) = mpsc::sync_channel(20);
let mgm_assembly_mode_node = ModeRequestorAndHandlerMpscBounded::new(
MgmAssembly::id(),
mgm_assy_mode_req_rx,
mgm_assy_mode_reply_rx,
);
let mut mgm_assembly = MgmAssembly::new(mgm_assembly_mode_node);
let shared_mgm_0_set = Arc::default();
let shared_mgm_1_set = Arc::default();
let mgm_0_mode_node = ModeRequestHandlerMpscBounded::new(MGM0.into(), mgm_0_handler_mode_rx);
@@ -364,6 +379,19 @@ fn main() {
&mut mgm_1_handler,
pus_mode_reply_tx.clone(),
);
// Connect assembly to device handlers.
connect_mode_nodes(
&mut mgm_assembly,
mgm_assy_mode_req_tx.clone(),
&mut mgm_1_handler,
mgm_assy_mode_reply_tx.clone(),
);
connect_mode_nodes(
&mut mgm_assembly,
mgm_assy_mode_req_tx,
&mut mgm_1_handler,
mgm_assy_mode_reply_tx,
);
let pcdu_serial_interface = if let Some(sim_client) = opt_sim_client.as_mut() {
sim_client.add_reply_recipient(satrs_minisim::SimComponent::Pcdu, pcdu_sim_reply_tx);
@@ -455,6 +483,7 @@ fn main() {
let jh_aocs = thread::Builder::new()
.name("sat-rs aocs".to_string())
.spawn(move || loop {
mgm_assembly.periodic_operation();
mgm_0_handler.periodic_operation();
mgm_1_handler.periodic_operation();
thread::sleep(Duration::from_millis(FREQ_MS_AOCS));

View File

@@ -102,7 +102,7 @@ impl PusTcDistributor {
sender_id,
pus_tc_result.unwrap_err()
);
log::warn!("raw data: {raw_tc:x?}");
log::warn!("raw data: {:x?}", raw_tc);
// TODO: Shouldn't this be an error?
return Ok(HandlingStatus::HandledOne);
}

View File

@@ -11,7 +11,7 @@ serde_json = "1"
log = "0.4"
thiserror = "2"
fern = "0.7"
strum = { version = "0.27", features = ["derive"] }
strum = { version = "0.26", features = ["derive"] }
num_enum = "0.7"
humantime = "2"
tai-time = { version = "0.3", features = ["serde"] }

View File

@@ -120,7 +120,7 @@ impl SimController {
fn handle_ctrl_request(&mut self, request: &SimRequest) -> Result<(), SimRequestError> {
let sim_ctrl_request = SimCtrlRequest::from_sim_message(request)?;
if SIM_CTRL_REQ_WIRETAPPING {
log::info!("received sim ctrl request: {sim_ctrl_request:?}");
log::info!("received sim ctrl request: {:?}", sim_ctrl_request);
}
match sim_ctrl_request {
SimCtrlRequest::Ping => {
@@ -139,7 +139,7 @@ impl SimController {
) -> Result<(), SimRequestError> {
let mgm_request = MgmRequestLis3Mdl::from_sim_message(request)?;
if MGM_REQ_WIRETAPPING {
log::info!("received MGM request: {mgm_request:?}");
log::info!("received MGM request: {:?}", mgm_request);
}
match mgm_request {
MgmRequestLis3Mdl::RequestSensorData => {
@@ -160,7 +160,7 @@ impl SimController {
fn handle_pcdu_request(&mut self, request: &SimRequest) -> Result<(), SimRequestError> {
let pcdu_request = PcduRequest::from_sim_message(request)?;
if PCDU_REQ_WIRETAPPING {
log::info!("received PCDU request: {pcdu_request:?}");
log::info!("received PCDU request: {:?}", pcdu_request);
}
match pcdu_request {
PcduRequest::RequestSwitchInfo => {
@@ -188,7 +188,7 @@ impl SimController {
fn handle_mgt_request(&mut self, request: &SimRequest) -> Result<(), SimRequestError> {
let mgt_request = MgtRequest::from_sim_message(request)?;
if MGT_REQ_WIRETAPPING {
log::info!("received MGT request: {mgt_request:?}");
log::info!("received MGT request: {:?}", mgt_request);
}
match mgt_request {
MgtRequest::ApplyTorque { duration, dipole } => self

View File

@@ -130,7 +130,7 @@ fn main() {
let mut udp_server =
SimUdpServer::new(SIM_CTRL_PORT, request_sender, reply_receiver, 200, None)
.expect("could not create UDP request server");
log::info!("starting UDP server on port {SIM_CTRL_PORT}");
log::info!("starting UDP server on port {}", SIM_CTRL_PORT);
// This thread manages the simulator UDP server.
let udp_tc_thread = thread::spawn(move || {
udp_server.run();

View File

@@ -8,10 +8,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased]
# [v0.2.3] 2025-07-22
`spacepackets` range v0.14 to v0.15
# [v0.2.2] 2025-05-10
- Bump to `spacepackests` v0.14
@@ -50,6 +46,5 @@ Allow `spacepackets` range starting with v0.10 and v0.11.
Initial release.
[unreleased]: https://egit.irs.uni-stuttgart.de/rust/sat-rs/compare/satrs-shared-v0.2.3...HEAD
[v0.2.3]: https://egit.irs.uni-stuttgart.de/rust/sat-rs/compare/satrs-shared-v0.2.1...satrs-shared-v0.2.3
[unreleased]: https://egit.irs.uni-stuttgart.de/rust/sat-rs/compare/satrs-shared-v0.2.2...HEAD
[v0.2.2]: https://egit.irs.uni-stuttgart.de/rust/sat-rs/compare/satrs-shared-v0.2.1...satrs-shared-v0.2.2

View File

@@ -1,7 +1,7 @@
[package]
name = "satrs-shared"
description = "Components shared by multiple sat-rs crates"
version = "0.2.3"
version = "0.2.2"
edition = "2021"
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
homepage = "https://absatsw.irs.uni-stuttgart.de/projects/sat-rs/"
@@ -11,7 +11,7 @@ license = "Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
spacepackets = { version = ">=0.14, <=0.15", default-features = false }
spacepackets = { version = ">=0.14, <=0.15", git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git", default-features = false }
[dependencies.serde]
version = "1"

View File

@@ -8,14 +8,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased]
# [v0.3.0-alpha.2] 2025-07-22
`satrs-shared` update
# [v0.3.0-alpha.1] 2025-07-22
`spacepackets` range v0.14 to v0.15
# [v0.3.0-alpha.0] 2025-02-18
`spacepackets` v0.13
@@ -206,8 +198,3 @@ docs-rs hotfix
# [v0.1.0] 2024-02-12
Initial release.
[unreleased]: https://egit.irs.uni-stuttgart.de/rust/sat-rs/compare/satrs-v0.3.0-alpha.2...HEAD
[v0.3.0-alpha.2]: https://egit.irs.uni-stuttgart.de/rust/sat-rs/compare/satrs-v0.3.0-alpha.1...satrs-v0.3.0-alpha.2
[v0.3.0-alpha.1]: https://egit.irs.uni-stuttgart.de/rust/sat-rs/compare/satrs-v0.3.0-alpha.0...satrs-v0.3.0-alpha.1
[v0.3.0-alpha.0]: https://egit.irs.uni-stuttgart.de/rust/sat-rs/compare/satrs-v0.2.1...satrs-v0.3.0-alpha.0

View File

@@ -1,6 +1,6 @@
[package]
name = "satrs"
version = "0.3.0-alpha.2"
version = "0.3.0-alpha.0"
edition = "2021"
rust-version = "1.82.0"
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
@@ -13,14 +13,14 @@ keywords = ["no-std", "space", "aerospace"]
categories = ["aerospace", "aerospace::space-protocols", "no-std", "hardware-support", "embedded"]
[dependencies]
satrs-shared = { version = "0.2", path = "../satrs-shared" }
spacepackets = { version = ">=0.14, <=0.15", default-features = false }
satrs-shared = { version = "0.2.2", path = "../satrs-shared" }
spacepackets = { version = ">=0.14, <=0.15", git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git", default-features = false }
delegate = ">0.7, <=0.13"
paste = "1"
derive-new = ">=0.6, <=0.7"
num_enum = { version = ">0.5, <=0.7", default-features = false }
cobs = { version = "0.4", default-features = false }
cobs = { version = "0.4", default-features = false, git = "https://github.com/jamesmunns/cobs.rs.git", branch = "main" }
thiserror = { version = "2", default-features = false }
hashbrown = { version = ">=0.14, <=0.15", optional = true }
@@ -31,9 +31,9 @@ downcast-rs = { version = "2", default-features = false, optional = true }
bus = { version = "2.2", optional = true }
crossbeam-channel = { version = "0.5", default-features = false, optional = true }
serde = { version = "1", default-features = false, optional = true }
socket2 = { version = "0.6", features = ["all"], optional = true }
socket2 = { version = "0.5", features = ["all"], optional = true }
mio = { version = "1", features = ["os-poll", "net"], optional = true }
defmt = { version = "1", optional = true }
defmt = { version = "0.3", optional = true }
[dev-dependencies]
serde = "1"

View File

@@ -90,8 +90,8 @@ pub fn parse_buffer_for_ccsds_space_packets<SendError>(
#[cfg(test)]
mod tests {
use spacepackets::{
ecss::tc::PusTcCreator, CcsdsPacket, PacketId, PacketSequenceCtrl, PacketType,
SequenceFlags, SpHeader,
ecss::{tc::PusTcCreator, WritablePusPacket},
CcsdsPacket, PacketId, PacketSequenceCtrl, PacketType, SequenceFlags, SpHeader,
};
use crate::{encoding::tests::TcCacher, ComponentId};

View File

@@ -129,6 +129,7 @@ mod tests {
use crate::ComponentId;
use core::cell::RefCell;
use spacepackets::ecss::tc::PusTcCreator;
use spacepackets::ecss::WritablePusPacket;
use spacepackets::SpHeader;
use std::collections::VecDeque;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};

View File

@@ -39,7 +39,7 @@ impl UniqueApidTargetId {
}
}
pub fn raw(&self) -> ComponentId {
pub const fn raw(&self) -> ComponentId {
((self.apid as u64) << 32) | (self.unique_id as u64)
}

View File

@@ -46,8 +46,8 @@ pub mod crossbeam_test {
let sender =
PacketSenderWithSharedPool::new_with_shared_packet_pool(tx.clone(), &shared_tm_pool);
let sender_1 = sender.clone();
let reporter_with_sender_0 = VerificationReporter::new(TEST_COMPONENT_ID_0.id(), &cfg);
let reporter_with_sender_1 = reporter_with_sender_0.clone();
let mut reporter_with_sender_0 = VerificationReporter::new(TEST_COMPONENT_ID_0.id(), &cfg);
let mut reporter_with_sender_1 = reporter_with_sender_0.clone();
// For test purposes, we retrieve the request ID from the TCs and pass them to the receiver
// tread.
let req_id_0;