From 53003b9c66fa0dae7fcd57f0fea0ee6420c75eab Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Feb 2023 14:53:57 +0100 Subject: [PATCH] allow verif failure and completion starting from accepted - Also add some prototyping code a prep for generic PUS router --- satrs-core/src/mode.rs | 8 +++- satrs-core/src/pus/verification.rs | 61 +++++++++++++++++------------- satrs-example/src/pus.rs | 42 +++++++++++++++++++- 3 files changed, 80 insertions(+), 31 deletions(-) diff --git a/satrs-core/src/mode.rs b/satrs-core/src/mode.rs index 7155d67..e29cbf0 100644 --- a/satrs-core/src/mode.rs +++ b/satrs-core/src/mode.rs @@ -36,9 +36,13 @@ impl ModeAndSubmode { }) } - pub fn mode(&self) -> u32 {self.mode} + pub fn mode(&self) -> u32 { + self.mode + } - pub fn submode(&self) -> u16 {self.submode} + pub fn submode(&self) -> u16 { + self.submode + } } #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] diff --git a/satrs-core/src/pus/verification.rs b/satrs-core/src/pus/verification.rs index 75ca496..8a71d00 100644 --- a/satrs-core/src/pus/verification.rs +++ b/satrs-core/src/pus/verification.rs @@ -199,6 +199,8 @@ pub struct VerificationToken { req_id: RequestId, } +pub trait WasAtLeastAccepted {} + #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct TcStateNone; #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -206,6 +208,9 @@ pub struct TcStateAccepted; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct TcStateStarted; +impl WasAtLeastAccepted for TcStateAccepted {} +impl WasAtLeastAccepted for TcStateStarted {} + #[derive(Debug, Eq, PartialEq)] pub enum TcStateToken { None(VerificationToken), @@ -381,7 +386,9 @@ impl<'src_data> VerificationSendable<'src_data, TcStateAccepted, VerifSuccess> { } } -impl<'src_data> VerificationSendable<'src_data, TcStateStarted, VerifSuccess> { +impl<'src_data, TcState: WasAtLeastAccepted + Copy> + VerificationSendable<'src_data, TcState, VerifSuccess> +{ pub fn send_success_step_or_completion_success( self, seq_counter: Option<&(impl SequenceCountProviderCore + ?Sized)>, @@ -704,15 +711,15 @@ impl VerificationReporterCore { /// /// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// token because verification handling is done. - pub fn completion_success<'src_data>( + pub fn completion_success<'src_data, TcState: WasAtLeastAccepted + Copy>( &mut self, src_data_buf: &'src_data mut [u8], - token: VerificationToken, + token: VerificationToken, seq_counter: &(impl SequenceCountProviderCore + ?Sized), time_stamp: Option<&'src_data [u8]>, ) -> Result< - VerificationSendable<'src_data, TcStateStarted, VerifSuccess>, - VerificationErrorWithToken, + VerificationSendable<'src_data, TcState, VerifSuccess>, + VerificationErrorWithToken, > { self.sendable_success_no_step( src_data_buf, @@ -727,15 +734,15 @@ impl VerificationReporterCore { /// /// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// token because verification handling is done. - pub fn completion_failure<'src_data>( + pub fn completion_failure<'src_data, TcState: WasAtLeastAccepted + Copy>( &mut self, src_data_buf: &'src_data mut [u8], - token: VerificationToken, + token: VerificationToken, seq_counter: &(impl SequenceCountProviderCore + ?Sized), params: FailParams<'src_data, '_>, ) -> Result< - VerificationSendable<'src_data, TcStateStarted, VerifFailure>, - VerificationErrorWithToken, + VerificationSendable<'src_data, TcState, VerifFailure>, + VerificationErrorWithToken, > { self.sendable_failure_no_step( src_data_buf, @@ -747,12 +754,12 @@ impl VerificationReporterCore { ) } - pub fn send_step_or_completion_success( + pub fn send_step_or_completion_success( &self, - mut sendable: VerificationSendable<'_, TcStateStarted, VerifSuccess>, + mut sendable: VerificationSendable<'_, TcState, VerifSuccess>, seq_counter: &(impl SequenceCountProviderCore + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized), - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), VerificationOrSendErrorWithToken> { sender .send_tm(sendable.pus_tm.take().unwrap()) .map_err(|e| { @@ -765,12 +772,12 @@ impl VerificationReporterCore { Ok(()) } - pub fn send_step_or_completion_failure( + pub fn send_step_or_completion_failure( &self, - mut sendable: VerificationSendable<'_, TcStateStarted, VerifFailure>, + mut sendable: VerificationSendable<'_, TcState, VerifFailure>, seq_counter: &(impl SequenceCountProviderCore + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized), - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), VerificationOrSendErrorWithToken> { sender .send_tm(sendable.pus_tm.take().unwrap()) .map_err(|e| { @@ -1087,12 +1094,12 @@ mod alloc_mod { /// /// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// token because verification handling is done. - pub fn completion_success( + pub fn completion_success( &mut self, - token: VerificationToken, + token: VerificationToken, sender: &mut (impl EcssTmSenderCore + ?Sized), time_stamp: Option<&[u8]>, - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), VerificationOrSendErrorWithToken> { let sendable = self.reporter.completion_success( self.source_data_buf.as_mut_slice(), token, @@ -1110,12 +1117,12 @@ mod alloc_mod { /// /// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// token because verification handling is done. - pub fn completion_failure( + pub fn completion_failure( &mut self, - token: VerificationToken, + token: VerificationToken, sender: &mut (impl EcssTmSenderCore + ?Sized), params: FailParams, - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), VerificationOrSendErrorWithToken> { let sendable = self.reporter.completion_failure( self.source_data_buf.as_mut_slice(), token, @@ -1226,20 +1233,20 @@ mod alloc_mod { .step_failure(token, self.sender.as_mut(), params) } - pub fn completion_success( + pub fn completion_success( &mut self, - token: VerificationToken, + token: VerificationToken, time_stamp: Option<&[u8]>, - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), VerificationOrSendErrorWithToken> { self.reporter .completion_success(token, self.sender.as_mut(), time_stamp) } - pub fn completion_failure( + pub fn completion_failure( &mut self, - token: VerificationToken, + token: VerificationToken, params: FailParams, - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), VerificationOrSendErrorWithToken> { self.reporter .completion_failure(token, self.sender.as_mut(), params) } diff --git a/satrs-example/src/pus.rs b/satrs-example/src/pus.rs index 06d98eb..b08abac 100644 --- a/satrs-example/src/pus.rs +++ b/satrs-example/src/pus.rs @@ -5,7 +5,7 @@ use satrs_core::events::EventU32; use satrs_core::hk::{CollectionIntervalFactor, HkRequest}; use satrs_core::mode::{ModeAndSubmode, ModeRequest}; use satrs_core::params::Params; -use satrs_core::pool::StoreAddr; +use satrs_core::pool::{PoolProvider, StoreAddr}; use satrs_core::pus::event_man::{EventRequest, EventRequestWithToken}; use satrs_core::pus::hk; use satrs_core::pus::mode; @@ -18,6 +18,7 @@ use satrs_core::pus::verification::{ use satrs_core::pus::{event, GenericTcCheckError}; use satrs_core::res_code::ResultU16; use satrs_core::spacepackets::ecss::{scheduling, PusServiceId}; +use satrs_core::spacepackets::time::CcsdsTimeProvider; use satrs_core::tmtc::tm_helper::PusTmWithCdsShortHelper; use satrs_core::tmtc::{AddressableId, PusServiceProvider, TargetId}; use satrs_core::{ @@ -29,7 +30,7 @@ use std::cell::RefCell; use std::collections::HashMap; use std::convert::TryFrom; use std::rc::Rc; -use std::sync::mpsc::Sender; +use std::sync::mpsc::{Receiver, Sender}; pub struct PusReceiver { pub tm_helper: PusTmWithCdsShortHelper, @@ -53,6 +54,43 @@ impl PusTmArgs { } } +pub struct PusTcHandlerBase { + pub tc_store: Box, + pub receiver: Receiver<(StoreAddr, VerificationToken)>, + pub verif_reporter: StdVerifReporterWithSender, + pub time_provider: Box, +} + +pub trait TestHandlerNoPing { + fn handle_no_ping_tc(&mut self, tc: PusTc); +} + +pub struct PusTestTcHandler { + pub base: PusTcHandlerBase, + handler: Option>, +} + +pub struct PusScheduleTcHandler { + pub base: PusTestTcHandler, +} + +impl PusTestTcHandler { + pub fn operation(&mut self) { + let (addr, token) = self.base.receiver.recv().unwrap(); + let data = self.base.tc_store.read(&addr).unwrap(); + let (pus_tc, _len) = PusTc::from_bytes(data).unwrap(); + let stamp: [u8; 7] = [0; 7]; + if pus_tc.subservice() == 1 { + self.base + .verif_reporter + .completion_success(token, Some(&stamp)) + .unwrap(); + } else if let Some(handler) = &mut self.handler { + handler.handle_no_ping_tc(pus_tc); + } + } +} + pub struct PusTcArgs { pub event_request_tx: Sender, /// Request routing helper. Maps targeted requests to their recipient. -- 2.43.0