From 4e450808b747e8a54a3da950b1ddfb05b5d2da3b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 22 Dec 2022 09:26:00 +0100 Subject: [PATCH] always supply addressable ID --- satrs-core/src/tmtc/mod.rs | 12 ++++++++++++ satrs-example/src/hk.rs | 11 ++++++----- satrs-example/src/main.rs | 39 +++++++++++++++++++++++++++----------- satrs-example/src/pus.rs | 7 ++++--- 4 files changed, 50 insertions(+), 19 deletions(-) diff --git a/satrs-core/src/tmtc/mod.rs b/satrs-core/src/tmtc/mod.rs index 6d67887..511099c 100644 --- a/satrs-core/src/tmtc/mod.rs +++ b/satrs-core/src/tmtc/mod.rs @@ -40,6 +40,18 @@ impl AddressableId { unique_id: u32::from_be_bytes(buf[4..8].try_into().unwrap()), }) } + + pub fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result { + if buf.len() < 8 { + return Err(ByteConversionError::ToSliceTooSmall(SizeMissmatch { + found: buf.len(), + expected: 8, + })); + } + buf[0..4].copy_from_slice(&self.target_id.to_be_bytes()); + buf[4..8].copy_from_slice(&self.unique_id.to_be_bytes()); + Ok(8) + } } /// Generic trait for object which can receive any telecommands in form of a raw bytestream, with diff --git a/satrs-example/src/hk.rs b/satrs-example/src/hk.rs index 96cd37b..d27c0f0 100644 --- a/satrs-example/src/hk.rs +++ b/satrs-example/src/hk.rs @@ -1,4 +1,5 @@ -#![allow(dead_code)] +use satrs_core::tmtc::AddressableId; + pub type CollectionIntervalFactor = u32; #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -8,8 +9,8 @@ pub enum AcsHkIds { #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum HkRequest { - OneShot(u32), - Enable(u32), - Disable(u32), - ModifyCollectionInterval(CollectionIntervalFactor), + OneShot(AddressableId), + Enable(AddressableId), + Disable(AddressableId), + ModifyCollectionInterval(AddressableId, CollectionIntervalFactor), } diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index 51c62ca..eecb858 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -4,7 +4,8 @@ mod pus; mod requests; mod tmtc; -use crate::requests::RequestWithToken; +use crate::hk::{AcsHkIds, HkRequest}; +use crate::requests::{Request, RequestWithToken}; use crate::tmtc::{ core_tmtc_task, OtherArgs, PusTcSource, TcArgs, TcStore, TmArgs, TmFunnel, TmStore, PUS_APID, }; @@ -214,16 +215,32 @@ fn main() { Ok(request) => { println!("ACS thread: Received HK request {:?}", request.0); update_time(&mut time_provider, &mut timestamp); - let mut sp_header = - SpHeader::tm(PUS_APID, SequenceFlags::Unsegmented, 0, 0).unwrap(); - let sec_header = PusTmSecondaryHeader::new_simple( - 3, - Subservice::TmHkPacket as u8, - ×tamp, - ); - let pus_tm = PusTm::new(&mut sp_header, sec_header, None, true); - let addr = aocs_tm_store.add_pus_tm(&pus_tm); - aocs_to_funnel.send(addr).expect("Sending HK TM failed"); + match request.0 { + Request::HkRequest(hk_req) => match hk_req { + HkRequest::OneShot(one_shot_req) => { + assert_eq!( + one_shot_req.unique_id, + RequestTargetId::AcsSubsystem as u32 + ); + if one_shot_req.unique_id == AcsHkIds::TestMgmSet as u32 { + let mut sp_header = + SpHeader::tm(PUS_APID, SequenceFlags::Unsegmented, 0, 0) + .unwrap(); + let sec_header = PusTmSecondaryHeader::new_simple( + 3, + Subservice::TmHkPacket as u8, + ×tamp, + ); + let pus_tm = PusTm::new(&mut sp_header, sec_header, None, true); + let addr = aocs_tm_store.add_pus_tm(&pus_tm); + aocs_to_funnel.send(addr).expect("Sending HK TM failed"); + } + } + HkRequest::Enable(_) => {} + HkRequest::Disable(_) => {} + HkRequest::ModifyCollectionInterval(_, _) => {} + }, + } let started_token = reporter_aocs .start_success(request.1, ×tamp) .expect("Sending start success failed"); diff --git a/satrs-example/src/pus.rs b/satrs-example/src/pus.rs index d0480f4..c7e1e40 100644 --- a/satrs-example/src/pus.rs +++ b/satrs-example/src/pus.rs @@ -171,11 +171,11 @@ impl PusReceiver { .unwrap_or_else(|_| panic!("Sending HK request {:?} failed", request)); }; if PusPacket::subservice(pus_tc) == hk::Subservice::TcEnableGeneration as u8 { - send_request(HkRequest::Enable(addressable_id.unique_id)); + send_request(HkRequest::Enable(addressable_id)); } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcDisableGeneration as u8 { - send_request(HkRequest::Disable(addressable_id.unique_id)); + send_request(HkRequest::Disable(addressable_id)); } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcGenerateOneShotHk as u8 { - send_request(HkRequest::OneShot(addressable_id.unique_id)); + send_request(HkRequest::OneShot(addressable_id)); } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcModifyCollectionInterval as u8 { if user_data.len() < 12 { @@ -193,6 +193,7 @@ impl PusReceiver { return; } send_request(HkRequest::ModifyCollectionInterval( + addressable_id, CollectionIntervalFactor::from_be_bytes(user_data[8..12].try_into().unwrap()), )); }