generics shananigans
This commit is contained in:
parent
b0d32aff4f
commit
1fbb400809
@ -7,9 +7,10 @@ use crate::{
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
verification::{TcStateAccepted, VerificationToken},
|
verification::{TcStateAccepted, VerificationToken},
|
||||||
ActiveRequest,
|
ActiveRequest, ActiveRequestProvider,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use delegate::delegate;
|
||||||
use satrs_shared::res_code::ResultU16;
|
use satrs_shared::res_code::ResultU16;
|
||||||
use spacepackets::ecss::EcssEnumU16;
|
use spacepackets::ecss::EcssEnumU16;
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ pub struct ActionReplyPusWithIds {
|
|||||||
|
|
||||||
/// A reply to an action request, but tailored to the PUS standard verification process.
|
/// A reply to an action request, but tailored to the PUS standard verification process.
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
pub enum ActionReplyPus {
|
pub enum ActionReplyPus {
|
||||||
Completed,
|
Completed,
|
||||||
StepSuccess {
|
StepSuccess {
|
||||||
@ -71,6 +72,17 @@ pub struct ActiveActionRequest {
|
|||||||
common: ActiveRequest,
|
common: ActiveRequest,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ActiveRequestProvider for ActiveActionRequest {
|
||||||
|
delegate! {
|
||||||
|
to self.common {
|
||||||
|
fn target_id(&self) -> TargetId;
|
||||||
|
fn token(&self) -> VerificationToken<super::verification::TcStateStarted>;
|
||||||
|
fn start_time(&self) -> spacepackets::time::UnixTimestamp;
|
||||||
|
fn timeout(&self) -> core::time::Duration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||||
pub mod alloc_mod {
|
pub mod alloc_mod {
|
||||||
@ -117,15 +129,15 @@ pub mod std_mod {
|
|||||||
verification::{
|
verification::{
|
||||||
self, FailParams, FailParamsWithStep, TcStateStarted, VerificationReportingProvider,
|
self, FailParams, FailParamsWithStep, TcStateStarted, VerificationReportingProvider,
|
||||||
},
|
},
|
||||||
ActiveRequestMapProvider, DefaultActiveRequestMap, EcssTcInMemConverter,
|
ActiveRequestMapProvider, ActiveRequestProvider, DefaultActiveRequestMap,
|
||||||
EcssTcReceiverCore, EcssTmSenderCore, EcssTmtcError, GenericRoutingError,
|
EcssTcInMemConverter, EcssTcReceiverCore, EcssTmSenderCore, EcssTmtcError,
|
||||||
PusPacketHandlerResult, PusPacketHandlingError, PusRoutingErrorHandler,
|
GenericRoutingError, PusPacketHandlerResult, PusPacketHandlingError,
|
||||||
PusServiceHelper,
|
PusRoutingErrorHandler, PusServiceHelper,
|
||||||
},
|
},
|
||||||
request::RequestId,
|
request::RequestId,
|
||||||
};
|
};
|
||||||
use core::time::Duration;
|
use core::{marker::PhantomData, time::Duration};
|
||||||
use hashbrown::HashMap;
|
use delegate::delegate;
|
||||||
use spacepackets::time::UnixTimestamp;
|
use spacepackets::time::UnixTimestamp;
|
||||||
use std::time::SystemTimeError;
|
use std::time::SystemTimeError;
|
||||||
|
|
||||||
@ -240,29 +252,41 @@ pub mod std_mod {
|
|||||||
|
|
||||||
pub type DefaultActiveActionRequestMap = DefaultActiveRequestMap<ActiveActionRequest>;
|
pub type DefaultActiveActionRequestMap = DefaultActiveRequestMap<ActiveActionRequest>;
|
||||||
|
|
||||||
pub trait ActionReplyHandlerHook {
|
pub trait ReplyHandlerHook<ActiveRequestType, Reply> {
|
||||||
fn handle_unexpected_reply(&mut self, reply: &ActionReplyPusWithIds);
|
fn handle_unexpected_reply(&mut self, reply: &Reply);
|
||||||
fn timeout_callback(&self, active_request: &ActiveActionRequest);
|
fn timeout_callback(&self, active_request: &ActiveRequestType);
|
||||||
fn timeout_error_code(&self) -> ResultU16;
|
fn timeout_error_code(&self) -> ResultU16;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PusService8ReplyHandler<
|
pub struct PusServiceReplyHandler<
|
||||||
VerificationReporter: VerificationReportingProvider,
|
VerificationReporter: VerificationReportingProvider,
|
||||||
ActiveRequestMap: ActiveRequestMapProvider<ActiveActionRequest>,
|
ActiveRequestMap: ActiveRequestMapProvider<ActiveRequestType>,
|
||||||
UserHook: ActionReplyHandlerHook,
|
UserHook: ReplyHandlerHook<ActiveRequestType, Reply>,
|
||||||
|
ActiveRequestType: ActiveRequestProvider,
|
||||||
|
Reply,
|
||||||
> {
|
> {
|
||||||
active_request_map: ActiveRequestMap,
|
active_request_map: ActiveRequestMap,
|
||||||
verification_reporter: VerificationReporter,
|
verification_reporter: VerificationReporter,
|
||||||
fail_data_buf: alloc::vec::Vec<u8>,
|
fail_data_buf: alloc::vec::Vec<u8>,
|
||||||
current_time: UnixTimestamp,
|
current_time: UnixTimestamp,
|
||||||
user_hook: UserHook,
|
pub user_hook: UserHook,
|
||||||
|
phantom: PhantomData<(ActiveRequestType, Reply)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
VerificationReporter: VerificationReportingProvider,
|
VerificationReporter: VerificationReportingProvider,
|
||||||
ActiveRequestMap: ActiveRequestMapProvider<ActiveActionRequest>,
|
ActiveRequestMap: ActiveRequestMapProvider<ActiveRequestType>,
|
||||||
UserHook: ActionReplyHandlerHook,
|
UserHook: ReplyHandlerHook<ActiveRequestType, ReplyType>,
|
||||||
> PusService8ReplyHandler<VerificationReporter, ActiveRequestMap, UserHook>
|
ActiveRequestType: ActiveRequestProvider,
|
||||||
|
ReplyType,
|
||||||
|
>
|
||||||
|
PusServiceReplyHandler<
|
||||||
|
VerificationReporter,
|
||||||
|
ActiveRequestMap,
|
||||||
|
UserHook,
|
||||||
|
ActiveRequestType,
|
||||||
|
ReplyType,
|
||||||
|
>
|
||||||
{
|
{
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||||
@ -295,48 +319,31 @@ pub mod std_mod {
|
|||||||
fail_data_buf: alloc::vec![0; fail_data_buf_size],
|
fail_data_buf: alloc::vec![0; fail_data_buf_size],
|
||||||
current_time: init_time,
|
current_time: init_time,
|
||||||
user_hook,
|
user_hook,
|
||||||
|
phantom: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_routed_request(
|
pub fn add_routed_request(
|
||||||
&mut self,
|
&mut self,
|
||||||
request_id: verification::RequestId,
|
request_id: verification::RequestId,
|
||||||
action_id: ActionId,
|
active_request_type: ActiveRequestType,
|
||||||
token: VerificationToken<TcStateStarted>,
|
|
||||||
timeout: Duration,
|
|
||||||
) {
|
) {
|
||||||
self.active_request_map.insert(
|
self.active_request_map
|
||||||
&request_id.into(),
|
.insert(&request_id.into(), active_request_type);
|
||||||
ActiveActionRequest {
|
|
||||||
action_id,
|
|
||||||
common: ActiveRequest {
|
|
||||||
token,
|
|
||||||
start_time: self.current_time,
|
|
||||||
timeout,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn request_active(&self, request_id: RequestId) -> bool {
|
pub fn request_active(&self, request_id: RequestId) -> bool {
|
||||||
self.active_request_map.get(request_id).is_some()
|
self.active_request_map.get(request_id).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
|
||||||
pub fn update_time_from_now(&mut self) -> Result<(), SystemTimeError> {
|
|
||||||
self.current_time = UnixTimestamp::from_now()?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check for timeouts across all active requests.
|
/// Check for timeouts across all active requests.
|
||||||
///
|
///
|
||||||
/// It will call [Self::handle_timeout] for all active requests which have timed out.
|
/// It will call [Self::handle_timeout] for all active requests which have timed out.
|
||||||
pub fn check_for_timeouts(&mut self, time_stamp: &[u8]) -> Result<(), EcssTmtcError> {
|
pub fn check_for_timeouts(&mut self, time_stamp: &[u8]) -> Result<(), EcssTmtcError> {
|
||||||
let mut timed_out_commands = alloc::vec::Vec::new();
|
let mut timed_out_commands = alloc::vec::Vec::new();
|
||||||
self.active_request_map.for_each(|request_id, active_req| {
|
self.active_request_map.for_each(|request_id, active_req| {
|
||||||
let diff = self.current_time - active_req.common.start_time;
|
let diff = self.current_time - active_req.start_time();
|
||||||
if diff.duration_absolute > active_req.common.timeout {
|
if diff.duration_absolute > active_req.timeout() {
|
||||||
self.handle_timeout(active_req, time_stamp);
|
self.handle_timeout(active_req, time_stamp);
|
||||||
}
|
}
|
||||||
timed_out_commands.push(*request_id);
|
timed_out_commands.push(*request_id);
|
||||||
@ -352,12 +359,12 @@ pub mod std_mod {
|
|||||||
/// This implementation will report a verification completion failure with a user-provided
|
/// This implementation will report a verification completion failure with a user-provided
|
||||||
/// error code. It supplies the configured request timeout in milliseconds as a [u64]
|
/// error code. It supplies the configured request timeout in milliseconds as a [u64]
|
||||||
/// serialized in big-endian format as the failure data.
|
/// serialized in big-endian format as the failure data.
|
||||||
pub fn handle_timeout(&self, active_request: &ActiveActionRequest, time_stamp: &[u8]) {
|
pub fn handle_timeout(&self, active_request: &ActiveRequestType, time_stamp: &[u8]) {
|
||||||
let timeout = active_request.common.timeout.as_millis() as u64;
|
let timeout = active_request.timeout().as_millis() as u64;
|
||||||
let timeout_raw = timeout.to_be_bytes();
|
let timeout_raw = timeout.to_be_bytes();
|
||||||
self.verification_reporter
|
self.verification_reporter
|
||||||
.completion_failure(
|
.completion_failure(
|
||||||
active_request.common.token,
|
active_request.token(),
|
||||||
FailParams::new(
|
FailParams::new(
|
||||||
time_stamp,
|
time_stamp,
|
||||||
&self.user_hook.timeout_error_code(),
|
&self.user_hook.timeout_error_code(),
|
||||||
@ -368,29 +375,150 @@ pub mod std_mod {
|
|||||||
self.user_hook.timeout_callback(active_request);
|
self.user_hook.timeout_callback(active_request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||||
|
pub fn update_time_from_now(&mut self) -> Result<(), SystemTimeError> {
|
||||||
|
self.current_time = UnixTimestamp::from_now()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type PusService8ReplyHandler<VerificationReporter, ActiveRequestMap, UserHook> =
|
||||||
|
PusServiceReplyHandler<
|
||||||
|
VerificationReporter,
|
||||||
|
DefaultActiveActionRequestMap,
|
||||||
|
UserHook,
|
||||||
|
ActiveActionRequest,
|
||||||
|
ActionReplyPusWithIds,
|
||||||
|
>;
|
||||||
|
/*
|
||||||
|
pub struct PusService8ReplyHandler<
|
||||||
|
VerificationReporter: VerificationReportingProvider,
|
||||||
|
ActiveRequestMap: ActiveRequestMapProvider<ActiveActionRequest>,
|
||||||
|
UserHook: ReplyHandlerHook<ActiveActionRequest, ActionReplyPusWithIds>,
|
||||||
|
> {
|
||||||
|
pub inner: PusServiceReplyHandler<
|
||||||
|
VerificationReporter,
|
||||||
|
ActiveRequestMap,
|
||||||
|
UserHook,
|
||||||
|
ActiveActionRequest,
|
||||||
|
ActionReplyPusWithIds,
|
||||||
|
>,
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
impl<
|
||||||
|
VerificationReporter: VerificationReportingProvider,
|
||||||
|
ActiveRequestMap: ActiveRequestMapProvider<ActiveActionRequest>,
|
||||||
|
UserHook: ReplyHandlerHook<ActiveActionRequest, ActionReplyPusWithIds>,
|
||||||
|
> PusService8ReplyHandler<VerificationReporter, ActiveRequestMap, UserHook>
|
||||||
|
{
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||||
|
pub fn new_from_now(
|
||||||
|
verification_reporter: VerificationReporter,
|
||||||
|
active_request_map: ActiveRequestMap,
|
||||||
|
fail_data_buf_size: usize,
|
||||||
|
user_hook: UserHook,
|
||||||
|
) -> Result<Self, SystemTimeError> {
|
||||||
|
let current_time = UnixTimestamp::from_now()?;
|
||||||
|
Ok(Self::new(
|
||||||
|
verification_reporter,
|
||||||
|
active_request_map,
|
||||||
|
fail_data_buf_size,
|
||||||
|
user_hook,
|
||||||
|
current_time,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(
|
||||||
|
verification_reporter: VerificationReporter,
|
||||||
|
active_request_map: ActiveRequestMap,
|
||||||
|
fail_data_buf_size: usize,
|
||||||
|
user_hook: UserHook,
|
||||||
|
init_time: UnixTimestamp,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
inner: PusServiceReplyHandler::new(
|
||||||
|
verification_reporter,
|
||||||
|
active_request_map,
|
||||||
|
fail_data_buf_size,
|
||||||
|
user_hook,
|
||||||
|
init_time,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_routed_request(
|
||||||
|
&mut self,
|
||||||
|
request_id: verification::RequestId,
|
||||||
|
target_id: TargetId,
|
||||||
|
action_id: ActionId,
|
||||||
|
token: VerificationToken<TcStateStarted>,
|
||||||
|
timeout: Duration,
|
||||||
|
) {
|
||||||
|
self.inner.active_request_map.insert(
|
||||||
|
&request_id.into(),
|
||||||
|
ActiveActionRequest {
|
||||||
|
action_id,
|
||||||
|
common: ActiveRequest {
|
||||||
|
target_id,
|
||||||
|
token,
|
||||||
|
start_time: self.inner.current_time,
|
||||||
|
timeout,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate! {
|
||||||
|
to self.inner {
|
||||||
|
pub fn request_active(&self, request_id: RequestId) -> bool;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||||
|
pub fn update_time_from_now(&mut self) -> Result<(), SystemTimeError>;
|
||||||
|
|
||||||
|
/// Check for timeouts across all active requests.
|
||||||
|
///
|
||||||
|
/// It will call [Self::handle_timeout] for all active requests which have timed out.
|
||||||
|
pub fn check_for_timeouts(&mut self, time_stamp: &[u8]) -> Result<(), EcssTmtcError>;
|
||||||
|
|
||||||
|
/// Handle the timeout for a given active request.
|
||||||
|
///
|
||||||
|
/// This implementation will report a verification completion failure with a user-provided
|
||||||
|
/// error code. It supplies the configured request timeout in milliseconds as a [u64]
|
||||||
|
/// serialized in big-endian format as the failure data.
|
||||||
|
pub fn handle_timeout(&self, active_request: &ActiveActionRequest, time_stamp: &[u8]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_action_reply(
|
pub fn handle_action_reply(
|
||||||
&mut self,
|
&mut self,
|
||||||
action_reply_with_ids: ActionReplyPusWithIds,
|
action_reply_with_ids: ActionReplyPusWithIds,
|
||||||
time_stamp: &[u8],
|
time_stamp: &[u8],
|
||||||
) -> Result<(), EcssTmtcError> {
|
) -> Result<(), EcssTmtcError> {
|
||||||
let active_req = self
|
let active_req = self
|
||||||
|
.inner
|
||||||
.active_request_map
|
.active_request_map
|
||||||
.get(action_reply_with_ids.request_id);
|
.get(action_reply_with_ids.request_id);
|
||||||
if active_req.is_none() {
|
if active_req.is_none() {
|
||||||
self.user_hook
|
self.inner
|
||||||
|
.user_hook
|
||||||
.handle_unexpected_reply(&action_reply_with_ids);
|
.handle_unexpected_reply(&action_reply_with_ids);
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
let active_req = active_req.unwrap().clone();
|
let active_req = active_req.unwrap().clone();
|
||||||
let remove_entry = match action_reply_with_ids.reply {
|
let remove_entry = match action_reply_with_ids.reply {
|
||||||
ActionReplyPus::CompletionFailed { error_code, params } => {
|
ActionReplyPus::CompletionFailed { error_code, params } => {
|
||||||
let fail_data_len = params.write_to_be_bytes(&mut self.fail_data_buf)?;
|
let fail_data_len = params.write_to_be_bytes(&mut self.inner.fail_data_buf)?;
|
||||||
self.verification_reporter
|
self.inner
|
||||||
|
.verification_reporter
|
||||||
.completion_failure(
|
.completion_failure(
|
||||||
active_req.common.token,
|
active_req.common.token,
|
||||||
FailParams::new(
|
FailParams::new(
|
||||||
time_stamp,
|
time_stamp,
|
||||||
&error_code,
|
&error_code,
|
||||||
&self.fail_data_buf[..fail_data_len],
|
&self.inner.fail_data_buf[..fail_data_len],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.map_err(|e| e.0)?;
|
.map_err(|e| e.0)?;
|
||||||
@ -401,28 +529,30 @@ pub mod std_mod {
|
|||||||
step,
|
step,
|
||||||
params,
|
params,
|
||||||
} => {
|
} => {
|
||||||
let fail_data_len = params.write_to_be_bytes(&mut self.fail_data_buf)?;
|
let fail_data_len = params.write_to_be_bytes(&mut self.inner.fail_data_buf)?;
|
||||||
self.verification_reporter
|
self.inner
|
||||||
|
.verification_reporter
|
||||||
.step_failure(
|
.step_failure(
|
||||||
active_req.common.token,
|
active_req.common.token,
|
||||||
FailParamsWithStep::new(
|
FailParamsWithStep::new(
|
||||||
time_stamp,
|
time_stamp,
|
||||||
&EcssEnumU16::new(step),
|
&EcssEnumU16::new(step),
|
||||||
&error_code,
|
&error_code,
|
||||||
&self.fail_data_buf[..fail_data_len],
|
&self.inner.fail_data_buf[..fail_data_len],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.map_err(|e| e.0)?;
|
.map_err(|e| e.0)?;
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
ActionReplyPus::Completed => {
|
ActionReplyPus::Completed => {
|
||||||
self.verification_reporter
|
self.inner
|
||||||
|
.verification_reporter
|
||||||
.completion_success(active_req.common.token, time_stamp)
|
.completion_success(active_req.common.token, time_stamp)
|
||||||
.map_err(|e| e.0)?;
|
.map_err(|e| e.0)?;
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
ActionReplyPus::StepSuccess { step } => {
|
ActionReplyPus::StepSuccess { step } => {
|
||||||
self.verification_reporter.step_success(
|
self.inner.verification_reporter.step_success(
|
||||||
&active_req.common.token,
|
&active_req.common.token,
|
||||||
time_stamp,
|
time_stamp,
|
||||||
EcssEnumU16::new(step),
|
EcssEnumU16::new(step),
|
||||||
@ -431,15 +561,18 @@ pub mod std_mod {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
if remove_entry {
|
if remove_entry {
|
||||||
self.active_request_map
|
self.inner
|
||||||
|
.active_request_map
|
||||||
.remove(action_reply_with_ids.request_id);
|
.remove(action_reply_with_ids.request_id);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<VerificationReporter: VerificationReportingProvider, UserHook: ActionReplyHandlerHook>
|
impl<
|
||||||
PusService8ReplyHandler<VerificationReporter, DefaultActiveActionRequestMap, UserHook>
|
VerificationReporter: VerificationReportingProvider,
|
||||||
|
UserHook: ReplyHandlerHook<ActiveActionRequest, ActionReplyPusWithIds>,
|
||||||
|
> PusService8ReplyHandler<VerificationReporter, DefaultActiveActionRequestMap, UserHook>
|
||||||
{
|
{
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||||
@ -465,7 +598,7 @@ pub mod std_mod {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new(
|
Self::new(
|
||||||
verification_reporter,
|
verification_reporter,
|
||||||
DefaultActiveRequestMap::<ActiveActionRequest>(HashMap::default()),
|
DefaultActiveActionRequestMap::default(),
|
||||||
fail_data_buf_size,
|
fail_data_buf_size,
|
||||||
user_hook,
|
user_hook,
|
||||||
init_time,
|
init_time,
|
||||||
@ -650,7 +783,7 @@ mod tests {
|
|||||||
pub timeouts: RefCell<VecDeque<ActiveActionRequest>>,
|
pub timeouts: RefCell<VecDeque<ActiveActionRequest>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActionReplyHandlerHook for TestReplyHandlerHook {
|
impl ReplyHandlerHook<ActiveActionRequest, ActionReplyPusWithIds> for TestReplyHandlerHook {
|
||||||
fn handle_unexpected_reply(&mut self, reply: &ActionReplyPusWithIds) {
|
fn handle_unexpected_reply(&mut self, reply: &ActionReplyPusWithIds) {
|
||||||
self.unexpected_replies.push_back(reply.clone());
|
self.unexpected_replies.push_back(reply.clone());
|
||||||
}
|
}
|
||||||
@ -674,16 +807,26 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Pus8ReplyTestbench {
|
impl Pus8ReplyTestbench {
|
||||||
pub fn new() -> Self {
|
pub fn new(normal_ctor: bool) -> Self {
|
||||||
let reply_handler_hook = TestReplyHandlerHook::default();
|
let reply_handler_hook = TestReplyHandlerHook::default();
|
||||||
let shared_verif_map = SharedVerificationMap::default();
|
let shared_verif_map = SharedVerificationMap::default();
|
||||||
let test_verif_reporter = TestVerificationReporter::new(shared_verif_map.clone());
|
let test_verif_reporter = TestVerificationReporter::new(shared_verif_map.clone());
|
||||||
let reply_handler = PusService8ReplyHandler::new_from_now_with_default_map(
|
let reply_handler = if normal_ctor {
|
||||||
test_verif_reporter.clone(),
|
PusService8ReplyHandler::new_from_now_with_default_map(
|
||||||
128,
|
test_verif_reporter.clone(),
|
||||||
reply_handler_hook,
|
128,
|
||||||
)
|
reply_handler_hook,
|
||||||
.expect("creating reply handler failed");
|
)
|
||||||
|
.expect("creating reply handler failed")
|
||||||
|
} else {
|
||||||
|
PusService8ReplyHandler::new_from_now(
|
||||||
|
test_verif_reporter.clone(),
|
||||||
|
DefaultActiveActionRequestMap::default(),
|
||||||
|
128,
|
||||||
|
reply_handler_hook,
|
||||||
|
)
|
||||||
|
.expect("creating reply handler failed")
|
||||||
|
};
|
||||||
Self {
|
Self {
|
||||||
verif_reporter: test_verif_reporter,
|
verif_reporter: test_verif_reporter,
|
||||||
handler: reply_handler,
|
handler: reply_handler,
|
||||||
@ -715,6 +858,15 @@ mod tests {
|
|||||||
token
|
token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn next_unrequested_reply(&self) -> Option<ActionReplyPusWithIds> {
|
||||||
|
self.handler
|
||||||
|
.inner
|
||||||
|
.user_hook
|
||||||
|
.unexpected_replies
|
||||||
|
.front()
|
||||||
|
.cloned()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn assert_request_completion_success(&self, step: Option<u16>, request_id: RequestId) {
|
pub fn assert_request_completion_success(&self, step: Option<u16>, request_id: RequestId) {
|
||||||
let verif_info = self
|
let verif_info = self
|
||||||
.verif_reporter
|
.verif_reporter
|
||||||
@ -770,6 +922,7 @@ mod tests {
|
|||||||
pub fn add_routed_request(
|
pub fn add_routed_request(
|
||||||
&mut self,
|
&mut self,
|
||||||
request_id: verification::RequestId,
|
request_id: verification::RequestId,
|
||||||
|
target_id: TargetId,
|
||||||
action_id: ActionId,
|
action_id: ActionId,
|
||||||
token: VerificationToken<TcStateStarted>,
|
token: VerificationToken<TcStateStarted>,
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
@ -778,7 +931,7 @@ mod tests {
|
|||||||
panic!("request already present");
|
panic!("request already present");
|
||||||
}
|
}
|
||||||
self.handler
|
self.handler
|
||||||
.add_routed_request(request_id, action_id, token, timeout);
|
.add_routed_request(request_id, target_id, action_id, token, timeout);
|
||||||
if !self.handler.request_active(request_id.into()) {
|
if !self.handler.request_active(request_id.into()) {
|
||||||
panic!("request should be active now");
|
panic!("request should be active now");
|
||||||
}
|
}
|
||||||
@ -869,12 +1022,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_reply_handler_completion_success() {
|
fn test_reply_handler_completion_success() {
|
||||||
let mut reply_testbench = Pus8ReplyTestbench::new();
|
let mut reply_testbench = Pus8ReplyTestbench::new(true);
|
||||||
let request_id = 0x02;
|
let request_id = 0x02;
|
||||||
|
let target_id = 0x05;
|
||||||
let action_id = 0x03;
|
let action_id = 0x03;
|
||||||
let token = reply_testbench.init_handling_for_request(request_id, action_id);
|
let token = reply_testbench.init_handling_for_request(request_id, action_id);
|
||||||
reply_testbench.add_routed_request(
|
reply_testbench.add_routed_request(
|
||||||
request_id.into(),
|
request_id.into(),
|
||||||
|
target_id,
|
||||||
action_id,
|
action_id,
|
||||||
token,
|
token,
|
||||||
Duration::from_millis(1),
|
Duration::from_millis(1),
|
||||||
@ -893,12 +1048,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_reply_handler_step_success() {
|
fn test_reply_handler_step_success() {
|
||||||
let mut reply_testbench = Pus8ReplyTestbench::new();
|
let mut reply_testbench = Pus8ReplyTestbench::new(false);
|
||||||
let request_id = 0x02;
|
let request_id = 0x02;
|
||||||
|
let target_id = 0x05;
|
||||||
let action_id = 0x03;
|
let action_id = 0x03;
|
||||||
let token = reply_testbench.init_handling_for_request(request_id, action_id);
|
let token = reply_testbench.init_handling_for_request(request_id, action_id);
|
||||||
reply_testbench.add_routed_request(
|
reply_testbench.add_routed_request(
|
||||||
request_id.into(),
|
request_id.into(),
|
||||||
|
target_id,
|
||||||
action_id,
|
action_id,
|
||||||
token,
|
token,
|
||||||
Duration::from_millis(1),
|
Duration::from_millis(1),
|
||||||
@ -924,12 +1081,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_reply_handler_completion_failure() {
|
fn test_reply_handler_completion_failure() {
|
||||||
let mut reply_testbench = Pus8ReplyTestbench::new();
|
let mut reply_testbench = Pus8ReplyTestbench::new(true);
|
||||||
let request_id = 0x02;
|
let request_id = 0x02;
|
||||||
|
let target_id = 0x05;
|
||||||
let action_id = 0x03;
|
let action_id = 0x03;
|
||||||
let token = reply_testbench.init_handling_for_request(request_id, action_id);
|
let token = reply_testbench.init_handling_for_request(request_id, action_id);
|
||||||
reply_testbench.add_routed_request(
|
reply_testbench.add_routed_request(
|
||||||
request_id.into(),
|
request_id.into(),
|
||||||
|
target_id,
|
||||||
action_id,
|
action_id,
|
||||||
token,
|
token,
|
||||||
Duration::from_millis(1),
|
Duration::from_millis(1),
|
||||||
@ -956,12 +1115,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_reply_handler_step_failure() {
|
fn test_reply_handler_step_failure() {
|
||||||
let mut reply_testbench = Pus8ReplyTestbench::new();
|
let mut reply_testbench = Pus8ReplyTestbench::new(false);
|
||||||
let request_id = 0x02;
|
let request_id = 0x02;
|
||||||
|
let target_id = 0x05;
|
||||||
let action_id = 0x03;
|
let action_id = 0x03;
|
||||||
let token = reply_testbench.init_handling_for_request(request_id, action_id);
|
let token = reply_testbench.init_handling_for_request(request_id, action_id);
|
||||||
reply_testbench.add_routed_request(
|
reply_testbench.add_routed_request(
|
||||||
request_id.into(),
|
request_id.into(),
|
||||||
|
target_id,
|
||||||
action_id,
|
action_id,
|
||||||
token,
|
token,
|
||||||
Duration::from_millis(1),
|
Duration::from_millis(1),
|
||||||
@ -983,12 +1144,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_reply_handler_timeout_handling() {
|
fn test_reply_handler_timeout_handling() {
|
||||||
let mut reply_testbench = Pus8ReplyTestbench::new();
|
let mut reply_testbench = Pus8ReplyTestbench::new(true);
|
||||||
let request_id = 0x02;
|
let request_id = 0x02;
|
||||||
|
let target_id = 0x06;
|
||||||
let action_id = 0x03;
|
let action_id = 0x03;
|
||||||
let token = reply_testbench.init_handling_for_request(request_id, action_id);
|
let token = reply_testbench.init_handling_for_request(request_id, action_id);
|
||||||
reply_testbench.add_routed_request(
|
reply_testbench.add_routed_request(
|
||||||
request_id.into(),
|
request_id.into(),
|
||||||
|
target_id,
|
||||||
action_id,
|
action_id,
|
||||||
token,
|
token,
|
||||||
Duration::from_millis(1),
|
Duration::from_millis(1),
|
||||||
@ -1010,6 +1173,22 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unrequested_reply() {
|
fn test_unrequested_reply() {
|
||||||
// TODO: Implement this test.
|
let mut reply_testbench = Pus8ReplyTestbench::new(true);
|
||||||
|
let request_id = 0x02;
|
||||||
|
let action_id = 0x03;
|
||||||
|
let action_reply = ActionReplyPusWithIds {
|
||||||
|
request_id,
|
||||||
|
action_id,
|
||||||
|
reply: ActionReplyPus::Completed,
|
||||||
|
};
|
||||||
|
reply_testbench
|
||||||
|
.handle_action_reply(action_reply, &[])
|
||||||
|
.expect("reply handling failure");
|
||||||
|
let reply = reply_testbench.next_unrequested_reply();
|
||||||
|
assert!(reply.is_some());
|
||||||
|
let reply = reply.unwrap();
|
||||||
|
assert_eq!(reply.action_id, action_id);
|
||||||
|
assert_eq!(reply.request_id, request_id);
|
||||||
|
assert_eq!(reply.reply, ActionReplyPus::Completed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ use crate::pool::{StoreAddr, StoreError};
|
|||||||
use crate::pus::verification::{TcStateAccepted, TcStateToken, VerificationToken};
|
use crate::pus::verification::{TcStateAccepted, TcStateToken, VerificationToken};
|
||||||
use crate::queue::{GenericReceiveError, GenericSendError};
|
use crate::queue::{GenericReceiveError, GenericSendError};
|
||||||
use crate::request::RequestId;
|
use crate::request::RequestId;
|
||||||
use crate::ChannelId;
|
use crate::{ChannelId, TargetId};
|
||||||
use core::fmt::{Display, Formatter};
|
use core::fmt::{Display, Formatter};
|
||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
@ -288,13 +288,39 @@ pub trait ActiveRequestMapProvider<V>: Sized {
|
|||||||
fn for_each_mut<F: FnMut(&RequestId, &mut V)>(&mut self, f: F);
|
fn for_each_mut<F: FnMut(&RequestId, &mut V)>(&mut self, f: F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait ActiveRequestProvider {
|
||||||
|
fn target_id(&self) -> TargetId;
|
||||||
|
fn token(&self) -> VerificationToken<TcStateStarted>;
|
||||||
|
fn start_time(&self) -> UnixTimestamp;
|
||||||
|
fn timeout(&self) -> Duration;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ActiveRequest {
|
pub struct ActiveRequest {
|
||||||
|
target_id: TargetId,
|
||||||
token: VerificationToken<TcStateStarted>,
|
token: VerificationToken<TcStateStarted>,
|
||||||
start_time: UnixTimestamp,
|
start_time: UnixTimestamp,
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ActiveRequestProvider for ActiveRequest {
|
||||||
|
fn target_id(&self) -> TargetId {
|
||||||
|
self.target_id
|
||||||
|
}
|
||||||
|
|
||||||
|
fn token(&self) -> VerificationToken<TcStateStarted> {
|
||||||
|
self.token
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_time(&self) -> UnixTimestamp {
|
||||||
|
self.start_time
|
||||||
|
}
|
||||||
|
|
||||||
|
fn timeout(&self) -> Duration {
|
||||||
|
self.timeout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
mod alloc_mod {
|
mod alloc_mod {
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
@ -398,9 +424,15 @@ mod alloc_mod {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct DefaultActiveRequestMap<V>(pub HashMap<RequestId, V>);
|
pub struct DefaultActiveRequestMap<V>(pub HashMap<RequestId, V>);
|
||||||
|
|
||||||
|
impl<V> Default for DefaultActiveRequestMap<V> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self(HashMap::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<V> ActiveRequestMapProvider<V> for DefaultActiveRequestMap<V> {
|
impl<V> ActiveRequestMapProvider<V> for DefaultActiveRequestMap<V> {
|
||||||
fn insert(&mut self, request_id: &RequestId, request: V) {
|
fn insert(&mut self, request_id: &RequestId, request: V) {
|
||||||
self.0.insert(*request_id, request);
|
self.0.insert(*request_id, request);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user