fix tests
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
Robin Müller 2024-02-16 18:51:05 +01:00
parent 3cb34cef58
commit 7092c8cd41
Signed by: muellerr
GPG Key ID: A649FB78196E3849
17 changed files with 295 additions and 126 deletions

View File

@ -1,7 +1,7 @@
use std::sync::mpsc::{self, TryRecvError}; use std::sync::mpsc::{self, TryRecvError};
use log::{info, warn}; use log::{info, warn};
use satrs::pus::verification::VerificationReporterWithSender; use satrs::pus::verification::{VerificationReporterWithSender, VerificationReportingProvider};
use satrs::pus::{EcssTmSender, PusTmWrapper}; use satrs::pus::{EcssTmSender, PusTmWrapper};
use satrs::request::TargetAndApidId; use satrs::request::TargetAndApidId;
use satrs::spacepackets::ecss::hk::Subservice as HkSubservice; use satrs::spacepackets::ecss::hk::Subservice as HkSubservice;

View File

@ -12,7 +12,7 @@ use satrs::{
DefaultPusMgmtBackendProvider, EventReporter, EventRequest, EventRequestWithToken, DefaultPusMgmtBackendProvider, EventReporter, EventRequest, EventRequestWithToken,
PusEventDispatcher, PusEventDispatcher,
}, },
verification::{TcStateStarted, VerificationReporterWithSender, VerificationToken}, verification::{TcStateStarted, VerificationReporterWithSender, VerificationToken, VerificationReportingProvider},
EcssTmSender, EcssTmSender,
}, },
spacepackets::time::cds::{self, TimeProvider}, spacepackets::time::cds::{self, TimeProvider},

View File

@ -3,7 +3,7 @@ use satrs::action::ActionRequest;
use satrs::pool::{SharedStaticMemoryPool, StoreAddr}; use satrs::pool::{SharedStaticMemoryPool, StoreAddr};
use satrs::pus::action::{PusActionToRequestConverter, PusService8ActionHandler}; use satrs::pus::action::{PusActionToRequestConverter, PusService8ActionHandler};
use satrs::pus::verification::{ use satrs::pus::verification::{
FailParams, TcStateAccepted, VerificationReporterWithSender, VerificationToken, FailParams, TcStateAccepted, VerificationReporterWithSender, VerificationToken, VerificationReportingProvider,
}; };
use satrs::pus::{ use satrs::pus::{
EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter,
@ -33,7 +33,7 @@ impl PusActionToRequestConverter for ExampleActionRequestConverter {
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
tc: &PusTcReader, tc: &PusTcReader,
time_stamp: &[u8], time_stamp: &[u8],
verif_reporter: &mut VerificationReporterWithSender, verif_reporter: &impl VerificationReportingProvider,
) -> Result<(TargetId, ActionRequest), Self::Error> { ) -> Result<(TargetId, ActionRequest), Self::Error> {
let subservice = tc.subservice(); let subservice = tc.subservice();
let user_data = tc.user_data(); let user_data = tc.user_data();
@ -138,6 +138,7 @@ pub fn create_action_service_dynamic(
pub struct Pus8Wrapper<TcInMemConverter: EcssTcInMemConverter> { pub struct Pus8Wrapper<TcInMemConverter: EcssTcInMemConverter> {
pub(crate) pus_8_handler: PusService8ActionHandler< pub(crate) pus_8_handler: PusService8ActionHandler<
TcInMemConverter, TcInMemConverter,
VerificationReporterWithSender,
ExampleActionRequestConverter, ExampleActionRequestConverter,
GenericRequestRouter, GenericRequestRouter,
GenericRoutingErrorHandler<8>, GenericRoutingErrorHandler<8>,

View File

@ -76,7 +76,7 @@ pub fn create_event_service_dynamic(
} }
pub struct Pus5Wrapper<TcInMemConverter: EcssTcInMemConverter> { pub struct Pus5Wrapper<TcInMemConverter: EcssTcInMemConverter> {
pub pus_5_handler: PusService5EventHandler<TcInMemConverter>, pub pus_5_handler: PusService5EventHandler<TcInMemConverter, VerificationReporterWithSender>,
} }
impl<TcInMemConverter: EcssTcInMemConverter> Pus5Wrapper<TcInMemConverter> { impl<TcInMemConverter: EcssTcInMemConverter> Pus5Wrapper<TcInMemConverter> {

View File

@ -3,7 +3,7 @@ use satrs::hk::{CollectionIntervalFactor, HkRequest};
use satrs::pool::{SharedStaticMemoryPool, StoreAddr}; use satrs::pool::{SharedStaticMemoryPool, StoreAddr};
use satrs::pus::hk::{PusHkToRequestConverter, PusService3HkHandler}; use satrs::pus::hk::{PusHkToRequestConverter, PusService3HkHandler};
use satrs::pus::verification::{ use satrs::pus::verification::{
FailParams, TcStateAccepted, VerificationReporterWithSender, VerificationToken, FailParams, TcStateAccepted, VerificationReporterWithSender, VerificationToken, VerificationReportingProvider,
}; };
use satrs::pus::{ use satrs::pus::{
EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter,
@ -33,7 +33,7 @@ impl PusHkToRequestConverter for ExampleHkRequestConverter {
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
tc: &PusTcReader, tc: &PusTcReader,
time_stamp: &[u8], time_stamp: &[u8],
verif_reporter: &mut VerificationReporterWithSender, verif_reporter: &impl VerificationReportingProvider,
) -> Result<(TargetId, HkRequest), Self::Error> { ) -> Result<(TargetId, HkRequest), Self::Error> {
let user_data = tc.user_data(); let user_data = tc.user_data();
if user_data.is_empty() { if user_data.is_empty() {
@ -196,6 +196,7 @@ pub fn create_hk_service_dynamic(
pub struct Pus3Wrapper<TcInMemConverter: EcssTcInMemConverter> { pub struct Pus3Wrapper<TcInMemConverter: EcssTcInMemConverter> {
pub(crate) pus_3_handler: PusService3HkHandler< pub(crate) pus_3_handler: PusService3HkHandler<
TcInMemConverter, TcInMemConverter,
VerificationReporterWithSender,
ExampleHkRequestConverter, ExampleHkRequestConverter,
GenericRequestRouter, GenericRequestRouter,
GenericRoutingErrorHandler<3>, GenericRoutingErrorHandler<3>,

View File

@ -1,6 +1,6 @@
use crate::tmtc::MpscStoreAndSendError; use crate::tmtc::MpscStoreAndSendError;
use log::warn; use log::warn;
use satrs::pus::verification::{FailParams, StdVerifReporterWithSender}; use satrs::pus::verification::{FailParams, StdVerifReporterWithSender, VerificationReportingProvider};
use satrs::pus::{ use satrs::pus::{
EcssTcAndToken, GenericRoutingError, PusPacketHandlerResult, PusRoutingErrorHandler, TcInMemory, EcssTcAndToken, GenericRoutingError, PusPacketHandlerResult, PusRoutingErrorHandler, TcInMemory,
}; };
@ -169,7 +169,7 @@ impl<const SERVICE_ID: u8> PusRoutingErrorHandler for GenericRoutingErrorHandler
_tc: &PusTcReader, _tc: &PusTcReader,
error: Self::Error, error: Self::Error,
time_stamp: &[u8], time_stamp: &[u8],
verif_reporter: &mut satrs::pus::verification::VerificationReporterWithSender, verif_reporter: &impl VerificationReportingProvider,
) { ) {
warn!("Routing request for service {SERVICE_ID} failed: {error:?}"); warn!("Routing request for service {SERVICE_ID} failed: {error:?}");
match error { match error {

View File

@ -52,7 +52,8 @@ impl TcReleaser for mpsc::Sender<Vec<u8>> {
} }
pub struct Pus11Wrapper<TcInMemConverter: EcssTcInMemConverter> { pub struct Pus11Wrapper<TcInMemConverter: EcssTcInMemConverter> {
pub pus_11_handler: PusService11SchedHandler<TcInMemConverter, PusScheduler>, pub pus_11_handler:
PusService11SchedHandler<TcInMemConverter, VerificationReporterWithSender, PusScheduler>,
pub sched_tc_pool: StaticMemoryPool, pub sched_tc_pool: StaticMemoryPool,
pub releaser_buf: [u8; 4096], pub releaser_buf: [u8; 4096],
pub tc_releaser: Box<dyn TcReleaser + Send>, pub tc_releaser: Box<dyn TcReleaser + Send>,

View File

@ -2,7 +2,7 @@ use log::{info, warn};
use satrs::params::Params; use satrs::params::Params;
use satrs::pool::{SharedStaticMemoryPool, StoreAddr}; use satrs::pool::{SharedStaticMemoryPool, StoreAddr};
use satrs::pus::test::PusService17TestHandler; use satrs::pus::test::PusService17TestHandler;
use satrs::pus::verification::{FailParams, VerificationReporterWithSender}; use satrs::pus::verification::{FailParams, VerificationReporterWithSender, VerificationReportingProvider};
use satrs::pus::{ use satrs::pus::{
EcssTcAndToken, EcssTcInMemConverter, EcssTcInVecConverter, MpscTcReceiver, MpscTmAsVecSender, EcssTcAndToken, EcssTcInMemConverter, EcssTcInVecConverter, MpscTcReceiver, MpscTmAsVecSender,
MpscTmInSharedPoolSender, PusPacketHandlerResult, PusServiceHelper, MpscTmInSharedPoolSender, PusPacketHandlerResult, PusServiceHelper,
@ -79,7 +79,7 @@ pub fn create_test_service_dynamic(
} }
pub struct Service17CustomWrapper<TcInMemConverter: EcssTcInMemConverter> { pub struct Service17CustomWrapper<TcInMemConverter: EcssTcInMemConverter> {
pub pus17_handler: PusService17TestHandler<TcInMemConverter>, pub pus17_handler: PusService17TestHandler<TcInMemConverter, VerificationReporterWithSender>,
pub test_srv_event_sender: Sender<(EventU32, Option<Params>)>, pub test_srv_event_sender: Sender<(EventU32, Option<Params>)>,
} }
@ -125,14 +125,12 @@ impl<TcInMemConverter: EcssTcInMemConverter> Service17CustomWrapper<TcInMemConve
.service_helper .service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.start_success(token, Some(&stamp_buf)) .start_success(token, Some(&stamp_buf))
.expect("Error sending start success"); .expect("Error sending start success");
self.pus17_handler self.pus17_handler
.service_helper .service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.completion_success(start_token, Some(&stamp_buf)) .completion_success(start_token, Some(&stamp_buf))
.expect("Error sending completion success"); .expect("Error sending completion success");
} else { } else {
@ -141,7 +139,6 @@ impl<TcInMemConverter: EcssTcInMemConverter> Service17CustomWrapper<TcInMemConve
.service_helper .service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.start_failure( .start_failure(
token, token,
FailParams::new( FailParams::new(

View File

@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased] # [unreleased]
# [v0.2.0]
## Added
- New PUS service abstractions for HK (PUS 3) and actions (PUS 8). Introducing new abstractions
allows to move some boilerplate code into the framework.
- New `VerificationReportingProvider` abstraction to avoid relying on a concrete verification
reporting provider.
# [v0.1.1] 2024-02-12 # [v0.1.1] 2024-02-12
- Minor fixes for crate config `homepage` entries and links in documentation. - Minor fixes for crate config `homepage` entries and links in documentation.

View File

@ -27,7 +27,7 @@ pub trait PusActionRequestRouter {
pub mod alloc_mod { pub mod alloc_mod {
use spacepackets::ecss::tc::PusTcReader; use spacepackets::ecss::tc::PusTcReader;
use crate::pus::verification::VerificationReporterWithSender; use crate::pus::verification::VerificationReportingProvider;
use super::*; use super::*;
@ -53,7 +53,7 @@ pub mod alloc_mod {
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
tc: &PusTcReader, tc: &PusTcReader,
time_stamp: &[u8], time_stamp: &[u8],
verif_reporter: &mut VerificationReporterWithSender, verif_reporter: &impl VerificationReportingProvider,
) -> Result<(TargetId, ActionRequest), Self::Error>; ) -> Result<(TargetId, ActionRequest), Self::Error>;
} }
} }
@ -62,8 +62,9 @@ pub mod alloc_mod {
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub mod std_mod { pub mod std_mod {
use crate::pus::{ use crate::pus::{
EcssTcInMemConverter, GenericRoutingError, PusPacketHandlerResult, PusPacketHandlingError, verification::VerificationReportingProvider, EcssTcInMemConverter, GenericRoutingError,
PusRoutingErrorHandler, PusServiceBase, PusServiceHelper, PusPacketHandlerResult, PusPacketHandlingError, PusRoutingErrorHandler, PusServiceBase,
PusServiceHelper,
}; };
use super::*; use super::*;
@ -81,12 +82,13 @@ pub mod std_mod {
/// 4. Handle all routing errors using the provided [PusRoutingErrorHandler]. /// 4. Handle all routing errors using the provided [PusRoutingErrorHandler].
pub struct PusService8ActionHandler< pub struct PusService8ActionHandler<
TcInMemConverter: EcssTcInMemConverter, TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
RequestConverter: PusActionToRequestConverter, RequestConverter: PusActionToRequestConverter,
RequestRouter: PusActionRequestRouter<Error=RoutingError>, RequestRouter: PusActionRequestRouter<Error = RoutingError>,
RoutingErrorHandler: PusRoutingErrorHandler<Error=RoutingError>, RoutingErrorHandler: PusRoutingErrorHandler<Error = RoutingError>,
RoutingError = GenericRoutingError RoutingError = GenericRoutingError,
> { > {
service_helper: PusServiceHelper<TcInMemConverter>, service_helper: PusServiceHelper<TcInMemConverter, VerificationReporter>,
request_converter: RequestConverter, request_converter: RequestConverter,
request_router: RequestRouter, request_router: RequestRouter,
routing_error_handler: RoutingErrorHandler, routing_error_handler: RoutingErrorHandler,
@ -94,21 +96,23 @@ pub mod std_mod {
impl< impl<
TcInMemConverter: EcssTcInMemConverter, TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
RequestConverter: PusActionToRequestConverter<Error = PusPacketHandlingError>, RequestConverter: PusActionToRequestConverter<Error = PusPacketHandlingError>,
RequestRouter: PusActionRequestRouter<Error = RoutingError>, RequestRouter: PusActionRequestRouter<Error = RoutingError>,
RoutingErrorHandler: PusRoutingErrorHandler<Error = RoutingError>, RoutingErrorHandler: PusRoutingErrorHandler<Error = RoutingError>,
RoutingError RoutingError,
> >
PusService8ActionHandler< PusService8ActionHandler<
TcInMemConverter, TcInMemConverter,
VerificationReporter,
RequestConverter, RequestConverter,
RequestRouter, RequestRouter,
RoutingErrorHandler, RoutingErrorHandler,
RoutingError RoutingError,
> >
{ {
pub fn new( pub fn new(
service_helper: PusServiceHelper<TcInMemConverter>, service_helper: PusServiceHelper<TcInMemConverter, VerificationReporter>,
request_converter: RequestConverter, request_converter: RequestConverter,
request_router: RequestRouter, request_router: RequestRouter,
routing_error_handler: RoutingErrorHandler, routing_error_handler: RoutingErrorHandler,
@ -133,12 +137,15 @@ pub mod std_mod {
.tc_in_mem_converter .tc_in_mem_converter
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?; .convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?;
let mut partial_error = None; let mut partial_error = None;
let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error); let time_stamp =
PusServiceBase::<VerificationReporter>::get_current_cds_short_timestamp(
&mut partial_error,
);
let (target_id, action_request) = self.request_converter.convert( let (target_id, action_request) = self.request_converter.convert(
ecss_tc_and_token.token, ecss_tc_and_token.token,
&tc, &tc,
&time_stamp, &time_stamp,
&mut self.service_helper.common.verification_handler.borrow_mut(), &self.service_helper.common.verification_handler,
)?; )?;
if let Err(e) = if let Err(e) =
self.request_router self.request_router
@ -150,10 +157,47 @@ pub mod std_mod {
&tc, &tc,
e, e,
&time_stamp, &time_stamp,
&mut self.service_helper.common.verification_handler.borrow_mut(), &self.service_helper.common.verification_handler,
); );
} }
Ok(PusPacketHandlerResult::RequestHandled) Ok(PusPacketHandlerResult::RequestHandled)
} }
} }
} }
#[cfg(test)]
mod tests {
use spacepackets::ecss::tc::PusTcReader;
use crate::pus::{verification::VerificationReportingProvider, GenericRoutingError};
use super::*;
pub struct TestRouter {}
impl PusActionRequestRouter for TestRouter {
type Error = GenericRoutingError;
fn route(
&self,
target_id: TargetId,
hk_request: ActionRequest,
token: VerificationToken<TcStateAccepted>,
) -> Result<(), Self::Error> {
todo!()
}
}
pub struct TestConverter {}
impl PusActionToRequestConverter for TestConverter {
type Error = GenericRoutingError;
fn convert(
&mut self,
token: VerificationToken<TcStateAccepted>,
tc: &PusTcReader,
time_stamp: &[u8],
verif_reporter: &impl VerificationReportingProvider,
) -> Result<(TargetId, ActionRequest), Self::Error> {
todo!()
}
}
}

View File

@ -6,16 +6,24 @@ use spacepackets::ecss::event::Subservice;
use spacepackets::ecss::PusPacket; use spacepackets::ecss::PusPacket;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use super::verification::VerificationReportingProvider;
use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper}; use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper};
pub struct PusService5EventHandler<TcInMemConverter: EcssTcInMemConverter> { pub struct PusService5EventHandler<
pub service_helper: PusServiceHelper<TcInMemConverter>, TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
> {
pub service_helper: PusServiceHelper<TcInMemConverter, VerificationReporter>,
event_request_tx: Sender<EventRequestWithToken>, event_request_tx: Sender<EventRequestWithToken>,
} }
impl<TcInMemConverter: EcssTcInMemConverter> PusService5EventHandler<TcInMemConverter> { impl<
TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
> PusService5EventHandler<TcInMemConverter, VerificationReporter>
{
pub fn new( pub fn new(
service_handler: PusServiceHelper<TcInMemConverter>, service_handler: PusServiceHelper<TcInMemConverter, VerificationReporter>,
event_request_tx: Sender<EventRequestWithToken>, event_request_tx: Sender<EventRequestWithToken>,
) -> Self { ) -> Self {
Self { Self {
@ -54,7 +62,6 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService5EventHandler<TcInMemConv
.service_helper .service_helper
.common .common
.verification_handler .verification_handler
.borrow_mut()
.start_success(ecss_tc_and_token.token, Some(&stamp)) .start_success(ecss_tc_and_token.token, Some(&stamp))
.map_err(|_| PartialPusHandlingError::Verification); .map_err(|_| PartialPusHandlingError::Verification);
let partial_error = start_token.clone().err(); let partial_error = start_token.clone().err();
@ -86,7 +93,9 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService5EventHandler<TcInMemConv
Ok(PusPacketHandlerResult::RequestHandled) Ok(PusPacketHandlerResult::RequestHandled)
}; };
let mut partial_error = None; let mut partial_error = None;
let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error); let time_stamp = PusServiceBase::<VerificationReporter>::get_current_cds_short_timestamp(
&mut partial_error,
);
match srv.unwrap() { match srv.unwrap() {
Subservice::TmInfoReport Subservice::TmInfoReport
| Subservice::TmLowSeverityReport | Subservice::TmLowSeverityReport
@ -128,7 +137,7 @@ mod tests {
use crate::pus::event_man::EventRequest; use crate::pus::event_man::EventRequest;
use crate::pus::tests::SimplePusPacketHandler; use crate::pus::tests::SimplePusPacketHandler;
use crate::pus::verification::RequestId; use crate::pus::verification::{RequestId, VerificationReporterWithSender};
use crate::{ use crate::{
events::EventU32, events::EventU32,
pus::{ pus::{
@ -145,7 +154,8 @@ mod tests {
struct Pus5HandlerWithStoreTester { struct Pus5HandlerWithStoreTester {
common: PusServiceHandlerWithSharedStoreCommon, common: PusServiceHandlerWithSharedStoreCommon,
handler: PusService5EventHandler<EcssTcInSharedStoreConverter>, handler:
PusService5EventHandler<EcssTcInSharedStoreConverter, VerificationReporterWithSender>,
} }
impl Pus5HandlerWithStoreTester { impl Pus5HandlerWithStoreTester {

View File

@ -29,7 +29,7 @@ pub trait PusHkRequestRouter {
pub mod alloc_mod { pub mod alloc_mod {
use spacepackets::ecss::tc::PusTcReader; use spacepackets::ecss::tc::PusTcReader;
use crate::pus::verification::VerificationReporterWithSender; use crate::pus::verification::VerificationReportingProvider;
use super::*; use super::*;
@ -55,7 +55,7 @@ pub mod alloc_mod {
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
tc: &PusTcReader, tc: &PusTcReader,
time_stamp: &[u8], time_stamp: &[u8],
verif_reporter: &mut VerificationReporterWithSender, verif_reporter: &impl VerificationReportingProvider,
) -> Result<(TargetId, HkRequest), Self::Error>; ) -> Result<(TargetId, HkRequest), Self::Error>;
} }
} }
@ -64,8 +64,9 @@ pub mod alloc_mod {
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub mod std_mod { pub mod std_mod {
use crate::pus::{ use crate::pus::{
EcssTcInMemConverter, GenericRoutingError, PusPacketHandlerResult, PusPacketHandlingError, verification::VerificationReportingProvider, EcssTcInMemConverter, GenericRoutingError,
PusRoutingErrorHandler, PusServiceBase, PusServiceHelper, PusPacketHandlerResult, PusPacketHandlingError, PusRoutingErrorHandler, PusServiceBase,
PusServiceHelper,
}; };
use super::*; use super::*;
@ -85,12 +86,13 @@ pub mod std_mod {
/// type is constrained to the [GenericRoutingError] for the concrete implementation. /// type is constrained to the [GenericRoutingError] for the concrete implementation.
pub struct PusService3HkHandler< pub struct PusService3HkHandler<
TcInMemConverter: EcssTcInMemConverter, TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
RequestConverter: PusHkToRequestConverter, RequestConverter: PusHkToRequestConverter,
RequestRouter: PusHkRequestRouter<Error=RoutingError>, RequestRouter: PusHkRequestRouter<Error = RoutingError>,
RoutingErrorHandler: PusRoutingErrorHandler<Error=RoutingError>, RoutingErrorHandler: PusRoutingErrorHandler<Error = RoutingError>,
RoutingError = GenericRoutingError RoutingError = GenericRoutingError,
> { > {
service_helper: PusServiceHelper<TcInMemConverter>, service_helper: PusServiceHelper<TcInMemConverter, VerificationReporter>,
request_converter: RequestConverter, request_converter: RequestConverter,
request_router: RequestRouter, request_router: RequestRouter,
routing_error_handler: RoutingErrorHandler, routing_error_handler: RoutingErrorHandler,
@ -98,15 +100,23 @@ pub mod std_mod {
impl< impl<
TcInMemConverter: EcssTcInMemConverter, TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
RequestConverter: PusHkToRequestConverter<Error = PusPacketHandlingError>, RequestConverter: PusHkToRequestConverter<Error = PusPacketHandlingError>,
RequestRouter: PusHkRequestRouter<Error = RoutingError>, RequestRouter: PusHkRequestRouter<Error = RoutingError>,
RoutingErrorHandler: PusRoutingErrorHandler<Error = RoutingError>, RoutingErrorHandler: PusRoutingErrorHandler<Error = RoutingError>,
RoutingError, RoutingError,
> >
PusService3HkHandler<TcInMemConverter, RequestConverter, RequestRouter, RoutingErrorHandler, RoutingError> PusService3HkHandler<
TcInMemConverter,
VerificationReporter,
RequestConverter,
RequestRouter,
RoutingErrorHandler,
RoutingError,
>
{ {
pub fn new( pub fn new(
service_helper: PusServiceHelper<TcInMemConverter>, service_helper: PusServiceHelper<TcInMemConverter, VerificationReporter>,
request_converter: RequestConverter, request_converter: RequestConverter,
request_router: RequestRouter, request_router: RequestRouter,
routing_error_handler: RoutingErrorHandler, routing_error_handler: RoutingErrorHandler,
@ -130,12 +140,15 @@ pub mod std_mod {
.tc_in_mem_converter .tc_in_mem_converter
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?; .convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?;
let mut partial_error = None; let mut partial_error = None;
let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error); let time_stamp =
PusServiceBase::<VerificationReporter>::get_current_cds_short_timestamp(
&mut partial_error,
);
let (target_id, hk_request) = self.request_converter.convert( let (target_id, hk_request) = self.request_converter.convert(
ecss_tc_and_token.token, ecss_tc_and_token.token,
&tc, &tc,
&time_stamp, &time_stamp,
&mut self.service_helper.common.verification_handler.borrow_mut(), &self.service_helper.common.verification_handler,
)?; )?;
if let Err(e) = if let Err(e) =
self.request_router self.request_router
@ -147,7 +160,7 @@ pub mod std_mod {
&tc, &tc,
e, e,
&time_stamp, &time_stamp,
&mut self.service_helper.common.verification_handler.borrow_mut(), &self.service_helper.common.verification_handler,
); );
} }
Ok(PusPacketHandlerResult::RequestHandled) Ok(PusPacketHandlerResult::RequestHandled)

View File

@ -262,10 +262,10 @@ pub trait ReceivesEcssPusTc {
mod alloc_mod { mod alloc_mod {
use crate::TargetId; use crate::TargetId;
use self::verification::VerificationReporterWithSender;
use super::*; use super::*;
use crate::pus::verification::VerificationReportingProvider;
/// Extension trait for [EcssTmSenderCore]. /// Extension trait for [EcssTmSenderCore].
/// ///
/// It provides additional functionality, for example by implementing the [Downcast] trait /// It provides additional functionality, for example by implementing the [Downcast] trait
@ -355,7 +355,7 @@ mod alloc_mod {
tc: &PusTcReader, tc: &PusTcReader,
error: Self::Error, error: Self::Error,
time_stamp: &[u8], time_stamp: &[u8],
verif_reporter: &mut VerificationReporterWithSender, verif_reporter: &impl VerificationReportingProvider,
); );
} }
} }
@ -364,9 +364,7 @@ mod alloc_mod {
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub mod std_mod { pub mod std_mod {
use crate::pool::{PoolProvider, PoolProviderWithGuards, SharedStaticMemoryPool, StoreAddr}; use crate::pool::{PoolProvider, PoolProviderWithGuards, SharedStaticMemoryPool, StoreAddr};
use crate::pus::verification::{ use crate::pus::verification::{TcStateAccepted, VerificationToken};
StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
};
use crate::pus::{ use crate::pus::{
EcssChannel, EcssTcAndToken, EcssTcReceiver, EcssTcReceiverCore, EcssTmSender, EcssChannel, EcssTcAndToken, EcssTcReceiver, EcssTcReceiverCore, EcssTmSender,
EcssTmSenderCore, EcssTmtcError, GenericRecvError, GenericSendError, PusTmWrapper, EcssTmSenderCore, EcssTmtcError, GenericRecvError, GenericSendError, PusTmWrapper,
@ -383,13 +381,12 @@ pub mod std_mod {
use spacepackets::time::cds::TimeProvider; use spacepackets::time::cds::TimeProvider;
use spacepackets::time::StdTimestampError; use spacepackets::time::StdTimestampError;
use spacepackets::time::TimeWriter; use spacepackets::time::TimeWriter;
use std::cell::RefCell;
use std::string::String; use std::string::String;
use std::sync::mpsc; use std::sync::mpsc;
use std::sync::mpsc::TryRecvError; use std::sync::mpsc::TryRecvError;
use thiserror::Error; use thiserror::Error;
use super::verification::VerificationReporterWithSender; use super::verification::VerificationReportingProvider;
use super::{AcceptedEcssTcAndToken, TcInMemory}; use super::{AcceptedEcssTcAndToken, TcInMemory};
impl From<mpsc::SendError<StoreAddr>> for EcssTmtcError { impl From<mpsc::SendError<StoreAddr>> for EcssTmtcError {
@ -814,18 +811,18 @@ pub mod std_mod {
} }
} }
pub struct PusServiceBase { pub struct PusServiceBase<VerificationReporter: VerificationReportingProvider> {
pub tc_receiver: Box<dyn EcssTcReceiver>, pub tc_receiver: Box<dyn EcssTcReceiver>,
pub tm_sender: Box<dyn EcssTmSender>, pub tm_sender: Box<dyn EcssTmSender>,
pub tm_apid: u16, pub tm_apid: u16,
/// The verification handler is wrapped in a [RefCell] to allow the interior mutability /// The verification handler is wrapped in a [RefCell] to allow the interior mutability
/// pattern. This makes writing methods which are not mutable a lot easier. /// pattern. This makes writing methods which are not mutable a lot easier.
pub verification_handler: RefCell<StdVerifReporterWithSender>, pub verification_handler: VerificationReporter,
} }
impl PusServiceBase { impl<VerificationReporter: VerificationReportingProvider> PusServiceBase<VerificationReporter> {
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub fn get_current_timestamp( pub fn get_current_cds_short_timestamp(
partial_error: &mut Option<PartialPusHandlingError>, partial_error: &mut Option<PartialPusHandlingError>,
) -> [u8; 7] { ) -> [u8; 7] {
let mut time_stamp: [u8; 7] = [0; 7]; let mut time_stamp: [u8; 7] = [0; 7];
@ -839,11 +836,10 @@ pub mod std_mod {
} }
time_stamp time_stamp
} }
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub fn get_current_timestamp_ignore_error() -> [u8; 7] { pub fn get_current_timestamp_ignore_error() -> [u8; 7] {
let mut dummy = None; let mut dummy = None;
Self::get_current_timestamp(&mut dummy) Self::get_current_cds_short_timestamp(&mut dummy)
} }
} }
@ -856,17 +852,24 @@ pub mod std_mod {
/// This base class can handle PUS telecommands backed by different memory storage machanisms /// This base class can handle PUS telecommands backed by different memory storage machanisms
/// by using the [EcssTcInMemConverter] abstraction. This object provides some convenience /// by using the [EcssTcInMemConverter] abstraction. This object provides some convenience
/// methods to make the generic parts of TC handling easier. /// methods to make the generic parts of TC handling easier.
pub struct PusServiceHelper<TcInMemConverter: EcssTcInMemConverter> { pub struct PusServiceHelper<
pub common: PusServiceBase, TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
> {
pub common: PusServiceBase<VerificationReporter>,
pub tc_in_mem_converter: TcInMemConverter, pub tc_in_mem_converter: TcInMemConverter,
} }
impl<TcInMemConverter: EcssTcInMemConverter> PusServiceHelper<TcInMemConverter> { impl<
TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
> PusServiceHelper<TcInMemConverter, VerificationReporter>
{
pub fn new( pub fn new(
tc_receiver: Box<dyn EcssTcReceiver>, tc_receiver: Box<dyn EcssTcReceiver>,
tm_sender: Box<dyn EcssTmSender>, tm_sender: Box<dyn EcssTmSender>,
tm_apid: u16, tm_apid: u16,
verification_handler: VerificationReporterWithSender, verification_handler: VerificationReporter,
tc_in_mem_converter: TcInMemConverter, tc_in_mem_converter: TcInMemConverter,
) -> Self { ) -> Self {
Self { Self {
@ -874,7 +877,7 @@ pub mod std_mod {
tc_receiver, tc_receiver,
tm_sender, tm_sender,
tm_apid, tm_apid,
verification_handler: RefCell::new(verification_handler), verification_handler,
}, },
tc_in_mem_converter, tc_in_mem_converter,
} }
@ -945,7 +948,8 @@ pub mod tests {
use crate::tmtc::tm_helper::SharedTmPool; use crate::tmtc::tm_helper::SharedTmPool;
use super::verification::{ use super::verification::{
TcStateAccepted, VerificationReporterCfg, VerificationReporterWithSender, VerificationToken, TcStateAccepted, VerificationReporterCfg, VerificationReporterWithSender,
VerificationReportingProvider, VerificationToken,
}; };
use super::{ use super::{
EcssTcAndToken, EcssTcInSharedStoreConverter, EcssTcInVecConverter, MpscTcReceiver, EcssTcAndToken, EcssTcInSharedStoreConverter, EcssTcInVecConverter, MpscTcReceiver,
@ -1005,7 +1009,10 @@ pub mod tests {
/// [PusServiceHandler] which might be required for a specific PUS service handler. /// [PusServiceHandler] which might be required for a specific PUS service handler.
/// ///
/// The PUS service handler is instantiated with a [EcssTcInStoreConverter]. /// The PUS service handler is instantiated with a [EcssTcInStoreConverter].
pub fn new() -> (Self, PusServiceHelper<EcssTcInSharedStoreConverter>) { pub fn new() -> (
Self,
PusServiceHelper<EcssTcInSharedStoreConverter, VerificationReporterWithSender>,
) {
let pool_cfg = StaticPoolConfig::new(vec![(16, 16), (8, 32), (4, 64)], false); let pool_cfg = StaticPoolConfig::new(vec![(16, 16), (8, 32), (4, 64)], false);
let tc_pool = StaticMemoryPool::new(pool_cfg.clone()); let tc_pool = StaticMemoryPool::new(pool_cfg.clone());
let tm_pool = StaticMemoryPool::new(pool_cfg); let tm_pool = StaticMemoryPool::new(pool_cfg);
@ -1106,7 +1113,10 @@ pub mod tests {
} }
impl PusServiceHandlerWithVecCommon { impl PusServiceHandlerWithVecCommon {
pub fn new() -> (Self, PusServiceHelper<EcssTcInVecConverter>) { pub fn new() -> (
Self,
PusServiceHelper<EcssTcInVecConverter, VerificationReporterWithSender>,
) {
let (test_srv_tc_tx, test_srv_tc_rx) = mpsc::channel(); let (test_srv_tc_tx, test_srv_tc_rx) = mpsc::channel();
let (tm_tx, tm_rx) = mpsc::channel(); let (tm_tx, tm_rx) = mpsc::channel();

View File

@ -1,4 +1,5 @@
use super::scheduler::PusSchedulerProvider; use super::scheduler::PusSchedulerProvider;
use super::verification::VerificationReportingProvider;
use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper}; use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper};
use crate::pool::PoolProvider; use crate::pool::PoolProvider;
use crate::pus::{PusPacketHandlerResult, PusPacketHandlingError}; use crate::pus::{PusPacketHandlerResult, PusPacketHandlingError};
@ -16,16 +17,23 @@ use spacepackets::time::cds::TimeProvider;
/// telecommands when applicable. /// telecommands when applicable.
pub struct PusService11SchedHandler< pub struct PusService11SchedHandler<
TcInMemConverter: EcssTcInMemConverter, TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
PusScheduler: PusSchedulerProvider, PusScheduler: PusSchedulerProvider,
> { > {
pub service_helper: PusServiceHelper<TcInMemConverter>, pub service_helper: PusServiceHelper<TcInMemConverter, VerificationReporter>,
scheduler: PusScheduler, scheduler: PusScheduler,
} }
impl<TcInMemConverter: EcssTcInMemConverter, Scheduler: PusSchedulerProvider> impl<
PusService11SchedHandler<TcInMemConverter, Scheduler> TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
Scheduler: PusSchedulerProvider,
> PusService11SchedHandler<TcInMemConverter, VerificationReporter, Scheduler>
{ {
pub fn new(service_helper: PusServiceHelper<TcInMemConverter>, scheduler: Scheduler) -> Self { pub fn new(
service_helper: PusServiceHelper<TcInMemConverter, VerificationReporter>,
scheduler: Scheduler,
) -> Self {
Self { Self {
service_helper, service_helper,
scheduler, scheduler,
@ -62,14 +70,15 @@ impl<TcInMemConverter: EcssTcInMemConverter, Scheduler: PusSchedulerProvider>
)); ));
} }
let mut partial_error = None; let mut partial_error = None;
let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error); let time_stamp = PusServiceBase::<VerificationReporter>::get_current_cds_short_timestamp(
&mut partial_error,
);
match standard_subservice.unwrap() { match standard_subservice.unwrap() {
scheduling::Subservice::TcEnableScheduling => { scheduling::Subservice::TcEnableScheduling => {
let start_token = self let start_token = self
.service_helper .service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.start_success(ecss_tc_and_token.token, Some(&time_stamp)) .start_success(ecss_tc_and_token.token, Some(&time_stamp))
.expect("Error sending start success"); .expect("Error sending start success");
@ -78,7 +87,6 @@ impl<TcInMemConverter: EcssTcInMemConverter, Scheduler: PusSchedulerProvider>
self.service_helper self.service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.completion_success(start_token, Some(&time_stamp)) .completion_success(start_token, Some(&time_stamp))
.expect("Error sending completion success"); .expect("Error sending completion success");
} else { } else {
@ -92,7 +100,6 @@ impl<TcInMemConverter: EcssTcInMemConverter, Scheduler: PusSchedulerProvider>
.service_helper .service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.start_success(ecss_tc_and_token.token, Some(&time_stamp)) .start_success(ecss_tc_and_token.token, Some(&time_stamp))
.expect("Error sending start success"); .expect("Error sending start success");
@ -101,7 +108,6 @@ impl<TcInMemConverter: EcssTcInMemConverter, Scheduler: PusSchedulerProvider>
self.service_helper self.service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.completion_success(start_token, Some(&time_stamp)) .completion_success(start_token, Some(&time_stamp))
.expect("Error sending completion success"); .expect("Error sending completion success");
} else { } else {
@ -115,7 +121,6 @@ impl<TcInMemConverter: EcssTcInMemConverter, Scheduler: PusSchedulerProvider>
.service_helper .service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.start_success(ecss_tc_and_token.token, Some(&time_stamp)) .start_success(ecss_tc_and_token.token, Some(&time_stamp))
.expect("Error sending start success"); .expect("Error sending start success");
@ -126,7 +131,6 @@ impl<TcInMemConverter: EcssTcInMemConverter, Scheduler: PusSchedulerProvider>
self.service_helper self.service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.completion_success(start_token, Some(&time_stamp)) .completion_success(start_token, Some(&time_stamp))
.expect("Error sending completion success"); .expect("Error sending completion success");
} }
@ -135,7 +139,6 @@ impl<TcInMemConverter: EcssTcInMemConverter, Scheduler: PusSchedulerProvider>
.service_helper .service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.start_success(ecss_tc_and_token.token, Some(&time_stamp)) .start_success(ecss_tc_and_token.token, Some(&time_stamp))
.expect("error sending start success"); .expect("error sending start success");
@ -147,7 +150,6 @@ impl<TcInMemConverter: EcssTcInMemConverter, Scheduler: PusSchedulerProvider>
self.service_helper self.service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.completion_success(start_token, Some(&time_stamp)) .completion_success(start_token, Some(&time_stamp))
.expect("sending completion success failed"); .expect("sending completion success failed");
} }
@ -172,6 +174,7 @@ impl<TcInMemConverter: EcssTcInMemConverter, Scheduler: PusSchedulerProvider>
mod tests { mod tests {
use crate::pool::{StaticMemoryPool, StaticPoolConfig}; use crate::pool::{StaticMemoryPool, StaticPoolConfig};
use crate::pus::tests::TEST_APID; use crate::pus::tests::TEST_APID;
use crate::pus::verification::VerificationReporterWithSender;
use crate::pus::{ use crate::pus::{
scheduler::{self, PusSchedulerProvider, TcInfo}, scheduler::{self, PusSchedulerProvider, TcInfo},
tests::{PusServiceHandlerWithSharedStoreCommon, PusTestHarness}, tests::{PusServiceHandlerWithSharedStoreCommon, PusTestHarness},
@ -194,7 +197,11 @@ mod tests {
struct Pus11HandlerWithStoreTester { struct Pus11HandlerWithStoreTester {
common: PusServiceHandlerWithSharedStoreCommon, common: PusServiceHandlerWithSharedStoreCommon,
handler: PusService11SchedHandler<EcssTcInSharedStoreConverter, TestScheduler>, handler: PusService11SchedHandler<
EcssTcInSharedStoreConverter,
VerificationReporterWithSender,
TestScheduler,
>,
sched_tc_pool: StaticMemoryPool, sched_tc_pool: StaticMemoryPool,
} }

View File

@ -5,16 +5,24 @@ use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
use spacepackets::ecss::PusPacket; use spacepackets::ecss::PusPacket;
use spacepackets::SpHeader; use spacepackets::SpHeader;
use super::verification::VerificationReportingProvider;
use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper}; use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper};
/// This is a helper class for [std] environments to handle generic PUS 17 (test service) packets. /// This is a helper class for [std] environments to handle generic PUS 17 (test service) packets.
/// This handler only processes ping requests and generates a ping reply for them accordingly. /// This handler only processes ping requests and generates a ping reply for them accordingly.
pub struct PusService17TestHandler<TcInMemConverter: EcssTcInMemConverter> { pub struct PusService17TestHandler<
pub service_helper: PusServiceHelper<TcInMemConverter>, TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
> {
pub service_helper: PusServiceHelper<TcInMemConverter, VerificationReporter>,
} }
impl<TcInMemConverter: EcssTcInMemConverter> PusService17TestHandler<TcInMemConverter> { impl<
pub fn new(service_helper: PusServiceHelper<TcInMemConverter>) -> Self { TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
> PusService17TestHandler<TcInMemConverter, VerificationReporter>
{
pub fn new(service_helper: PusServiceHelper<TcInMemConverter, VerificationReporter>) -> Self {
Self { service_helper } Self { service_helper }
} }
@ -33,12 +41,14 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService17TestHandler<TcInMemConv
} }
if tc.subservice() == 1 { if tc.subservice() == 1 {
let mut partial_error = None; let mut partial_error = None;
let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error); let time_stamp =
PusServiceBase::<VerificationReporter>::get_current_cds_short_timestamp(
&mut partial_error,
);
let result = self let result = self
.service_helper .service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.start_success(ecss_tc_and_token.token, Some(&time_stamp)) .start_success(ecss_tc_and_token.token, Some(&time_stamp))
.map_err(|_| PartialPusHandlingError::Verification); .map_err(|_| PartialPusHandlingError::Verification);
let start_token = if let Ok(result) = result { let start_token = if let Ok(result) = result {
@ -67,7 +77,6 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService17TestHandler<TcInMemConv
.service_helper .service_helper
.common .common
.verification_handler .verification_handler
.get_mut()
.completion_success(start_token, Some(&time_stamp)) .completion_success(start_token, Some(&time_stamp))
.is_err() .is_err()
{ {
@ -95,7 +104,9 @@ mod tests {
PusServiceHandlerWithSharedStoreCommon, PusServiceHandlerWithVecCommon, PusTestHarness, PusServiceHandlerWithSharedStoreCommon, PusServiceHandlerWithVecCommon, PusTestHarness,
SimplePusPacketHandler, TEST_APID, SimplePusPacketHandler, TEST_APID,
}; };
use crate::pus::verification::RequestId; use crate::pus::verification::{
RequestId, VerificationReporterWithSender, VerificationReportingProvider,
};
use crate::pus::verification::{TcStateAccepted, VerificationToken}; use crate::pus::verification::{TcStateAccepted, VerificationToken};
use crate::pus::{ use crate::pus::{
EcssTcInSharedStoreConverter, EcssTcInVecConverter, PusPacketHandlerResult, EcssTcInSharedStoreConverter, EcssTcInVecConverter, PusPacketHandlerResult,
@ -111,7 +122,8 @@ mod tests {
struct Pus17HandlerWithStoreTester { struct Pus17HandlerWithStoreTester {
common: PusServiceHandlerWithSharedStoreCommon, common: PusServiceHandlerWithSharedStoreCommon,
handler: PusService17TestHandler<EcssTcInSharedStoreConverter>, handler:
PusService17TestHandler<EcssTcInSharedStoreConverter, VerificationReporterWithSender>,
} }
impl Pus17HandlerWithStoreTester { impl Pus17HandlerWithStoreTester {
@ -149,7 +161,7 @@ mod tests {
struct Pus17HandlerWithVecTester { struct Pus17HandlerWithVecTester {
common: PusServiceHandlerWithVecCommon, common: PusServiceHandlerWithVecCommon,
handler: PusService17TestHandler<EcssTcInVecConverter>, handler: PusService17TestHandler<EcssTcInVecConverter, VerificationReporterWithSender>,
} }
impl Pus17HandlerWithVecTester { impl Pus17HandlerWithVecTester {

View File

@ -16,7 +16,9 @@
//! use std::sync::{Arc, mpsc, RwLock}; //! use std::sync::{Arc, mpsc, RwLock};
//! use std::time::Duration; //! use std::time::Duration;
//! use satrs::pool::{PoolProviderWithGuards, StaticMemoryPool, StaticPoolConfig}; //! use satrs::pool::{PoolProviderWithGuards, StaticMemoryPool, StaticPoolConfig};
//! use satrs::pus::verification::{VerificationReporterCfg, VerificationReporterWithSender}; //! use satrs::pus::verification::{
//! VerificationReportingProvider, VerificationReporterCfg, VerificationReporterWithSender
//! };
//! use satrs::seq_count::SeqCountProviderSimple; //! use satrs::seq_count::SeqCountProviderSimple;
//! use satrs::pus::MpscTmInSharedPoolSender; //! use satrs::pus::MpscTmInSharedPoolSender;
//! use satrs::tmtc::tm_helper::SharedTmPool; //! use satrs::tmtc::tm_helper::SharedTmPool;
@ -399,6 +401,64 @@ impl<'src_data, TcState: WasAtLeastAccepted + Copy>
pub fn send_success_step_or_completion_success(self) {} pub fn send_success_step_or_completion_success(self) {}
} }
pub trait VerificationReportingProvider {
fn add_tc(
&mut self,
pus_tc: &(impl CcsdsPacket + IsPusTelecommand),
) -> VerificationToken<TcStateNone>;
fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone>;
fn acceptance_success(
&self,
token: VerificationToken<TcStateNone>,
time_stamp: Option<&[u8]>,
) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateNone>>;
fn acceptance_failure(
&self,
token: VerificationToken<TcStateNone>,
params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<TcStateNone>>;
fn start_success(
&self,
token: VerificationToken<TcStateAccepted>,
time_stamp: Option<&[u8]>,
) -> Result<VerificationToken<TcStateStarted>, VerificationOrSendErrorWithToken<TcStateAccepted>>;
fn start_failure(
&self,
token: VerificationToken<TcStateAccepted>,
params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<TcStateAccepted>>;
fn step_success(
&self,
token: &VerificationToken<TcStateStarted>,
time_stamp: Option<&[u8]>,
step: impl EcssEnumeration,
) -> Result<(), EcssTmtcError>;
fn step_failure(
&self,
token: VerificationToken<TcStateStarted>,
params: FailParamsWithStep,
) -> Result<(), VerificationOrSendErrorWithToken<TcStateStarted>>;
fn completion_success<TcState: WasAtLeastAccepted + Copy>(
&self,
token: VerificationToken<TcState>,
time_stamp: Option<&[u8]>,
) -> Result<(), VerificationOrSendErrorWithToken<TcState>>;
fn completion_failure<TcState: WasAtLeastAccepted + Copy>(
&self,
token: VerificationToken<TcState>,
params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<TcState>>;
}
/// Primary verification handler. It provides an API to send PUS 1 verification telemetry packets /// Primary verification handler. It provides an API to send PUS 1 verification telemetry packets
/// and verify the various steps of telecommand handling as specified in the PUS standard. /// and verify the various steps of telecommand handling as specified in the PUS standard.
/// ///
@ -1226,14 +1286,24 @@ mod alloc_mod {
to self.reporter { to self.reporter {
pub fn set_apid(&mut self, apid: u16) -> bool; pub fn set_apid(&mut self, apid: u16) -> bool;
pub fn apid(&self) -> u16; pub fn apid(&self) -> u16;
pub fn add_tc(&mut self, pus_tc: &(impl CcsdsPacket + IsPusTelecommand)) -> VerificationToken<TcStateNone>;
pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone>;
pub fn dest_id(&self) -> u16; pub fn dest_id(&self) -> u16;
pub fn set_dest_id(&mut self, dest_id: u16); pub fn set_dest_id(&mut self, dest_id: u16);
} }
} }
}
pub fn acceptance_success( impl VerificationReportingProvider for VerificationReporterWithSender {
delegate! {
to self.reporter {
fn add_tc(
&mut self,
pus_tc: &(impl CcsdsPacket + IsPusTelecommand),
) -> VerificationToken<TcStateNone>;
fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone>;
}
}
fn acceptance_success(
&self, &self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
@ -1243,7 +1313,7 @@ mod alloc_mod {
.acceptance_success(token, self.sender.as_ref(), time_stamp) .acceptance_success(token, self.sender.as_ref(), time_stamp)
} }
pub fn acceptance_failure( fn acceptance_failure(
&self, &self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
params: FailParams, params: FailParams,
@ -1252,7 +1322,7 @@ mod alloc_mod {
.acceptance_failure(token, self.sender.as_ref(), params) .acceptance_failure(token, self.sender.as_ref(), params)
} }
pub fn start_success( fn start_success(
&self, &self,
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
@ -1264,7 +1334,7 @@ mod alloc_mod {
.start_success(token, self.sender.as_ref(), time_stamp) .start_success(token, self.sender.as_ref(), time_stamp)
} }
pub fn start_failure( fn start_failure(
&self, &self,
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
params: FailParams, params: FailParams,
@ -1273,7 +1343,7 @@ mod alloc_mod {
.start_failure(token, self.sender.as_ref(), params) .start_failure(token, self.sender.as_ref(), params)
} }
pub fn step_success( fn step_success(
&self, &self,
token: &VerificationToken<TcStateStarted>, token: &VerificationToken<TcStateStarted>,
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
@ -1283,7 +1353,7 @@ mod alloc_mod {
.step_success(token, self.sender.as_ref(), time_stamp, step) .step_success(token, self.sender.as_ref(), time_stamp, step)
} }
pub fn step_failure( fn step_failure(
&self, &self,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
params: FailParamsWithStep, params: FailParamsWithStep,
@ -1292,7 +1362,7 @@ mod alloc_mod {
.step_failure(token, self.sender.as_ref(), params) .step_failure(token, self.sender.as_ref(), params)
} }
pub fn completion_success<TcState: WasAtLeastAccepted + Copy>( fn completion_success<TcState: WasAtLeastAccepted + Copy>(
&self, &self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
@ -1301,7 +1371,7 @@ mod alloc_mod {
.completion_success(token, self.sender.as_ref(), time_stamp) .completion_success(token, self.sender.as_ref(), time_stamp)
} }
pub fn completion_failure<TcState: WasAtLeastAccepted + Copy>( fn completion_failure<TcState: WasAtLeastAccepted + Copy>(
&self, &self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
params: FailParams, params: FailParams,
@ -1347,6 +1417,8 @@ mod tests {
use std::vec; use std::vec;
use std::vec::Vec; use std::vec::Vec;
use super::VerificationReportingProvider;
fn is_send<T: Send>(_: &T) {} fn is_send<T: Send>(_: &T) {}
#[allow(dead_code)] #[allow(dead_code)]
fn is_sync<T: Sync>(_: &T) {} fn is_sync<T: Sync>(_: &T) {}
@ -1682,7 +1754,7 @@ mod tests {
let accepted_token = let accepted_token =
b.vr.acceptance_success(tok, &sender, Some(&EMPTY_STAMP)) b.vr.acceptance_success(tok, &sender, Some(&EMPTY_STAMP))
.expect("Sending acceptance success failed"); .expect("Sending acceptance success failed");
b.vr.start_failure(accepted_token, &mut sender, fail_params) b.vr.start_failure(accepted_token, &sender, fail_params)
.expect("Start failure failure"); .expect("Start failure failure");
start_fail_check(&mut sender, tok.req_id, fail_data_raw); start_fail_check(&mut sender, tok.req_id, fail_data_raw);
} }
@ -1905,12 +1977,11 @@ mod tests {
); );
let accepted_token = let accepted_token =
b.vr.acceptance_success(tok, &mut sender, Some(&EMPTY_STAMP)) b.vr.acceptance_success(tok, &sender, Some(&EMPTY_STAMP))
.expect("Sending acceptance success failed"); .expect("Sending acceptance success failed");
let started_token = let started_token =
b.vr.start_success(accepted_token, &mut sender, Some(&[0, 1, 0, 1, 0, 1, 0])) b.vr.start_success(accepted_token, &sender, Some(&[0, 1, 0, 1, 0, 1, 0]))
.expect("Sending start success failed"); .expect("Sending start success failed");
let mut empty =
b.vr.step_success( b.vr.step_success(
&started_token, &started_token,
&mut sender, &mut sender,
@ -1918,11 +1989,8 @@ mod tests {
EcssEnumU8::new(0), EcssEnumU8::new(0),
) )
.expect("Sending completion success failed"); .expect("Sending completion success failed");
assert_eq!(empty, ()); b.vr.step_failure(started_token, &sender, fail_params)
empty =
b.vr.step_failure(started_token, &mut sender, fail_params)
.expect("Step failure failed"); .expect("Step failure failed");
assert_eq!(empty, ());
check_step_failure(&mut sender, req_id, fail_data_raw); check_step_failure(&mut sender, req_id, fail_data_raw);
} }
@ -2024,10 +2092,8 @@ mod tests {
let started_token = let started_token =
b.vr.start_success(accepted_token, &mut sender, Some(&[0, 1, 0, 1, 0, 1, 0])) b.vr.start_success(accepted_token, &mut sender, Some(&[0, 1, 0, 1, 0, 1, 0]))
.expect("Sending start success failed"); .expect("Sending start success failed");
let empty =
b.vr.completion_failure(started_token, &mut sender, fail_params) b.vr.completion_failure(started_token, &mut sender, fail_params)
.expect("Completion failure"); .expect("Completion failure");
assert_eq!(empty, ());
completion_fail_check(&mut sender, req_id); completion_fail_check(&mut sender, req_id);
} }
@ -2046,11 +2112,9 @@ mod tests {
.helper .helper
.start_success(accepted_token, Some(&[0, 1, 0, 1, 0, 1, 0])) .start_success(accepted_token, Some(&[0, 1, 0, 1, 0, 1, 0]))
.expect("Sending start success failed"); .expect("Sending start success failed");
let empty = b b.helper
.helper
.completion_failure(started_token, fail_params) .completion_failure(started_token, fail_params)
.expect("Completion failure"); .expect("Completion failure");
assert_eq!(empty, ());
let sender: &mut TestSender = b.helper.sender.downcast_mut().unwrap(); let sender: &mut TestSender = b.helper.sender.downcast_mut().unwrap();
completion_fail_check(sender, req_id); completion_fail_check(sender, req_id);
} }
@ -2104,12 +2168,12 @@ mod tests {
let (b, tok) = base_init(false); let (b, tok) = base_init(false);
let mut sender = TestSender::default(); let mut sender = TestSender::default();
let accepted_token = let accepted_token =
b.vr.acceptance_success(tok, &mut sender, Some(&EMPTY_STAMP)) b.vr.acceptance_success(tok, &sender, Some(&EMPTY_STAMP))
.expect("Sending acceptance success failed"); .expect("Sending acceptance success failed");
let started_token = let started_token =
b.vr.start_success(accepted_token, &mut sender, Some(&[0, 1, 0, 1, 0, 1, 0])) b.vr.start_success(accepted_token, &sender, Some(&[0, 1, 0, 1, 0, 1, 0]))
.expect("Sending start success failed"); .expect("Sending start success failed");
b.vr.completion_success(started_token, &mut sender, Some(&EMPTY_STAMP)) b.vr.completion_success(started_token, &sender, Some(&EMPTY_STAMP))
.expect("Sending completion success failed"); .expect("Sending completion success failed");
completion_success_check(&mut sender, tok.req_id); completion_success_check(&mut sender, tok.req_id);
} }

View File

@ -3,7 +3,7 @@ pub mod crossbeam_test {
use hashbrown::HashMap; use hashbrown::HashMap;
use satrs::pool::{PoolProvider, PoolProviderWithGuards, StaticMemoryPool, StaticPoolConfig}; use satrs::pool::{PoolProvider, PoolProviderWithGuards, StaticMemoryPool, StaticPoolConfig};
use satrs::pus::verification::{ use satrs::pus::verification::{
FailParams, RequestId, VerificationReporterCfg, VerificationReporterWithSender, FailParams, RequestId, VerificationReporterCfg, VerificationReporterWithSender, VerificationReportingProvider,
}; };
use satrs::pus::CrossbeamTmInStoreSender; use satrs::pus::CrossbeamTmInStoreSender;
use satrs::tmtc::tm_helper::SharedTmPool; use satrs::tmtc::tm_helper::SharedTmPool;