use generic request ID type
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
Robin Müller 2024-02-28 11:05:22 +01:00
parent 9f82c57a95
commit dca573e8a9
Signed by: muellerr
GPG Key ID: A649FB78196E3849
3 changed files with 36 additions and 11 deletions

View File

@ -1,10 +1,11 @@
use crate::{ use crate::{
action::{ActionId, ActionRequest}, action::{ActionId, ActionRequest},
params::Params, params::Params,
request::RequestId,
TargetId, TargetId,
}; };
use super::verification::{RequestId, TcStateAccepted, VerificationToken}; use super::verification::{TcStateAccepted, VerificationToken};
use satrs_shared::res_code::ResultU16; use satrs_shared::res_code::ResultU16;
use spacepackets::ecss::EcssEnumU16; use spacepackets::ecss::EcssEnumU16;
@ -19,14 +20,14 @@ pub use alloc_mod::*;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct ActionRequestWithId { pub struct ActionRequestWithId {
pub req_id: RequestId, pub request_id: RequestId,
pub request: ActionRequest, pub request: ActionRequest,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct ActionReplyPusWithIds { pub struct ActionReplyPusWithIds {
pub request_id: RequestId,
pub action_id: ActionId, pub action_id: ActionId,
pub req_id: RequestId,
pub reply: ActionReplyPus, pub reply: ActionReplyPus,
} }
@ -105,13 +106,13 @@ pub mod std_mod {
pus::{ pus::{
get_current_cds_short_timestamp, get_current_cds_short_timestamp,
verification::{ verification::{
FailParams, FailParamsWithStep, RequestId, TcStateStarted, self, FailParams, FailParamsWithStep, TcStateStarted, VerificationReportingProvider,
VerificationReportingProvider,
}, },
EcssTcInMemConverter, EcssTcReceiverCore, EcssTmSenderCore, EcssTmtcError, EcssTcInMemConverter, EcssTcReceiverCore, EcssTmSenderCore, EcssTmtcError,
GenericRoutingError, PusPacketHandlerResult, PusPacketHandlingError, GenericRoutingError, PusPacketHandlerResult, PusPacketHandlingError,
PusRoutingErrorHandler, PusServiceHelper, PusRoutingErrorHandler, PusServiceHelper,
}, },
request::RequestId,
}; };
use hashbrown::HashMap; use hashbrown::HashMap;
use spacepackets::time::UnixTimestamp; use spacepackets::time::UnixTimestamp;
@ -245,12 +246,12 @@ pub mod std_mod {
{ {
pub fn add_routed_request( pub fn add_routed_request(
&mut self, &mut self,
request_id: RequestId, request_id: verification::RequestId,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
timeout_seconds: u32, timeout_seconds: u32,
) { ) {
self.active_requests.insert( self.active_requests.insert(
request_id, request_id.into(),
ActiveRequest { ActiveRequest {
token, token,
start_time: self.current_time, start_time: self.current_time,
@ -297,7 +298,7 @@ pub mod std_mod {
action_reply_with_ids: ActionReplyPusWithIds, action_reply_with_ids: ActionReplyPusWithIds,
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<(), EcssTmtcError> { ) -> Result<(), EcssTmtcError> {
let active_req = self.active_requests.get(&action_reply_with_ids.req_id); let active_req = self.active_requests.get(&action_reply_with_ids.request_id);
if active_req.is_none() { if active_req.is_none() {
// TODO: This is an unexpected reply. We need to deal with this somehow. // TODO: This is an unexpected reply. We need to deal with this somehow.
} }
@ -311,7 +312,8 @@ pub mod std_mod {
FailParams::new(time_stamp, &error_code, &self.fail_data_buf), FailParams::new(time_stamp, &error_code, &self.fail_data_buf),
) )
.map_err(|e| e.0)?; .map_err(|e| e.0)?;
self.active_requests.remove(&action_reply_with_ids.req_id); self.active_requests
.remove(&action_reply_with_ids.request_id);
} }
ActionReplyPus::StepFailed { ActionReplyPus::StepFailed {
error_code, error_code,
@ -330,13 +332,15 @@ pub mod std_mod {
), ),
) )
.map_err(|e| e.0)?; .map_err(|e| e.0)?;
self.active_requests.remove(&action_reply_with_ids.req_id); self.active_requests
.remove(&action_reply_with_ids.request_id);
} }
ActionReplyPus::Completed => { ActionReplyPus::Completed => {
self.verification_reporter self.verification_reporter
.completion_success(active_req.token, time_stamp) .completion_success(active_req.token, time_stamp)
.map_err(|e| e.0)?; .map_err(|e| e.0)?;
self.active_requests.remove(&action_reply_with_ids.req_id); self.active_requests
.remove(&action_reply_with_ids.request_id);
} }
ActionReplyPus::StepSuccess { step } => { ActionReplyPus::StepSuccess { step } => {
self.verification_reporter self.verification_reporter

View File

@ -173,6 +173,22 @@ impl RequestId {
} }
} }
impl From<u32> for RequestId {
fn from(value: u32) -> Self {
Self {
version_number: ((value >> 29) & 0b111) as u8,
packet_id: PacketId::from(((value >> 16) & 0xffff) as u16),
psc: PacketSequenceCtrl::from((value & 0xffff) as u16),
}
}
}
impl From<RequestId> for u32 {
fn from(value: RequestId) -> Self {
value.raw()
}
}
/// If a verification operation fails, the passed token will be returned as well. This allows /// If a verification operation fails, the passed token will be returned as well. This allows
/// re-trying the operation at a later point. /// re-trying the operation at a later point.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -13,6 +13,11 @@ use spacepackets::{
use crate::{queue::GenericTargetedMessagingError, ChannelId, TargetId}; use crate::{queue::GenericTargetedMessagingError, ChannelId, TargetId};
/// Generic request ID type. Requests can be associated with an ID to have a unique identifier
/// for them. This can be useful for tasks like tracking their progress.
pub type RequestId = u32;
/// CCSDS APID type definition. Please note that the APID is a 14 bit value.
pub type Apid = u16; pub type Apid = u16;
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]