continue fixing old code

This commit is contained in:
Robin Müller 2024-03-20 10:45:30 +01:00
parent 0f2a700ef1
commit 9903194cfc
6 changed files with 313 additions and 137 deletions

View File

@ -1,54 +1,119 @@
use log::{error, warn};
use satrs::action::{ActionRequest, ActionRequestVariant};
use satrs::params::WritableToBeBytes;
use satrs::pool::{SharedStaticMemoryPool, StoreAddr};
use satrs::pus::action::{
ActionReplyPus, ActionReplyPusWithActionId, ActiveActionRequest, DefaultActiveActionRequestMap,
PusService8ReplyHandler,
ActionReplyPus, ActionReplyPusWithActionId, ActionRequestWithId, ActivePusActionRequest,
DefaultActiveActionRequestMap,
};
use satrs::pus::verification::{
FailParams, TcStateAccepted, VerificationReporterWithSharedPoolMpscBoundedSender,
VerificationReporterWithVecMpscSender, VerificationReportingProvider, VerificationToken,
self, FailParams, FailParamsWithStep, TcStateAccepted,
VerificationReporterWithSharedPoolMpscBoundedSender, VerificationReporterWithVecMpscSender,
VerificationReportingProvider, VerificationToken,
};
use satrs::pus::{
EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter,
EcssTcReceiverCore, EcssTmSenderCore, MpscTcReceiver, PusPacketHandlerResult,
PusPacketHandlingError, PusReplyHandler, PusServiceHelper, PusTcToRequestConverter,
ReplyHandlerHook, TmAsVecSenderWithId, TmAsVecSenderWithMpsc,
ActiveRequestProvider, EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter,
EcssTcInVecConverter, EcssTcReceiverCore, EcssTmSenderCore, EcssTmtcError, MpscTcReceiver,
PusPacketHandlerResult, PusPacketHandlingError, PusReplyHandler, PusServiceHelper,
PusTcToRequestConverter, TmAsVecSenderWithId, TmAsVecSenderWithMpsc,
TmInSharedPoolSenderWithBoundedMpsc, TmInSharedPoolSenderWithId,
};
use satrs::request::TargetAndApidId;
use satrs::request::{GenericMessage, TargetAndApidId};
use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::PusPacket;
use satrs::spacepackets::ecss::{EcssEnumU16, PusPacket};
use satrs::spacepackets::time::UnixTimestamp;
use satrs::tmtc::tm_helper::SharedTmPool;
use satrs::{ChannelId, TargetId};
use satrs_example::config::tmtc_err::REQUEST_TIMEOUT;
use satrs::ChannelId;
use satrs_example::config::{tmtc_err, TcReceiverId, TmSenderId, PUS_APID};
use std::sync::mpsc::{self};
use std::time::Duration;
use crate::requests::GenericRequestRouter;
use super::PusTargetedRequestService;
#[derive(Default)]
pub struct ActionReplyHandler {}
pub struct ActionReplyHandler {
fail_data_buf: [u8; 128],
}
impl PusReplyHandler<ActiveActionRequest, ActionReplyPusWithActionId> for ActionReplyHandler {
type Error = ();
impl Default for ActionReplyHandler {
fn default() -> Self {
Self {
fail_data_buf: [0; 128],
}
}
}
impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for ActionReplyHandler {
type Error = EcssTmtcError;
fn handle_unexpected_reply(
&mut self,
reply: &satrs::request::GenericMessage<ActionReplyPusWithActionId>,
reply: &GenericMessage<ActionReplyPusWithActionId>,
tm_sender: &impl EcssTmSenderCore,
) {
log::warn!("received unexpected reply for service {SERVICE}: {reply}");
log::warn!("received unexpected reply for service 8: {reply:?}");
}
fn handle_reply(
&mut self,
reply: &satrs::request::GenericMessage<ActionReplyPusWithActionId>,
active_request: &ActivePusActionRequest,
verification_handler: &impl VerificationReportingProvider,
time_stamp: &[u8],
tm_sender: &impl EcssTmSenderCore,
) -> Result<bool, Self::Error> {
todo!()
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
.completion_failure(
active_request.token(),
FailParams::new(
time_stamp,
&error_code,
&self.fail_data_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.fail_data_buf)?;
verification_handler
.step_failure(
active_request.token(),
FailParamsWithStep::new(
time_stamp,
&EcssEnumU16::new(step),
&error_code,
&self.fail_data_buf[..fail_data_len],
),
)
.map_err(|e| e.0)?;
true
}
ActionReplyPus::Completed => {
verification_handler
.completion_success(active_request.token(), time_stamp)
.map_err(|e| e.0)?;
true
}
ActionReplyPus::StepSuccess { step } => {
verification_handler.step_success(
&active_request.token(),
time_stamp,
EcssEnumU16::new(step),
)?;
false
}
_ => false,
};
Ok(remove_entry)
}
/*
@ -65,7 +130,9 @@ impl PusReplyHandler<ActiveActionRequest, ActionReplyPusWithActionId> for Action
#[derive(Default)]
pub struct ExampleActionRequestConverter {}
impl PusTcToRequestConverter<ActionRequest> for ExampleActionRequestConverter {
impl PusTcToRequestConverter<ActivePusActionRequest, ActionRequestWithId>
for ExampleActionRequestConverter
{
type Error = PusPacketHandlingError;
fn convert(
@ -74,7 +141,7 @@ impl PusTcToRequestConverter<ActionRequest> for ExampleActionRequestConverter {
tc: &PusTcReader,
time_stamp: &[u8],
verif_reporter: &impl VerificationReportingProvider,
) -> Result<(TargetId, ActionRequest), Self::Error> {
) -> Result<(ActivePusActionRequest, ActionRequestWithId), Self::Error> {
let subservice = tc.subservice();
let user_data = tc.user_data();
if user_data.len() < 8 {
@ -89,15 +156,27 @@ impl PusTcToRequestConverter<ActionRequest> for ExampleActionRequestConverter {
found: user_data.len(),
});
}
let target_id = TargetAndApidId::from_pus_tc(tc).unwrap();
let target_id_and_apid = TargetAndApidId::from_pus_tc(tc).unwrap();
let action_id = u32::from_be_bytes(user_data[4..8].try_into().unwrap());
if subservice == 128 {
let token = verif_reporter
.start_success(token, time_stamp)
.map_err(|e| e.0)?;
Ok((
target_id.raw(),
ActionRequest::new(
ActivePusActionRequest::new(
action_id,
ActionRequestVariant::VecData(user_data[8..].to_vec()),
target_id_and_apid.into(),
token,
UnixTimestamp::from_now().unwrap(),
Duration::from_secs(30),
),
ActionRequestWithId {
request_id: verification::RequestId::new(tc).into(),
request: ActionRequest::new(
action_id,
ActionRequestVariant::VecData(user_data[8..].to_vec()),
),
},
))
} else {
verif_reporter
@ -148,7 +227,7 @@ pub fn create_action_service_static(
// TODO: Implementation which does not use run-time allocation? Maybe something like
// a bounded wrapper which pre-allocates using [HashMap::with_capacity]..
DefaultActiveActionRequestMap::default(),
ActionReplyHandler::<8>::default(),
ActionReplyHandler::default(),
);
Pus8Wrapper {
action_request_handler,
@ -187,17 +266,18 @@ pub fn create_action_service_dynamic(
ExampleActionRequestConverter::default(),
action_router,
DefaultActiveActionRequestMap::default(),
ActionReplyHandler::<8>::default(),
ActionReplyHandler::default(),
);
Pus8Wrapper {
action_request_handler,
}
}
/*
#[derive(Default)]
pub struct PusActionReplyHook {}
impl ReplyHandlerHook<ActiveActionRequest, ActionReplyPusWithActionId> for PusActionReplyHook {
impl ReplyHandlerHook<ActivePusActionRequest, ActionReplyPusWithActionId> for PusActionReplyHook {
fn handle_unexpected_reply(
&mut self,
reply: &satrs::request::GenericMessage<ActionReplyPusWithActionId>,
@ -205,7 +285,7 @@ impl ReplyHandlerHook<ActiveActionRequest, ActionReplyPusWithActionId> for PusAc
println!("received unexpected action reply {:?}", reply);
}
fn timeout_callback(&self, active_request: &ActiveActionRequest) {
fn timeout_callback(&self, active_request: &ActivePusActionRequest) {
println!("active request {active_request:?} timed out");
}
@ -213,6 +293,8 @@ impl ReplyHandlerHook<ActiveActionRequest, ActionReplyPusWithActionId> for PusAc
todo!()
}
}
*/
pub struct Pus8Wrapper<
TcReceiver: EcssTcReceiverCore,
TmSender: EcssTmSenderCore,
@ -225,7 +307,11 @@ pub struct Pus8Wrapper<
TcInMemConverter,
VerificationReporter,
ExampleActionRequestConverter,
ActionRequest,
ActionReplyHandler,
DefaultActiveActionRequestMap,
ActivePusActionRequest,
ActionRequestWithId,
ActionReplyPusWithActionId,
>,
}
@ -236,8 +322,8 @@ impl<
VerificationReporter: VerificationReportingProvider,
> Pus8Wrapper<TcReceiver, TmSender, TcInMemConverter, VerificationReporter>
{
pub fn handle_next_packet(&mut self) -> bool {
match self.action_request_handler.handle_one_tc() {
pub fn handle_next_packet(&mut self, time_stamp: &[u8]) -> bool {
match self.action_request_handler.handle_one_tc(time_stamp) {
Ok(result) => match result {
PusPacketHandlerResult::RequestHandled => {}
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {

View File

@ -1,31 +1,83 @@
use log::{error, warn};
use satrs::hk::{CollectionIntervalFactor, HkRequest};
use satrs::pool::{SharedStaticMemoryPool, StoreAddr};
use satrs::pus::hk::PusService3HkRequestHandler;
use satrs::pus::verification::{
FailParams, TcStateAccepted, VerificationReporterWithSharedPoolMpscBoundedSender,
VerificationReporterWithVecMpscSender, VerificationReportingProvider, VerificationToken,
};
use satrs::pus::{
EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter,
EcssTcReceiverCore, EcssTmSenderCore, MpscTcReceiver, PusPacketHandlerResult,
PusPacketHandlingError, PusServiceHelper, PusTcToRequestConverter, TmAsVecSenderWithId,
ActivePusRequest, ActiveRequestProvider, DefaultActiveRequestMap, EcssTcAndToken,
EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTcReceiverCore,
EcssTmSenderCore, MpscTcReceiver, PusPacketHandlerResult, PusPacketHandlingError,
PusReplyHandler, PusServiceHelper, PusTcToRequestConverter, TmAsVecSenderWithId,
TmAsVecSenderWithMpsc, TmInSharedPoolSenderWithBoundedMpsc, TmInSharedPoolSenderWithId,
};
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_example::config::{hk_err, tmtc_err, TcReceiverId, TmSenderId, PUS_APID};
use std::sync::mpsc::{self};
use std::time::Duration;
use crate::requests::GenericRequestRouter;
use super::PusTargetedRequestService;
#[derive(Clone, PartialEq, Debug)]
pub enum HkReply {
Ack,
}
pub struct HkReplyHandler {
fail_data_buf: [u8; 128],
}
impl Default for HkReplyHandler {
fn default() -> Self {
Self {
fail_data_buf: [0; 128],
}
}
}
impl PusReplyHandler<ActivePusRequest, HkReply> for HkReplyHandler {
type Error = ();
fn handle_unexpected_reply(
&mut self,
reply: &satrs::request::GenericMessage<HkReply>,
tm_sender: &impl EcssTmSenderCore,
) {
log::warn!("received unexpected reply for service 3: {reply:?}");
}
fn handle_reply(
&mut self,
reply: &satrs::request::GenericMessage<HkReply>,
active_request: &ActivePusRequest,
verification_handler: &impl VerificationReportingProvider,
time_stamp: &[u8],
tm_sender: &impl EcssTmSenderCore,
) -> Result<bool, Self::Error> {
let remove_entry = match reply.message {
HkReply::Ack => {
verification_handler
.completion_success(active_request.token(), time_stamp)
.expect("Sending end success TM failed");
true
}
};
Ok(remove_entry)
}
}
#[derive(Default)]
pub struct ExampleHkRequestConverter {}
impl PusTcToRequestConverter<HkRequest> for ExampleHkRequestConverter {
impl PusTcToRequestConverter<ActivePusRequest, HkRequest> for ExampleHkRequestConverter {
type Error = PusPacketHandlingError;
fn convert(
@ -34,7 +86,7 @@ impl PusTcToRequestConverter<HkRequest> for ExampleHkRequestConverter {
tc: &PusTcReader,
time_stamp: &[u8],
verif_reporter: &impl VerificationReportingProvider,
) -> Result<(TargetId, HkRequest), Self::Error> {
) -> Result<(ActivePusRequest, HkRequest), Self::Error> {
let user_data = tc.user_data();
if user_data.is_empty() {
let user_data_len = user_data.len() as u32;
@ -71,7 +123,7 @@ impl PusTcToRequestConverter<HkRequest> for ExampleHkRequestConverter {
});
}
let subservice = tc.subservice();
let target_id = TargetAndApidId::from_pus_tc(tc).expect("invalid tc format");
let target_id_and_apid = TargetAndApidId::from_pus_tc(tc).expect("invalid tc format");
let unique_id = u32::from_be_bytes(tc.user_data()[4..8].try_into().unwrap());
let standard_subservice = hk::Subservice::try_from(subservice);
@ -84,58 +136,66 @@ impl PusTcToRequestConverter<HkRequest> for ExampleHkRequestConverter {
.expect("Sending start failure TM failed");
return Err(PusPacketHandlingError::InvalidSubservice(subservice));
}
Ok((
target_id.into(),
match standard_subservice.unwrap() {
hk::Subservice::TcEnableHkGeneration | hk::Subservice::TcEnableDiagGeneration => {
HkRequest::Enable(unique_id)
}
hk::Subservice::TcDisableHkGeneration | hk::Subservice::TcDisableDiagGeneration => {
HkRequest::Disable(unique_id)
}
hk::Subservice::TcReportHkReportStructures => todo!(),
hk::Subservice::TmHkPacket => todo!(),
hk::Subservice::TcGenerateOneShotHk | hk::Subservice::TcGenerateOneShotDiag => {
HkRequest::OneShot(unique_id)
}
hk::Subservice::TcModifyDiagCollectionInterval
| hk::Subservice::TcModifyHkCollectionInterval => {
if user_data.len() < 12 {
verif_reporter
.start_failure(
token,
FailParams::new_no_fail_data(
time_stamp,
&tmtc_err::NOT_ENOUGH_APP_DATA,
),
)
.expect("Sending start failure TM failed");
return Err(PusPacketHandlingError::NotEnoughAppData {
expected: 12,
found: user_data.len(),
});
}
HkRequest::ModifyCollectionInterval(
unique_id,
CollectionIntervalFactor::from_be_bytes(
user_data[8..12].try_into().unwrap(),
),
)
}
_ => {
let request = match standard_subservice.unwrap() {
hk::Subservice::TcEnableHkGeneration | hk::Subservice::TcEnableDiagGeneration => {
HkRequest::Enable(unique_id)
}
hk::Subservice::TcDisableHkGeneration | hk::Subservice::TcDisableDiagGeneration => {
HkRequest::Disable(unique_id)
}
hk::Subservice::TcReportHkReportStructures => todo!(),
hk::Subservice::TmHkPacket => todo!(),
hk::Subservice::TcGenerateOneShotHk | hk::Subservice::TcGenerateOneShotDiag => {
HkRequest::OneShot(unique_id)
}
hk::Subservice::TcModifyDiagCollectionInterval
| hk::Subservice::TcModifyHkCollectionInterval => {
if user_data.len() < 12 {
verif_reporter
.start_failure(
token,
FailParams::new(
FailParams::new_no_fail_data(
time_stamp,
&tmtc_err::PUS_SUBSERVICE_NOT_IMPLEMENTED,
&[subservice],
&tmtc_err::NOT_ENOUGH_APP_DATA,
),
)
.expect("Sending start failure TM failed");
return Err(PusPacketHandlingError::InvalidSubservice(subservice));
return Err(PusPacketHandlingError::NotEnoughAppData {
expected: 12,
found: user_data.len(),
});
}
},
HkRequest::ModifyCollectionInterval(
unique_id,
CollectionIntervalFactor::from_be_bytes(user_data[8..12].try_into().unwrap()),
)
}
_ => {
verif_reporter
.start_failure(
token,
FailParams::new(
time_stamp,
&tmtc_err::PUS_SUBSERVICE_NOT_IMPLEMENTED,
&[subservice],
),
)
.expect("Sending start failure TM failed");
return Err(PusPacketHandlingError::InvalidSubservice(subservice));
}
};
let token = verif_reporter
.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(),
request,
))
}
}
@ -161,7 +221,7 @@ pub fn create_hk_service_static(
);
let hk_srv_receiver =
MpscTcReceiver::new(TcReceiverId::PusHk as ChannelId, "PUS_8_TC_RECV", pus_hk_rx);
let pus_3_handler = PusService3HkRequestHandler::new(
let pus_3_handler = PusTargetedRequestService::new(
PusServiceHelper::new(
hk_srv_receiver,
hk_srv_tm_sender,
@ -171,6 +231,8 @@ pub fn create_hk_service_static(
),
ExampleHkRequestConverter::default(),
request_router,
DefaultActiveRequestMap::default(),
HkReplyHandler::default(),
);
Pus3Wrapper { pus_3_handler }
}
@ -193,7 +255,7 @@ pub fn create_hk_service_dynamic(
);
let hk_srv_receiver =
MpscTcReceiver::new(TcReceiverId::PusHk as ChannelId, "PUS_8_TC_RECV", pus_hk_rx);
let pus_3_handler = PusService3HkRequestHandler::new(
let pus_3_handler = PusTargetedRequestService::new(
PusServiceHelper::new(
hk_srv_receiver,
hk_srv_tm_sender,
@ -203,6 +265,8 @@ pub fn create_hk_service_dynamic(
),
ExampleHkRequestConverter::default(),
request_router,
DefaultActiveRequestMap::default(),
HkReplyHandler::default(),
);
Pus3Wrapper { pus_3_handler }
}
@ -213,13 +277,17 @@ pub struct Pus3Wrapper<
TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
> {
pub(crate) pus_3_handler: PusService3HkRequestHandler<
pub(crate) pus_3_handler: PusTargetedRequestService<
TcReceiver,
TmSender,
TcInMemConverter,
VerificationReporter,
ExampleHkRequestConverter,
GenericRequestRouter,
HkReplyHandler,
DefaultActiveRequestMap<ActivePusRequest>,
ActivePusRequest,
HkRequest,
HkReply,
>,
}
@ -230,8 +298,8 @@ impl<
VerificationReporter: VerificationReportingProvider,
> Pus3Wrapper<TcReceiver, TmSender, TcInMemConverter, VerificationReporter>
{
pub fn handle_next_packet(&mut self) -> bool {
match self.pus_3_handler.handle_one_tc() {
pub fn handle_next_packet(&mut self, time_stamp: &[u8]) -> bool {
match self.pus_3_handler.handle_one_tc(time_stamp) {
Ok(result) => match result {
PusPacketHandlerResult::RequestHandled => {}
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {

View File

@ -1,16 +1,11 @@
use crate::requests::GenericRequestRouter;
use crate::tmtc::MpscStoreAndSendError;
use log::warn;
use satrs::pus::verification::{
self, FailParams, VerificationReporter, VerificationReporterWithSharedPoolMpscBoundedSender,
VerificationReporterWithVecMpscSender, VerificationReportingProvider,
};
use satrs::pus::verification::{self, FailParams, VerificationReportingProvider};
use satrs::pus::{
ActiveRequestMapProvider, ActiveRequestProvider, DefaultActiveRequestMap, EcssTcAndToken,
EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTcReceiverCore,
EcssTmSenderCore, GenericRoutingError, MpscTcReceiver, PusPacketHandlerResult, PusReplyHandler,
PusServiceHelper, PusServiceReplyHandler, PusTcToRequestConverter, ReplyHandlerHook,
TcInMemory, TmAsVecSenderWithMpsc, TmInSharedPoolSenderWithBoundedMpsc,
ActiveRequestMapProvider, ActiveRequestProvider, EcssTcAndToken, EcssTcInMemConverter,
EcssTcReceiverCore, EcssTmSenderCore, PusPacketHandlerResult, PusPacketHandlingError,
PusReplyHandler, PusRequestRouter, PusServiceHelper, PusTcToRequestConverter, TcInMemory,
};
use satrs::request::GenericMessage;
use satrs::spacepackets::ecss::tc::PusTcReader;
@ -85,10 +80,10 @@ pub struct PusTargetedRequestService<
TmSender: EcssTmSenderCore,
TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
RequestConverter: PusTcToRequestConverter<RequestType>,
ReplyHook: ReplyHandlerHook<RequestType, ReplyType>,
ActiveRequestMap: ActiveRequestMapProvider<RequestType>,
ActiveRequestType: ActiveRequestProvider,
RequestConverter: PusTcToRequestConverter<ActiveRequestInfo, RequestType, Error = PusPacketHandlingError>,
ReplyHandler: PusReplyHandler<ActiveRequestInfo, ReplyType>,
ActiveRequestMap: ActiveRequestMapProvider<ActiveRequestInfo>,
ActiveRequestInfo: ActiveRequestProvider,
RequestType,
ReplyType,
> {
@ -97,8 +92,8 @@ pub struct PusTargetedRequestService<
pub request_router: GenericRequestRouter,
pub request_converter: RequestConverter,
pub active_request_map: ActiveRequestMap,
pub reply_hook: ReplyHook,
phantom: std::marker::PhantomData<RequestType>,
pub reply_hook: ReplyHandler,
phantom: std::marker::PhantomData<(RequestType, ActiveRequestInfo, ReplyType)>,
}
impl<
@ -106,10 +101,10 @@ impl<
TmSender: EcssTmSenderCore,
TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
RequestConverter: PusTcToRequestConverter<RequestType>,
ReplyHandler: PusReplyHandler<ActiveRequestType, ReplyType>,
ActiveRequestMap: ActiveRequestMapProvider<ActiveRequestType>,
ActiveRequestType: ActiveRequestProvider,
RequestConverter: PusTcToRequestConverter<ActiveRequestInfo, RequestType, Error = PusPacketHandlingError>,
ReplyHandler: PusReplyHandler<ActiveRequestInfo, ReplyType>,
ActiveRequestMap: ActiveRequestMapProvider<ActiveRequestInfo>,
ActiveRequestInfo: ActiveRequestProvider,
RequestType,
ReplyType,
>
@ -121,7 +116,7 @@ impl<
RequestConverter,
ReplyHandler,
ActiveRequestMap,
ActiveRequestType,
ActiveRequestInfo,
RequestType,
ReplyType,
>
@ -148,7 +143,10 @@ impl<
}
}
pub fn handle_one_tc(&mut self) {
pub fn handle_one_tc(
&mut self,
time_stamp: &[u8],
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
let possible_packet = self.service_helper.retrieve_and_accept_next_packet()?;
if possible_packet.is_none() {
return Ok(PusPacketHandlerResult::Empty);
@ -159,7 +157,6 @@ impl<
.tc_in_mem_converter
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?;
let mut partial_error = None;
let time_stamp = get_current_cds_short_timestamp(&mut partial_error);
let (active_request, action_request) = self.request_converter.convert(
ecss_tc_and_token.token,
&tc,
@ -175,7 +172,7 @@ impl<
self.active_request_map
.insert(verif_request_id.into(), active_request);
self.request_router.handle_error(
target_id,
active_request.target_id(),
ecss_tc_and_token.token,
&tc,
e.clone(),

View File

@ -5,7 +5,7 @@ use crate::{
ChannelId, TargetId,
};
use super::{verification::VerificationToken, ActiveRequest, ActiveRequestProvider};
use super::{verification::VerificationToken, ActivePusRequest, ActiveRequestProvider};
use delegate::delegate;
use satrs_shared::res_code::ResultU16;
@ -75,12 +75,12 @@ impl GenericActionReplyPus {
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActiveActionRequest {
pub struct ActivePusActionRequest {
pub action_id: ActionId,
common: ActiveRequest,
common: ActivePusRequest,
}
impl ActiveRequestProvider for ActiveActionRequest {
impl ActiveRequestProvider for ActivePusActionRequest {
delegate! {
to self.common {
fn target_id(&self) -> TargetId;
@ -91,6 +91,21 @@ impl ActiveRequestProvider for ActiveActionRequest {
}
}
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 {}
@ -105,7 +120,6 @@ pub mod std_mod {
self, FailParams, FailParamsWithStep, TcStateStarted, VerificationReportingProvider,
},
ActiveRequestMapProvider, DefaultActiveRequestMap, EcssTmSenderCore, EcssTmtcError,
ReplyHandlerHook,
},
};
use core::time::Duration;
@ -114,7 +128,7 @@ pub mod std_mod {
use super::*;
pub type DefaultActiveActionRequestMap = DefaultActiveRequestMap<ActiveActionRequest>;
pub type DefaultActiveActionRequestMap = DefaultActiveRequestMap<ActivePusActionRequest>;
/*
/// Type definition for a PUS 8 action service reply handler which constrains the
@ -317,12 +331,13 @@ mod tests {
},
EcssTcInMemConverter, EcssTcInVecConverter, EcssTmtcError, GenericRoutingError,
MpscTcReceiver, PusPacketHandlerResult, PusPacketHandlingError, PusRequestRouter,
PusServiceHelper, PusTcToRequestConverter, ReplyHandlerHook, TmAsVecSenderWithMpsc,
PusServiceHelper, PusTcToRequestConverter, TmAsVecSenderWithMpsc,
},
};
use super::*;
/*
impl<Request> PusRequestRouter<Request> for TestRouter<Request> {
type Error = GenericRoutingError;
@ -507,15 +522,15 @@ mod tests {
#[derive(Default)]
pub struct TestReplyHandlerHook {
pub unexpected_replies: VecDeque<GenericActionReplyPus>,
pub timeouts: RefCell<VecDeque<ActiveActionRequest>>,
pub timeouts: RefCell<VecDeque<ActivePusActionRequest>>,
}
impl ReplyHandlerHook<ActiveActionRequest, ActionReplyPusWithActionId> for TestReplyHandlerHook {
impl ReplyHandlerHook<ActivePusActionRequest, ActionReplyPusWithActionId> for TestReplyHandlerHook {
fn handle_unexpected_reply(&mut self, reply: &GenericActionReplyPus) {
self.unexpected_replies.push_back(reply.clone());
}
fn timeout_callback(&self, active_request: &ActiveActionRequest) {
fn timeout_callback(&self, active_request: &ActivePusActionRequest) {
self.timeouts.borrow_mut().push_back(active_request.clone());
}
@ -870,4 +885,5 @@ mod tests {
assert_eq!(reply.request_id, request_id);
assert_eq!(reply.message.variant, ActionReplyPus::Completed);
}
*/
}

View File

@ -304,6 +304,22 @@ pub struct ActivePusRequest {
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
@ -330,7 +346,7 @@ pub trait PusRequestRouter<Request> {
fn route(
&self,
target_id: TargetId,
hk_request: Request,
request: Request,
token: VerificationToken<TcStateAccepted>,
) -> Result<(), Self::Error>;
@ -351,7 +367,9 @@ pub trait PusReplyHandler<ActiveRequestInfo: ActiveRequestProvider, ReplyType> {
fn handle_reply(
&mut self,
reply: &GenericMessage<ReplyType>,
active_request: &ActiveRequestInfo,
verification_handler: &impl VerificationReportingProvider,
time_stamp: &[u8],
tm_sender: &impl EcssTmSenderCore,
) -> Result<bool, Self::Error>;
@ -467,7 +485,7 @@ pub mod alloc_mod {
///
/// A [VerificationReportingProvider] instance is passed to the user to also allow handling
/// of the verification process as part of the PUS standard requirements.
pub trait PusTcToRequestConverter<ActiveRequestInfo, Request> {
pub trait PusTcToRequestConverter<ActiveRequestInfo: ActiveRequestProvider, Request> {
type Error;
fn convert(
&mut self,

View File

@ -42,26 +42,16 @@ pub mod std_mod {
SpHeader,
};
use crate::{
mode::GenericModeReply,
pus::{
mode::Subservice,
verification::{
self, FailParams, TcStateStarted, VerificationReportingProvider, VerificationToken,
},
ActivePusRequest, ActiveRequestMapProvider, EcssTmSenderCore, EcssTmtcError,
PusServiceReplyHandler, PusTmWrapper, ReplyHandlerHook,
},
TargetId,
};
/*
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.
@ -180,6 +170,7 @@ pub mod std_mod {
Ok(())
}
}
*/
}
#[cfg(test)]