Merge pull request 'Change Request Type' (#36) from feature_change_request_types into main

Reviewed-on: #36
Reviewed-by: lkoester <st167799@stud.uni-stuttgart.de>
This commit is contained in:
Robin Müller 2023-02-27 21:46:51 +01:00
commit df7103cb82
5 changed files with 105 additions and 39 deletions

View File

@ -1,11 +1,16 @@
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,
}

View File

@ -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,
AnnounceMode,
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},
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};
@ -227,16 +228,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,
@ -250,7 +254,11 @@ fn main() {
&timestamp,
);
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,
@ -270,7 +278,7 @@ fn main() {
}
}
let started_token = reporter_aocs
.start_success(request.1, Some(&timestamp))
.start_success(request.token, Some(&timestamp))
.expect("Sending start success failed");
reporter_aocs
.completion_success(started_token, Some(&timestamp))

View File

@ -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:?}");

View File

@ -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<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,
}
}
}