it compiles again
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit
This commit is contained in:
parent
9903194cfc
commit
83e0a50e2a
@ -3,7 +3,7 @@ use satrs::action::{ActionRequest, ActionRequestVariant};
|
||||
use satrs::params::WritableToBeBytes;
|
||||
use satrs::pool::{SharedStaticMemoryPool, StoreAddr};
|
||||
use satrs::pus::action::{
|
||||
ActionReplyPus, ActionReplyPusWithActionId, ActionRequestWithId, ActivePusActionRequest,
|
||||
ActionReplyPus, ActionReplyPusWithActionId, ActionRequestWithId, ActivePusActionRequestStd,
|
||||
DefaultActiveActionRequestMap,
|
||||
};
|
||||
use satrs::pus::verification::{
|
||||
@ -21,7 +21,6 @@ use satrs::pus::{
|
||||
use satrs::request::{GenericMessage, TargetAndApidId};
|
||||
use satrs::spacepackets::ecss::tc::PusTcReader;
|
||||
use satrs::spacepackets::ecss::{EcssEnumU16, PusPacket};
|
||||
use satrs::spacepackets::time::UnixTimestamp;
|
||||
use satrs::tmtc::tm_helper::SharedTmPool;
|
||||
use satrs::ChannelId;
|
||||
use satrs_example::config::{tmtc_err, TcReceiverId, TmSenderId, PUS_APID};
|
||||
@ -44,13 +43,13 @@ impl Default for ActionReplyHandler {
|
||||
}
|
||||
}
|
||||
|
||||
impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for ActionReplyHandler {
|
||||
impl PusReplyHandler<ActivePusActionRequestStd, ActionReplyPusWithActionId> for ActionReplyHandler {
|
||||
type Error = EcssTmtcError;
|
||||
|
||||
fn handle_unexpected_reply(
|
||||
&mut self,
|
||||
reply: &GenericMessage<ActionReplyPusWithActionId>,
|
||||
tm_sender: &impl EcssTmSenderCore,
|
||||
_tm_sender: &impl EcssTmSenderCore,
|
||||
) {
|
||||
log::warn!("received unexpected reply for service 8: {reply:?}");
|
||||
}
|
||||
@ -58,12 +57,12 @@ impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for Act
|
||||
fn handle_reply(
|
||||
&mut self,
|
||||
reply: &satrs::request::GenericMessage<ActionReplyPusWithActionId>,
|
||||
active_request: &ActivePusActionRequest,
|
||||
active_request: &ActivePusActionRequestStd,
|
||||
verification_handler: &impl VerificationReportingProvider,
|
||||
time_stamp: &[u8],
|
||||
tm_sender: &impl EcssTmSenderCore,
|
||||
_tm_sender: &impl EcssTmSenderCore,
|
||||
) -> Result<bool, Self::Error> {
|
||||
let remove_entry = match reply.message.variant {
|
||||
let remove_entry = match &reply.message.variant {
|
||||
ActionReplyPus::CompletionFailed { error_code, params } => {
|
||||
let fail_data_len = params.write_to_be_bytes(&mut self.fail_data_buf)?;
|
||||
verification_handler
|
||||
@ -71,7 +70,7 @@ impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for Act
|
||||
active_request.token(),
|
||||
FailParams::new(
|
||||
time_stamp,
|
||||
&error_code,
|
||||
error_code,
|
||||
&self.fail_data_buf[..fail_data_len],
|
||||
),
|
||||
)
|
||||
@ -89,8 +88,8 @@ impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for Act
|
||||
active_request.token(),
|
||||
FailParamsWithStep::new(
|
||||
time_stamp,
|
||||
&EcssEnumU16::new(step),
|
||||
&error_code,
|
||||
&EcssEnumU16::new(*step),
|
||||
error_code,
|
||||
&self.fail_data_buf[..fail_data_len],
|
||||
),
|
||||
)
|
||||
@ -107,7 +106,7 @@ impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for Act
|
||||
verification_handler.step_success(
|
||||
&active_request.token(),
|
||||
time_stamp,
|
||||
EcssEnumU16::new(step),
|
||||
EcssEnumU16::new(*step),
|
||||
)?;
|
||||
false
|
||||
}
|
||||
@ -130,7 +129,7 @@ impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for Act
|
||||
#[derive(Default)]
|
||||
pub struct ExampleActionRequestConverter {}
|
||||
|
||||
impl PusTcToRequestConverter<ActivePusActionRequest, ActionRequestWithId>
|
||||
impl PusTcToRequestConverter<ActivePusActionRequestStd, ActionRequestWithId>
|
||||
for ExampleActionRequestConverter
|
||||
{
|
||||
type Error = PusPacketHandlingError;
|
||||
@ -141,7 +140,7 @@ impl PusTcToRequestConverter<ActivePusActionRequest, ActionRequestWithId>
|
||||
tc: &PusTcReader,
|
||||
time_stamp: &[u8],
|
||||
verif_reporter: &impl VerificationReportingProvider,
|
||||
) -> Result<(ActivePusActionRequest, ActionRequestWithId), Self::Error> {
|
||||
) -> Result<(ActivePusActionRequestStd, ActionRequestWithId), Self::Error> {
|
||||
let subservice = tc.subservice();
|
||||
let user_data = tc.user_data();
|
||||
if user_data.len() < 8 {
|
||||
@ -163,11 +162,10 @@ impl PusTcToRequestConverter<ActivePusActionRequest, ActionRequestWithId>
|
||||
.start_success(token, time_stamp)
|
||||
.map_err(|e| e.0)?;
|
||||
Ok((
|
||||
ActivePusActionRequest::new(
|
||||
ActivePusActionRequestStd::new(
|
||||
action_id,
|
||||
target_id_and_apid.into(),
|
||||
token,
|
||||
UnixTimestamp::from_now().unwrap(),
|
||||
Duration::from_secs(30),
|
||||
),
|
||||
ActionRequestWithId {
|
||||
@ -309,7 +307,7 @@ pub struct Pus8Wrapper<
|
||||
ExampleActionRequestConverter,
|
||||
ActionReplyHandler,
|
||||
DefaultActiveActionRequestMap,
|
||||
ActivePusActionRequest,
|
||||
ActivePusActionRequestStd,
|
||||
ActionRequestWithId,
|
||||
ActionReplyPusWithActionId,
|
||||
>,
|
||||
|
@ -6,7 +6,7 @@ use satrs::pus::verification::{
|
||||
VerificationReporterWithVecMpscSender, VerificationReportingProvider, VerificationToken,
|
||||
};
|
||||
use satrs::pus::{
|
||||
ActivePusRequest, ActiveRequestProvider, DefaultActiveRequestMap, EcssTcAndToken,
|
||||
ActivePusRequestStd, ActiveRequestProvider, DefaultActiveRequestMap, EcssTcAndToken,
|
||||
EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTcReceiverCore,
|
||||
EcssTmSenderCore, MpscTcReceiver, PusPacketHandlerResult, PusPacketHandlingError,
|
||||
PusReplyHandler, PusServiceHelper, PusTcToRequestConverter, TmAsVecSenderWithId,
|
||||
@ -15,9 +15,8 @@ use satrs::pus::{
|
||||
use satrs::request::TargetAndApidId;
|
||||
use satrs::spacepackets::ecss::tc::PusTcReader;
|
||||
use satrs::spacepackets::ecss::{hk, PusPacket};
|
||||
use satrs::spacepackets::time::UnixTimestamp;
|
||||
use satrs::tmtc::tm_helper::SharedTmPool;
|
||||
use satrs::{ChannelId, TargetId};
|
||||
use satrs::ChannelId;
|
||||
use satrs_example::config::{hk_err, tmtc_err, TcReceiverId, TmSenderId, PUS_APID};
|
||||
use std::sync::mpsc::{self};
|
||||
use std::time::Duration;
|
||||
@ -31,25 +30,16 @@ pub enum HkReply {
|
||||
Ack,
|
||||
}
|
||||
|
||||
pub struct HkReplyHandler {
|
||||
fail_data_buf: [u8; 128],
|
||||
}
|
||||
#[derive(Default)]
|
||||
pub struct HkReplyHandler {}
|
||||
|
||||
impl Default for HkReplyHandler {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
fail_data_buf: [0; 128],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PusReplyHandler<ActivePusRequest, HkReply> for HkReplyHandler {
|
||||
impl PusReplyHandler<ActivePusRequestStd, HkReply> for HkReplyHandler {
|
||||
type Error = ();
|
||||
|
||||
fn handle_unexpected_reply(
|
||||
&mut self,
|
||||
reply: &satrs::request::GenericMessage<HkReply>,
|
||||
tm_sender: &impl EcssTmSenderCore,
|
||||
_tm_sender: &impl EcssTmSenderCore,
|
||||
) {
|
||||
log::warn!("received unexpected reply for service 3: {reply:?}");
|
||||
}
|
||||
@ -57,27 +47,35 @@ impl PusReplyHandler<ActivePusRequest, HkReply> for HkReplyHandler {
|
||||
fn handle_reply(
|
||||
&mut self,
|
||||
reply: &satrs::request::GenericMessage<HkReply>,
|
||||
active_request: &ActivePusRequest,
|
||||
active_request: &ActivePusRequestStd,
|
||||
verification_handler: &impl VerificationReportingProvider,
|
||||
time_stamp: &[u8],
|
||||
tm_sender: &impl EcssTmSenderCore,
|
||||
_tm_sender: &impl EcssTmSenderCore,
|
||||
) -> Result<bool, Self::Error> {
|
||||
let remove_entry = match reply.message {
|
||||
match reply.message {
|
||||
HkReply::Ack => {
|
||||
verification_handler
|
||||
.completion_success(active_request.token(), time_stamp)
|
||||
.expect("Sending end success TM failed");
|
||||
true
|
||||
}
|
||||
};
|
||||
Ok(remove_entry)
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ExampleHkRequestConverter {}
|
||||
pub struct ExampleHkRequestConverter {
|
||||
timeout: Duration,
|
||||
}
|
||||
|
||||
impl PusTcToRequestConverter<ActivePusRequest, HkRequest> for ExampleHkRequestConverter {
|
||||
impl Default for ExampleHkRequestConverter {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
timeout: Duration::from_secs(60),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for ExampleHkRequestConverter {
|
||||
type Error = PusPacketHandlingError;
|
||||
|
||||
fn convert(
|
||||
@ -86,7 +84,7 @@ impl PusTcToRequestConverter<ActivePusRequest, HkRequest> for ExampleHkRequestCo
|
||||
tc: &PusTcReader,
|
||||
time_stamp: &[u8],
|
||||
verif_reporter: &impl VerificationReportingProvider,
|
||||
) -> Result<(ActivePusRequest, HkRequest), Self::Error> {
|
||||
) -> Result<(ActivePusRequestStd, HkRequest), Self::Error> {
|
||||
let user_data = tc.user_data();
|
||||
if user_data.is_empty() {
|
||||
let user_data_len = user_data.len() as u32;
|
||||
@ -188,13 +186,7 @@ impl PusTcToRequestConverter<ActivePusRequest, HkRequest> for ExampleHkRequestCo
|
||||
.start_success(token, time_stamp)
|
||||
.map_err(|e| e.0)?;
|
||||
Ok((
|
||||
ActivePusRequest::new(
|
||||
target_id_and_apid.into(),
|
||||
token,
|
||||
UnixTimestamp::from_now().unwrap(),
|
||||
Duration::from_secs(60),
|
||||
)
|
||||
.into(),
|
||||
ActivePusRequestStd::new(target_id_and_apid.into(), token, self.timeout),
|
||||
request,
|
||||
))
|
||||
}
|
||||
@ -284,8 +276,8 @@ pub struct Pus3Wrapper<
|
||||
VerificationReporter,
|
||||
ExampleHkRequestConverter,
|
||||
HkReplyHandler,
|
||||
DefaultActiveRequestMap<ActivePusRequest>,
|
||||
ActivePusRequest,
|
||||
DefaultActiveRequestMap<ActivePusRequestStd>,
|
||||
ActivePusRequestStd,
|
||||
HkRequest,
|
||||
HkReply,
|
||||
>,
|
||||
|
@ -4,8 +4,9 @@ use log::warn;
|
||||
use satrs::pus::verification::{self, FailParams, VerificationReportingProvider};
|
||||
use satrs::pus::{
|
||||
ActiveRequestMapProvider, ActiveRequestProvider, EcssTcAndToken, EcssTcInMemConverter,
|
||||
EcssTcReceiverCore, EcssTmSenderCore, PusPacketHandlerResult, PusPacketHandlingError,
|
||||
PusReplyHandler, PusRequestRouter, PusServiceHelper, PusTcToRequestConverter, TcInMemory,
|
||||
EcssTcReceiverCore, EcssTmSenderCore, GenericRoutingError, PusPacketHandlerResult,
|
||||
PusPacketHandlingError, PusReplyHandler, PusRequestRouter, PusServiceHelper,
|
||||
PusTcToRequestConverter, TcInMemory,
|
||||
};
|
||||
use satrs::request::GenericMessage;
|
||||
use satrs::spacepackets::ecss::tc::PusTcReader;
|
||||
@ -120,6 +121,8 @@ impl<
|
||||
RequestType,
|
||||
ReplyType,
|
||||
>
|
||||
where
|
||||
GenericRequestRouter: PusRequestRouter<RequestType, Error = GenericRoutingError>,
|
||||
{
|
||||
pub fn new(
|
||||
service_helper: PusServiceHelper<
|
||||
@ -156,27 +159,26 @@ impl<
|
||||
.service_helper
|
||||
.tc_in_mem_converter
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?;
|
||||
let mut partial_error = None;
|
||||
let (active_request, action_request) = self.request_converter.convert(
|
||||
let (request_info, request) = self.request_converter.convert(
|
||||
ecss_tc_and_token.token,
|
||||
&tc,
|
||||
&time_stamp,
|
||||
time_stamp,
|
||||
&self.service_helper.common.verification_handler,
|
||||
)?;
|
||||
if let Err(e) = self.request_router.route(
|
||||
active_request.target_id(),
|
||||
action_request,
|
||||
ecss_tc_and_token.token,
|
||||
) {
|
||||
let verif_request_id = verification::RequestId::new(&tc);
|
||||
let verif_request_id = verification::RequestId::new(&tc);
|
||||
if let Err(e) =
|
||||
self.request_router
|
||||
.route(request_info.target_id(), request, ecss_tc_and_token.token)
|
||||
{
|
||||
let target_id = request_info.target_id();
|
||||
self.active_request_map
|
||||
.insert(verif_request_id.into(), active_request);
|
||||
.insert(&verif_request_id.into(), request_info);
|
||||
self.request_router.handle_error(
|
||||
active_request.target_id(),
|
||||
target_id,
|
||||
ecss_tc_and_token.token,
|
||||
&tc,
|
||||
e.clone(),
|
||||
&time_stamp,
|
||||
time_stamp,
|
||||
&self.service_helper.common.verification_handler,
|
||||
);
|
||||
return Err(e.into());
|
||||
@ -184,9 +186,7 @@ impl<
|
||||
Ok(PusPacketHandlerResult::RequestHandled)
|
||||
}
|
||||
|
||||
pub fn insert_reply(&mut self, reply: &GenericMessage<ReplyType>) {
|
||||
// self.reply_hook.insert_reply(reply, &self.active_request_map);
|
||||
}
|
||||
pub fn insert_reply(&mut self, reply: &GenericMessage<ReplyType>) {}
|
||||
}
|
||||
|
||||
impl<VerificationReporter: VerificationReportingProvider> PusReceiver<VerificationReporter> {
|
||||
|
@ -68,8 +68,8 @@ impl<
|
||||
is_srv_finished(self.test_srv.handle_next_packet(&time_stamp));
|
||||
is_srv_finished(self.schedule_srv.handle_next_packet(&time_stamp));
|
||||
is_srv_finished(self.event_srv.handle_next_packet(&time_stamp));
|
||||
is_srv_finished(self.action_srv.handle_next_packet());
|
||||
is_srv_finished(self.hk_srv.handle_next_packet());
|
||||
is_srv_finished(self.action_srv.handle_next_packet(&time_stamp));
|
||||
is_srv_finished(self.hk_srv.handle_next_packet(&time_stamp));
|
||||
if all_queues_empty {
|
||||
break;
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ use std::sync::mpsc;
|
||||
|
||||
use derive_new::new;
|
||||
use log::warn;
|
||||
use satrs::action::ActionRequest;
|
||||
use satrs::hk::HkRequest;
|
||||
use satrs::mode::ModeRequest;
|
||||
use satrs::pus::action::ActionRequestWithId;
|
||||
use satrs::pus::verification::{
|
||||
FailParams, TcStateAccepted, VerificationReportingProvider, VerificationToken,
|
||||
};
|
||||
@ -17,21 +17,21 @@ use satrs::TargetId;
|
||||
use satrs_example::config::tmtc_err;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[non_exhaustive]
|
||||
pub enum Request {
|
||||
Hk(HkRequest),
|
||||
Mode(ModeRequest),
|
||||
Action(ActionRequest),
|
||||
Action(ActionRequestWithId),
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Debug, new)]
|
||||
#[derive(Clone, Debug, new)]
|
||||
pub struct TargetedRequest {
|
||||
pub(crate) target_id: TargetId,
|
||||
pub(crate) request: Request,
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RequestWithToken {
|
||||
pub(crate) targeted_request: TargetedRequest,
|
||||
pub(crate) token: VerificationToken<TcStateAccepted>,
|
||||
@ -138,13 +138,13 @@ impl PusRequestRouter<HkRequest> for GenericRequestRouter {
|
||||
}
|
||||
}
|
||||
|
||||
impl PusRequestRouter<ActionRequest> for GenericRequestRouter {
|
||||
impl PusRequestRouter<ActionRequestWithId> for GenericRequestRouter {
|
||||
type Error = GenericRoutingError;
|
||||
|
||||
fn route(
|
||||
&self,
|
||||
target_id: TargetId,
|
||||
action_request: ActionRequest,
|
||||
action_request: ActionRequestWithId,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
) -> Result<(), Self::Error> {
|
||||
if let Some(sender) = self.0.get(&target_id) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 .
|
||||
|
@ -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.
|
||||
|
@ -1,148 +0,0 @@
|
||||
use std::sync::mpsc;
|
||||
|
||||
use satrs::{
|
||||
pus::{
|
||||
verification::{
|
||||
TcStateAccepted, VerificationReporterCfg, VerificationReporterWithVecMpscSender,
|
||||
VerificationReportingProvider, VerificationToken,
|
||||
},
|
||||
ActivePusRequest, DefaultActiveRequestMap, EcssTcInVecConverter, PusRequestRouter,
|
||||
PusServiceReplyHandler, PusTargetedRequestHandler, PusTcToRequestConverter,
|
||||
ReplyHandlerHook, TmAsVecSenderWithId,
|
||||
},
|
||||
TargetId,
|
||||
};
|
||||
use spacepackets::{
|
||||
ecss::{tc::PusTcReader, PusPacket},
|
||||
CcsdsPacket,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
pub enum DummyRequest {
|
||||
Ping,
|
||||
WithParam(u32),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
pub enum DummyReply {
|
||||
Pong,
|
||||
}
|
||||
|
||||
pub struct DummyRequestConverter {}
|
||||
|
||||
impl PusTcToRequestConverter<DummyRequest> for DummyRequestRouter {
|
||||
type Error = ();
|
||||
|
||||
fn convert(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
tc: &PusTcReader,
|
||||
time_stamp: &[u8],
|
||||
verif_reporter: &impl VerificationReportingProvider,
|
||||
) -> Result<(TargetId, DummyRequest), Self::Error> {
|
||||
if tc.service() == 205 && tc.subservice() == 1 {
|
||||
return Ok((tc.apid().into(), DummyRequest::Ping));
|
||||
}
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DummyRequestRouter {
|
||||
dummy_1_sender: mpsc::Sender<DummyRequest>,
|
||||
dummy_2_sender: mpsc::Sender<DummyRequest>,
|
||||
}
|
||||
|
||||
impl PusRequestRouter<DummyRequest> for DummyRequestRouter {
|
||||
type Error = ();
|
||||
fn route(
|
||||
&self,
|
||||
target_id: TargetId,
|
||||
request: DummyRequest,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
) -> Result<(), Self::Error> {
|
||||
if target_id == DummyTargetId::Object1 as u64 {
|
||||
self.dummy_1_sender.send(request).ok();
|
||||
} else {
|
||||
self.dummy_2_sender.send(request).ok();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_error(
|
||||
&self,
|
||||
target_id: TargetId,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
tc: &PusTcReader,
|
||||
error: Self::Error,
|
||||
time_stamp: &[u8],
|
||||
verif_reporter: &impl VerificationReportingProvider,
|
||||
) {
|
||||
panic!("routing error");
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DummyReplyUserHook {}
|
||||
|
||||
impl ReplyHandlerHook<ActivePusRequest, DummyReply> for DummyReplyUserHook {
|
||||
fn handle_unexpected_reply(&mut self, reply: &satrs::request::GenericMessage<DummyReply>) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn timeout_callback(&self, active_request: &ActivePusRequest) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn timeout_error_code(&self) -> satrs_shared::res_code::ResultU16 {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub type PusDummyRequestHandler = PusTargetedRequestHandler<
|
||||
mpsc::Sender<Vec<u8>>,
|
||||
mpsc::Sender<Vec<u8>>,
|
||||
EcssTcInVecConverter,
|
||||
VerificationReporterWithVecMpscSender,
|
||||
DummyRequestConverter,
|
||||
DummyRequestRouter,
|
||||
DummyRequest,
|
||||
>;
|
||||
pub type PusDummyReplyHandler = PusServiceReplyHandler<
|
||||
VerificationReporterWithVecMpscSender,
|
||||
DefaultActiveRequestMap<ActivePusRequest>,
|
||||
DummyReplyUserHook,
|
||||
mpsc::Sender<Vec<u8>>,
|
||||
ActivePusRequest,
|
||||
DummyReply,
|
||||
>;
|
||||
const TEST_APID: u16 = 5;
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
pub enum DummyTargetId {
|
||||
Object1 = 1,
|
||||
Object2 = 2,
|
||||
}
|
||||
|
||||
pub enum DummyChannelId {
|
||||
Router = 1,
|
||||
Object1 = 2,
|
||||
Object2 = 3,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let reporter_cfg = VerificationReporterCfg::new(TEST_APID, 2, 2, 256).unwrap();
|
||||
let (tm_sender, tm_receiver) = mpsc::channel();
|
||||
let tm_sender_with_wrapper =
|
||||
TmAsVecSenderWithId::new(DummyChannelId::Router as u32, "ROUTER", tm_sender.clone());
|
||||
let verification_handler =
|
||||
VerificationReporterWithVecMpscSender::new(&reporter_cfg, tm_sender_with_wrapper);
|
||||
|
||||
// let dummy_request_handler = PusDummyRequestHandler::new()
|
||||
let dummy_reply_handler = PusDummyReplyHandler::new_from_now(
|
||||
verification_handler,
|
||||
DefaultActiveRequestMap::default(),
|
||||
256,
|
||||
DummyReplyUserHook::default(),
|
||||
tm_sender.clone(),
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user