From f639eb9b9a20c62ab0670979f682230418004961 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 27 Feb 2023 11:51:48 +0100 Subject: [PATCH 1/2] refactor messages --- satrs-core/src/hk.rs | 15 +++++++++++---- satrs-core/src/mode.rs | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/satrs-core/src/hk.rs b/satrs-core/src/hk.rs index 727e887..1124afb 100644 --- a/satrs-core/src/hk.rs +++ b/satrs-core/src/hk.rs @@ -1,11 +1,18 @@ use crate::tmtc::AddressableId; pub type CollectionIntervalFactor = u32; +pub type UniqueId = u32; #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum HkRequest { - OneShot(AddressableId), - Enable(AddressableId), - Disable(AddressableId), - ModifyCollectionInterval(AddressableId, CollectionIntervalFactor), + OneShot(UniqueId), + Enable(UniqueId), + Disable(UniqueId), + ModifyCollectionInterval(UniqueId, CollectionIntervalFactor), +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub struct TargetedHkRequest { + target: u32, + hk_request: HkRequest } diff --git a/satrs-core/src/mode.rs b/satrs-core/src/mode.rs index 1ebd854..49008d2 100644 --- a/satrs-core/src/mode.rs +++ b/satrs-core/src/mode.rs @@ -71,8 +71,15 @@ impl ModeCommand { #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum ModeRequest { - SetMode(ModeCommand), - ReadMode(TargetId), - AnnounceMode(TargetId), - AnnounceModeRecursive(TargetId), + SetMode(ModeAndSubmode), + ReadMode(ModeRequest), + AnnounceMode(ModeRequest), + AnnounceModeRecursive(ModeRequest), +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct TargetedModeRequest { + target_id: TargetId, + mode_request: ModeRequest } -- 2.43.0 From 1d19f0951916aa2c92543847062bc121bd7a61b5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 27 Feb 2023 13:44:24 +0100 Subject: [PATCH 2/2] reduced features --- satrs-core/src/hk.rs | 4 +-- satrs-core/src/mode.rs | 8 +++--- satrs-example/src/main.rs | 28 +++++++++++------- satrs-example/src/pus.rs | 53 +++++++++++++++++++++++------------ satrs-example/src/requests.rs | 31 +++++++++++++++++++- 5 files changed, 88 insertions(+), 36 deletions(-) diff --git a/satrs-core/src/hk.rs b/satrs-core/src/hk.rs index 1124afb..dc6c72e 100644 --- a/satrs-core/src/hk.rs +++ b/satrs-core/src/hk.rs @@ -1,5 +1,3 @@ -use crate::tmtc::AddressableId; - pub type CollectionIntervalFactor = u32; pub type UniqueId = u32; @@ -14,5 +12,5 @@ pub enum HkRequest { #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct TargetedHkRequest { target: u32, - hk_request: HkRequest + hk_request: HkRequest, } diff --git a/satrs-core/src/mode.rs b/satrs-core/src/mode.rs index 49008d2..cdc23a4 100644 --- a/satrs-core/src/mode.rs +++ b/satrs-core/src/mode.rs @@ -72,14 +72,14 @@ impl ModeCommand { #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum ModeRequest { SetMode(ModeAndSubmode), - ReadMode(ModeRequest), - AnnounceMode(ModeRequest), - AnnounceModeRecursive(ModeRequest), + ReadMode, + AnnounceMode, + AnnounceModeRecursive, } #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct TargetedModeRequest { target_id: TargetId, - mode_request: ModeRequest + mode_request: ModeRequest, } diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index bcb08f8..d575e56 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -35,6 +35,7 @@ use satrs_core::spacepackets::{ tm::{PusTm, PusTmSecondaryHeader}, SequenceFlags, SpHeader, }; +use satrs_core::tmtc::AddressableId; use satrs_example::{RequestTargetId, OBSW_SERVER_ADDR, SERVER_PORT}; use std::collections::HashMap; use std::net::{IpAddr, SocketAddr}; @@ -253,16 +254,19 @@ fn main() { loop { match acs_thread_rx.try_recv() { Ok(request) => { - info!("ACS thread: Received HK request {:?}", request.0); + info!( + "ACS thread: Received HK request {:?}", + request.targeted_request + ); update_time(&mut time_provider, &mut timestamp); - match request.0 { + match request.targeted_request.request { Request::HkRequest(hk_req) => match hk_req { - HkRequest::OneShot(address) => { - assert_eq!( - address.target_id, - RequestTargetId::AcsSubsystem as u32 - ); - if address.unique_id == AcsHkIds::TestMgmSet as u32 { + HkRequest::OneShot(unique_id) => { + let target = request.targeted_request.target_id; + assert_eq!(target, RequestTargetId::AcsSubsystem as u32); + if request.targeted_request.target_id + == AcsHkIds::TestMgmSet as u32 + { let mut sp_header = SpHeader::tm( PUS_APID, SequenceFlags::Unsegmented, @@ -276,7 +280,11 @@ fn main() { ×tamp, ); let mut buf: [u8; 8] = [0; 8]; - address.write_to_be_bytes(&mut buf).unwrap(); + let addressable_id = AddressableId { + target_id: target, + unique_id, + }; + addressable_id.write_to_be_bytes(&mut buf).unwrap(); let pus_tm = PusTm::new( &mut sp_header, sec_header, @@ -296,7 +304,7 @@ fn main() { } } let started_token = reporter_aocs - .start_success(request.1, Some(×tamp)) + .start_success(request.token, Some(×tamp)) .expect("Sending start success failed"); reporter_aocs .completion_success(started_token, Some(×tamp)) diff --git a/satrs-example/src/pus.rs b/satrs-example/src/pus.rs index f36675a..06d98eb 100644 --- a/satrs-example/src/pus.rs +++ b/satrs-example/src/pus.rs @@ -3,7 +3,7 @@ use crate::tmtc::{PusTcSource, TmStore}; use log::{info, warn}; use satrs_core::events::EventU32; use satrs_core::hk::{CollectionIntervalFactor, HkRequest}; -use satrs_core::mode::{ModeAndSubmode, ModeCommand, ModeRequest}; +use satrs_core::mode::{ModeAndSubmode, ModeRequest}; use satrs_core::params::Params; use satrs_core::pool::StoreAddr; use satrs_core::pus::event_man::{EventRequest, EventRequestWithToken}; @@ -268,22 +268,35 @@ impl PusReceiver { .expect("Sending start failure TM failed"); return; } - let send_request = |request: HkRequest| { + let send_request = |target: TargetId, request: HkRequest| { let sender = self .tc_args .request_map .get(&addressable_id.target_id) .unwrap(); sender - .send(RequestWithToken(Request::HkRequest(request), token)) + .send(RequestWithToken::new( + target, + Request::HkRequest(request), + token, + )) .unwrap_or_else(|_| panic!("Sending HK request {request:?} failed")); }; if PusPacket::subservice(pus_tc) == hk::Subservice::TcEnableHkGeneration as u8 { - send_request(HkRequest::Enable(addressable_id)); + send_request( + addressable_id.target_id, + HkRequest::Enable(addressable_id.unique_id), + ); } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcDisableHkGeneration as u8 { - send_request(HkRequest::Disable(addressable_id)); + send_request( + addressable_id.target_id, + HkRequest::Disable(addressable_id.unique_id), + ); } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcGenerateOneShotHk as u8 { - send_request(HkRequest::OneShot(addressable_id)); + send_request( + addressable_id.target_id, + HkRequest::OneShot(addressable_id.unique_id), + ); } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcModifyHkCollectionInterval as u8 { @@ -301,10 +314,13 @@ impl PusReceiver { .expect("Sending start failure TM failed"); return; } - send_request(HkRequest::ModifyCollectionInterval( - addressable_id, - CollectionIntervalFactor::from_be_bytes(user_data[8..12].try_into().unwrap()), - )); + send_request( + addressable_id.target_id, + HkRequest::ModifyCollectionInterval( + addressable_id.unique_id, + CollectionIntervalFactor::from_be_bytes(user_data[8..12].try_into().unwrap()), + ), + ); } } @@ -550,7 +566,11 @@ impl PusReceiver { None => warn!("not mode request recipient for target ID {target_id} found"), Some(sender_to_recipient) => { sender_to_recipient - .send(RequestWithToken(Request::ModeRequest(mode_request), token)) + .send(RequestWithToken::new( + target_id, + Request::ModeRequest(mode_request), + token, + )) .expect("sending mode request failed"); } }; @@ -582,22 +602,19 @@ impl PusReceiver { .unwrap(), ) .unwrap(); - forward_mode_request( - target_id, - ModeRequest::SetMode(ModeCommand::new(target_id, mode_submode)), - ); + forward_mode_request(target_id, ModeRequest::SetMode(mode_submode)); } Subservice::TcReadMode => { let target_id = u32::from_be_bytes(app_data[0..4].try_into().unwrap()); - forward_mode_request(target_id, ModeRequest::ReadMode(target_id)); + forward_mode_request(target_id, ModeRequest::ReadMode); } Subservice::TcAnnounceMode => { let target_id = u32::from_be_bytes(app_data[0..4].try_into().unwrap()); - forward_mode_request(target_id, ModeRequest::AnnounceMode(target_id)); + forward_mode_request(target_id, ModeRequest::AnnounceMode); } Subservice::TcAnnounceModeRecursive => { let target_id = u32::from_be_bytes(app_data[0..4].try_into().unwrap()); - forward_mode_request(target_id, ModeRequest::AnnounceModeRecursive(target_id)); + forward_mode_request(target_id, ModeRequest::AnnounceModeRecursive); } _ => { warn!("Can not process mode request with subservice {subservice:?}"); diff --git a/satrs-example/src/requests.rs b/satrs-example/src/requests.rs index 68f59a4..6f11eef 100644 --- a/satrs-example/src/requests.rs +++ b/satrs-example/src/requests.rs @@ -1,6 +1,7 @@ use satrs_core::hk::HkRequest; use satrs_core::mode::ModeRequest; use satrs_core::pus::verification::{TcStateAccepted, VerificationToken}; +use satrs_core::tmtc::TargetId; #[derive(Copy, Clone, Eq, PartialEq, Debug)] #[non_exhaustive] @@ -10,4 +11,32 @@ pub enum Request { } #[derive(Copy, Clone, Eq, PartialEq, Debug)] -pub struct RequestWithToken(pub Request, pub VerificationToken); +pub struct TargetedRequest { + pub(crate) target_id: TargetId, + pub(crate) request: Request, +} + +impl TargetedRequest { + pub fn new(target_id: TargetId, request: Request) -> Self { + Self { target_id, request } + } +} + +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub struct RequestWithToken { + pub(crate) targeted_request: TargetedRequest, + pub(crate) token: VerificationToken, +} + +impl RequestWithToken { + pub fn new( + target_id: u32, + request: Request, + token: VerificationToken, + ) -> Self { + Self { + targeted_request: TargetedRequest::new(target_id, request), + token, + } + } +} -- 2.43.0