Merge branch 'main' into feature_sender_abstraction_has_id_and_name

This commit is contained in:
lkoester 2023-02-28 18:35:16 +01:00
commit 2f724f8ce3
5 changed files with 111 additions and 41 deletions

View File

@ -1,11 +1,16 @@
use crate::tmtc::AddressableId;
pub type CollectionIntervalFactor = u32; pub type CollectionIntervalFactor = u32;
pub type UniqueId = u32;
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum HkRequest { pub enum HkRequest {
OneShot(AddressableId), OneShot(UniqueId),
Enable(AddressableId), Enable(UniqueId),
Disable(AddressableId), Disable(UniqueId),
ModifyCollectionInterval(AddressableId, CollectionIntervalFactor), ModifyCollectionInterval(UniqueId, CollectionIntervalFactor),
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct TargetedHkRequest {
target: u32,
hk_request: HkRequest,
} }

View File

@ -35,12 +35,16 @@ impl ModeAndSubmode {
submode: u16::from_be_bytes(buf[4..6].try_into().unwrap()), submode: u16::from_be_bytes(buf[4..6].try_into().unwrap()),
}) })
} }
pub fn mode(&self) -> u32 {self.mode}
pub fn submode(&self) -> u16 {self.submode}
} }
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ModeCommand { pub struct ModeCommand {
address: TargetId, pub address: TargetId,
mode_submode: ModeAndSubmode, pub mode_submode: ModeAndSubmode,
} }
impl ModeCommand { impl ModeCommand {
@ -71,8 +75,15 @@ impl ModeCommand {
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum ModeRequest { pub enum ModeRequest {
SetMode(ModeCommand), SetMode(ModeAndSubmode),
ReadMode(TargetId), ReadMode,
AnnounceMode(TargetId), AnnounceMode,
AnnounceModeRecursive(TargetId), AnnounceModeRecursive,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TargetedModeRequest {
target_id: TargetId,
mode_request: ModeRequest,
} }

View File

@ -35,6 +35,7 @@ use satrs_core::spacepackets::{
tm::{PusTm, PusTmSecondaryHeader}, tm::{PusTm, PusTmSecondaryHeader},
SequenceFlags, SpHeader, SequenceFlags, SpHeader,
}; };
use satrs_core::tmtc::AddressableId;
use satrs_example::{RequestTargetId, OBSW_SERVER_ADDR, SERVER_PORT}; use satrs_example::{RequestTargetId, OBSW_SERVER_ADDR, SERVER_PORT};
use std::collections::HashMap; use std::collections::HashMap;
use std::net::{IpAddr, SocketAddr}; use std::net::{IpAddr, SocketAddr};
@ -233,16 +234,19 @@ fn main() {
loop { loop {
match acs_thread_rx.try_recv() { match acs_thread_rx.try_recv() {
Ok(request) => { 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); update_time(&mut time_provider, &mut timestamp);
match request.0 { match request.targeted_request.request {
Request::HkRequest(hk_req) => match hk_req { Request::HkRequest(hk_req) => match hk_req {
HkRequest::OneShot(address) => { HkRequest::OneShot(unique_id) => {
assert_eq!( let target = request.targeted_request.target_id;
address.target_id, assert_eq!(target, RequestTargetId::AcsSubsystem as u32);
RequestTargetId::AcsSubsystem as u32 if request.targeted_request.target_id
); == AcsHkIds::TestMgmSet as u32
if address.unique_id == AcsHkIds::TestMgmSet as u32 { {
let mut sp_header = SpHeader::tm( let mut sp_header = SpHeader::tm(
PUS_APID, PUS_APID,
SequenceFlags::Unsegmented, SequenceFlags::Unsegmented,
@ -256,7 +260,11 @@ fn main() {
&timestamp, &timestamp,
); );
let mut buf: [u8; 8] = [0; 8]; 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( let pus_tm = PusTm::new(
&mut sp_header, &mut sp_header,
sec_header, sec_header,
@ -276,7 +284,7 @@ fn main() {
} }
} }
let started_token = reporter_aocs let started_token = reporter_aocs
.start_success(request.1, Some(&timestamp)) .start_success(request.token, Some(&timestamp))
.expect("Sending start success failed"); .expect("Sending start success failed");
reporter_aocs reporter_aocs
.completion_success(started_token, Some(&timestamp)) .completion_success(started_token, Some(&timestamp))

View File

@ -3,7 +3,7 @@ use crate::tmtc::{PusTcSource, TmStore};
use log::{info, warn}; use log::{info, warn};
use satrs_core::events::EventU32; use satrs_core::events::EventU32;
use satrs_core::hk::{CollectionIntervalFactor, HkRequest}; 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::params::Params;
use satrs_core::pool::StoreAddr; use satrs_core::pool::StoreAddr;
use satrs_core::pus::event_man::{EventRequest, EventRequestWithToken}; use satrs_core::pus::event_man::{EventRequest, EventRequestWithToken};
@ -268,22 +268,35 @@ impl PusReceiver {
.expect("Sending start failure TM failed"); .expect("Sending start failure TM failed");
return; return;
} }
let send_request = |request: HkRequest| { let send_request = |target: TargetId, request: HkRequest| {
let sender = self let sender = self
.tc_args .tc_args
.request_map .request_map
.get(&addressable_id.target_id) .get(&addressable_id.target_id)
.unwrap(); .unwrap();
sender sender
.send(RequestWithToken(Request::HkRequest(request), token)) .send(RequestWithToken::new(
target,
Request::HkRequest(request),
token,
))
.unwrap_or_else(|_| panic!("Sending HK request {request:?} failed")); .unwrap_or_else(|_| panic!("Sending HK request {request:?} failed"));
}; };
if PusPacket::subservice(pus_tc) == hk::Subservice::TcEnableHkGeneration as u8 { 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 { } 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 { } 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) } else if PusPacket::subservice(pus_tc)
== hk::Subservice::TcModifyHkCollectionInterval as u8 == hk::Subservice::TcModifyHkCollectionInterval as u8
{ {
@ -301,10 +314,13 @@ impl PusReceiver {
.expect("Sending start failure TM failed"); .expect("Sending start failure TM failed");
return; return;
} }
send_request(HkRequest::ModifyCollectionInterval( send_request(
addressable_id, addressable_id.target_id,
CollectionIntervalFactor::from_be_bytes(user_data[8..12].try_into().unwrap()), 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"), None => warn!("not mode request recipient for target ID {target_id} found"),
Some(sender_to_recipient) => { Some(sender_to_recipient) => {
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"); .expect("sending mode request failed");
} }
}; };
@ -582,22 +602,19 @@ impl PusReceiver {
.unwrap(), .unwrap(),
) )
.unwrap(); .unwrap();
forward_mode_request( forward_mode_request(target_id, ModeRequest::SetMode(mode_submode));
target_id,
ModeRequest::SetMode(ModeCommand::new(target_id, mode_submode)),
);
} }
Subservice::TcReadMode => { Subservice::TcReadMode => {
let target_id = u32::from_be_bytes(app_data[0..4].try_into().unwrap()); 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 => { Subservice::TcAnnounceMode => {
let target_id = u32::from_be_bytes(app_data[0..4].try_into().unwrap()); 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 => { Subservice::TcAnnounceModeRecursive => {
let target_id = u32::from_be_bytes(app_data[0..4].try_into().unwrap()); 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:?}"); warn!("Can not process mode request with subservice {subservice:?}");

View File

@ -1,6 +1,7 @@
use satrs_core::hk::HkRequest; use satrs_core::hk::HkRequest;
use satrs_core::mode::ModeRequest; use satrs_core::mode::ModeRequest;
use satrs_core::pus::verification::{TcStateAccepted, VerificationToken}; use satrs_core::pus::verification::{TcStateAccepted, VerificationToken};
use satrs_core::tmtc::TargetId;
#[derive(Copy, Clone, Eq, PartialEq, Debug)] #[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[non_exhaustive] #[non_exhaustive]
@ -10,4 +11,32 @@ pub enum Request {
} }
#[derive(Copy, Clone, Eq, PartialEq, Debug)] #[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub struct RequestWithToken(pub Request, pub VerificationToken<TcStateAccepted>); 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<TcStateAccepted>,
}
impl RequestWithToken {
pub fn new(
target_id: u32,
request: Request,
token: VerificationToken<TcStateAccepted>,
) -> Self {
Self {
targeted_request: TargetedRequest::new(target_id, request),
token,
}
}
}