it compiles again
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
2024-03-20 13:51:55 +01:00
parent 9903194cfc
commit 83e0a50e2a
9 changed files with 142 additions and 491 deletions

View File

@ -5,11 +5,10 @@ use crate::{
ChannelId, TargetId,
};
use super::{verification::VerificationToken, ActivePusRequest, ActiveRequestProvider};
use super::{verification::VerificationToken, ActivePusRequestStd, ActiveRequestProvider};
use delegate::delegate;
use satrs_shared::res_code::ResultU16;
use spacepackets::ecss::EcssEnumU16;
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
@ -74,38 +73,6 @@ impl GenericActionReplyPus {
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActivePusActionRequest {
pub action_id: ActionId,
common: ActivePusRequest,
}
impl ActiveRequestProvider for ActivePusActionRequest {
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;
}
}
}
impl ActivePusActionRequest {
pub fn new(
action_id: ActionId,
target_id: TargetId,
token: VerificationToken<super::verification::TcStateStarted>,
start_time: spacepackets::time::UnixTimestamp,
timeout: core::time::Duration,
) -> Self {
Self {
action_id,
common: ActivePusRequest::new(target_id, token, start_time, timeout),
}
}
}
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub mod alloc_mod {}
@ -113,192 +80,46 @@ pub mod alloc_mod {}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub mod std_mod {
use crate::{
params::WritableToBeBytes,
pus::{
verification::{
self, FailParams, FailParamsWithStep, TcStateStarted, VerificationReportingProvider,
},
ActiveRequestMapProvider, DefaultActiveRequestMap, EcssTmSenderCore, EcssTmtcError,
},
};
use core::time::Duration;
use spacepackets::time::UnixTimestamp;
use std::time::SystemTimeError;
use crate::pus::{verification, DefaultActiveRequestMap};
use super::*;
pub type DefaultActiveActionRequestMap = DefaultActiveRequestMap<ActivePusActionRequest>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActivePusActionRequestStd {
pub action_id: ActionId,
common: ActivePusRequestStd,
}
/*
/// Type definition for a PUS 8 action service reply handler which constrains the
/// [PusServiceReplyHandler] active request and reply generics to the [ActiveActionRequest] and
/// [ActionReplyPusWithIds] type.
pub type PusService8ReplyHandler<VerificationReporter, ActiveRequestMap, UserHook, TmSender> =
PusServiceReplyHandler<
VerificationReporter,
ActiveRequestMap,
UserHook,
TmSender,
ActiveActionRequest,
ActionReplyPusWithActionId,
>;
impl ActiveRequestProvider for ActivePusActionRequestStd {
delegate! {
to self.common {
fn target_id(&self) -> TargetId;
fn token(&self) -> VerificationToken<verification::TcStateStarted>;
fn has_timed_out(&self) -> bool;
fn timeout(&self) -> core::time::Duration;
}
}
}
impl<
VerificationReporter: VerificationReportingProvider,
ActiveRequestMap: ActiveRequestMapProvider<ActiveActionRequest>,
UserHook: ReplyHandlerHook<ActiveActionRequest, ActionReplyPusWithActionId>,
TmSender: EcssTmSenderCore,
> PusService8ReplyHandler<VerificationReporter, ActiveRequestMap, UserHook, TmSender>
{
/// Helper method to register a recently routed action request.
pub fn add_routed_action_request(
&mut self,
request_id: verification::RequestId,
target_id: TargetId,
impl ActivePusActionRequestStd {
pub fn new(
action_id: ActionId,
token: VerificationToken<TcStateStarted>,
timeout: Duration,
) {
self.active_request_map.insert(
&request_id.into(),
ActiveActionRequest {
action_id,
common: ActiveRequest {
target_id,
token,
start_time: self.current_time,
timeout,
},
},
);
}
/// Main handler function to handle all received action replies.
pub fn handle_action_reply(
&mut self,
action_reply_with_ids: GenericMessage<ActionReplyPusWithActionId>,
time_stamp: &[u8],
) -> Result<(), EcssTmtcError> {
let active_req = self
.active_request_map
.get(action_reply_with_ids.request_id);
if active_req.is_none() {
self.user_hook
.handle_unexpected_reply(&action_reply_with_ids);
return Ok(());
}
let active_req = active_req.unwrap().clone();
let remove_entry = match action_reply_with_ids.message.variant {
ActionReplyPus::CompletionFailed { error_code, params } => {
let fail_data_len = params.write_to_be_bytes(&mut self.tm_buf)?;
self.verification_reporter
.completion_failure(
active_req.common.token,
FailParams::new(time_stamp, &error_code, &self.tm_buf[..fail_data_len]),
)
.map_err(|e| e.0)?;
true
}
ActionReplyPus::StepFailed {
error_code,
step,
params,
} => {
let fail_data_len = params.write_to_be_bytes(&mut self.tm_buf)?;
self.verification_reporter
.step_failure(
active_req.common.token,
FailParamsWithStep::new(
time_stamp,
&EcssEnumU16::new(step),
&error_code,
&self.tm_buf[..fail_data_len],
),
)
.map_err(|e| e.0)?;
true
}
ActionReplyPus::Completed => {
self.verification_reporter
.completion_success(active_req.common.token, time_stamp)
.map_err(|e| e.0)?;
true
}
ActionReplyPus::StepSuccess { step } => {
self.verification_reporter.step_success(
&active_req.common.token,
time_stamp,
EcssEnumU16::new(step),
)?;
false
}
};
if remove_entry {
self.active_request_map
.remove(action_reply_with_ids.request_id);
}
Ok(())
}
}
impl<
VerificationReporter: VerificationReportingProvider,
UserHook: ReplyHandlerHook<ActiveActionRequest, ActionReplyPusWithActionId>,
TmSender: EcssTmSenderCore,
>
PusService8ReplyHandler<
VerificationReporter,
DefaultActiveActionRequestMap,
UserHook,
TmSender,
>
{
/// Create a new PUS Service 8 reply handler with the [ActiveRequestMap] generic
/// constrained to the [DefaultActiveActionRequestMap] object and with the current time
/// set to the OS time.
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub fn new_from_now_with_default_map(
verification_reporter: VerificationReporter,
fail_data_buf_size: usize,
user_hook: UserHook,
tm_sender: TmSender,
) -> Result<Self, SystemTimeError> {
let current_time = UnixTimestamp::from_now()?;
Ok(Self::new_with_default_map(
verification_reporter,
fail_data_buf_size,
user_hook,
tm_sender,
current_time,
))
}
/// Create a new PUS Service 8 reply handler with the [ActiveRequestMap] generic
/// constrained to the [DefaultActiveActionRequestMap] object.
pub fn new_with_default_map(
verification_reporter: VerificationReporter,
fail_data_buf_size: usize,
user_hook: UserHook,
tm_sender: TmSender,
init_time: UnixTimestamp,
target_id: TargetId,
token: VerificationToken<verification::TcStateStarted>,
timeout: core::time::Duration,
) -> Self {
Self::new(
verification_reporter,
DefaultActiveActionRequestMap::default(),
fail_data_buf_size,
user_hook,
tm_sender,
init_time,
)
Self {
action_id,
common: ActivePusRequestStd::new(target_id, token, timeout),
}
}
}
*/
pub type DefaultActiveActionRequestMap = DefaultActiveRequestMap<ActivePusActionRequestStd>;
}
#[cfg(test)]
mod tests {
/*
use core::{cell::RefCell, time::Duration};
use std::{sync::mpsc, time::SystemTimeError};
@ -337,7 +158,6 @@ mod tests {
use super::*;
/*
impl<Request> PusRequestRouter<Request> for TestRouter<Request> {
type Error = GenericRoutingError;

View File

@ -8,14 +8,11 @@ use crate::queue::{GenericReceiveError, GenericSendError};
use crate::request::{GenericMessage, RequestId};
use crate::{ChannelId, TargetId};
use core::fmt::{Display, Formatter};
use core::marker::PhantomData;
use core::time::Duration;
#[cfg(feature = "alloc")]
use downcast_rs::{impl_downcast, Downcast};
#[cfg(feature = "alloc")]
use dyn_clone::DynClone;
use satrs_shared::res_code::ResultU16;
use spacepackets::time::UnixTimestamp;
#[cfg(feature = "std")]
use std::error::Error;
@ -277,7 +274,7 @@ pub trait ReceivesEcssPusTc {
}
pub trait ActiveRequestMapProvider<V>: Sized {
fn insert(&mut self, request_id: &RequestId, request: V);
fn insert(&mut self, request_id: &RequestId, request_info: V);
fn get(&self, request_id: RequestId) -> Option<&V>;
fn get_mut(&mut self, request_id: RequestId) -> Option<&mut V>;
fn remove(&mut self, request_id: RequestId) -> bool;
@ -292,52 +289,10 @@ pub trait ActiveRequestMapProvider<V>: Sized {
pub trait ActiveRequestProvider {
fn target_id(&self) -> TargetId;
fn token(&self) -> VerificationToken<TcStateStarted>;
fn start_time(&self) -> UnixTimestamp;
fn has_timed_out(&self) -> bool;
fn timeout(&self) -> Duration;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActivePusRequest {
target_id: TargetId,
token: VerificationToken<TcStateStarted>,
start_time: UnixTimestamp,
timeout: Duration,
}
impl ActivePusRequest {
pub fn new(
target_id: TargetId,
token: VerificationToken<TcStateStarted>,
start_time: UnixTimestamp,
timeout: Duration,
) -> Self {
Self {
target_id,
token,
start_time,
timeout,
}
}
}
impl ActiveRequestProvider for ActivePusRequest {
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
}
}
/// This trait is an abstraction for the routing of PUS request to a dedicated
/// recipient using the generic [TargetId].
pub trait PusRequestRouter<Request> {
@ -384,8 +339,6 @@ pub trait PusReplyHandler<ActiveRequestInfo: ActiveRequestProvider, ReplyType> {
pub mod alloc_mod {
use hashbrown::HashMap;
use crate::TargetId;
use super::*;
use crate::pus::verification::VerificationReportingProvider;
@ -697,6 +650,7 @@ pub mod std_mod {
use crate::tmtc::tm_helper::SharedTmPool;
use crate::{ChannelId, TargetId};
use alloc::vec::Vec;
use core::time::Duration;
use spacepackets::ecss::tc::PusTcReader;
use spacepackets::ecss::tm::PusTmCreator;
use spacepackets::ecss::{PusError, WritablePusPacket};
@ -709,8 +663,8 @@ pub mod std_mod {
#[cfg(feature = "crossbeam")]
pub use cb_mod::*;
use super::verification::VerificationReportingProvider;
use super::{AcceptedEcssTcAndToken, TcInMemory};
use super::verification::{TcStateStarted, VerificationReportingProvider};
use super::{AcceptedEcssTcAndToken, ActiveRequestProvider, TcInMemory};
impl From<mpsc::SendError<StoreAddr>> for EcssTmtcError {
fn from(_: mpsc::SendError<StoreAddr>) -> Self {
@ -1094,6 +1048,47 @@ pub mod std_mod {
}
}
*/
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActivePusRequestStd {
target_id: TargetId,
token: VerificationToken<TcStateStarted>,
start_time: std::time::Instant,
timeout: Duration,
}
impl ActivePusRequestStd {
pub fn new(
target_id: TargetId,
token: VerificationToken<TcStateStarted>,
timeout: Duration,
) -> Self {
Self {
target_id,
token,
start_time: std::time::Instant::now(),
timeout,
}
}
}
impl ActiveRequestProvider for ActivePusRequestStd {
fn target_id(&self) -> TargetId {
self.target_id
}
fn token(&self) -> VerificationToken<TcStateStarted> {
self.token
}
fn timeout(&self) -> Duration {
self.timeout
}
fn has_timed_out(&self) -> bool {
std::time::Instant::now() - self.start_time > self.timeout
}
}
// TODO: All these types could probably be no_std if we implemented error handling ourselves..
// but thiserror is really nice, so keep it like this for simplicity for now. Maybe thiserror
// will be no_std soon, see https://github.com/rust-lang/rust/issues/103765 .

View File

@ -2,13 +2,12 @@ use num_enum::{IntoPrimitive, TryFromPrimitive};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::mode::ModeReply;
#[cfg(feature = "alloc")]
#[allow(unused_imports)]
pub use alloc_mod::*;
#[cfg(feature = "std")]
#[allow(unused_imports)]
pub use std_mod::*;
pub const MODE_SERVICE_ID: u8 = 200;
@ -33,25 +32,20 @@ pub mod alloc_mod {}
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub mod std_mod {
use core::time::Duration;
use satrs_shared::res_code::ResultU16;
/*
use spacepackets::{
ecss::tm::{PusTmCreator, PusTmSecondaryHeader},
util::UnsignedEnum,
SpHeader,
};
/*
pub trait ModeReplyHook: ReplyHandlerHook<ActivePusRequest, ModeReply> {
fn wrong_mode_result_code(&self) -> ResultU16;
fn can_not_reach_mode_result_code(&self) -> ResultU16;
}
*/
use super::{ModeReply, MODE_SERVICE_ID};
/*
/// Type definition for a PUS mode servicd reply handler which constrains the
/// [PusServiceReplyHandler] active request and reply generics to the [ActiveActionRequest] and
/// [ActionReplyPusWithIds] type.