allow verif failure and completion starting from accepted #40

Merged
lkoester merged 1 commits from improved_verif_add_prototyping_code into main 2023-02-28 18:43:06 +01:00
3 changed files with 80 additions and 31 deletions

View File

@ -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)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

View File

@ -199,6 +199,8 @@ pub struct VerificationToken<STATE> {
req_id: RequestId, req_id: RequestId,
} }
pub trait WasAtLeastAccepted {}
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct TcStateNone; pub struct TcStateNone;
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
@ -206,6 +208,9 @@ pub struct TcStateAccepted;
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct TcStateStarted; pub struct TcStateStarted;
impl WasAtLeastAccepted for TcStateAccepted {}
impl WasAtLeastAccepted for TcStateStarted {}
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub enum TcStateToken { pub enum TcStateToken {
None(VerificationToken<TcStateNone>), None(VerificationToken<TcStateNone>),
@ -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( pub fn send_success_step_or_completion_success(
self, self,
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>, seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
@ -704,15 +711,15 @@ impl VerificationReporterCore {
/// ///
/// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// Requires a token previously acquired by calling [Self::start_success]. It consumes the
/// token because verification handling is done. /// token because verification handling is done.
pub fn completion_success<'src_data>( pub fn completion_success<'src_data, TcState: WasAtLeastAccepted + Copy>(
&mut self, &mut self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcState>,
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized), seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
time_stamp: Option<&'src_data [u8]>, time_stamp: Option<&'src_data [u8]>,
) -> Result< ) -> Result<
VerificationSendable<'src_data, TcStateStarted, VerifSuccess>, VerificationSendable<'src_data, TcState, VerifSuccess>,
VerificationErrorWithToken<TcStateStarted>, VerificationErrorWithToken<TcState>,
> { > {
self.sendable_success_no_step( self.sendable_success_no_step(
src_data_buf, src_data_buf,
@ -727,15 +734,15 @@ impl VerificationReporterCore {
/// ///
/// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// Requires a token previously acquired by calling [Self::start_success]. It consumes the
/// token because verification handling is done. /// token because verification handling is done.
pub fn completion_failure<'src_data>( pub fn completion_failure<'src_data, TcState: WasAtLeastAccepted + Copy>(
&mut self, &mut self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcState>,
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized), seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
params: FailParams<'src_data, '_>, params: FailParams<'src_data, '_>,
) -> Result< ) -> Result<
VerificationSendable<'src_data, TcStateStarted, VerifFailure>, VerificationSendable<'src_data, TcState, VerifFailure>,
VerificationErrorWithToken<TcStateStarted>, VerificationErrorWithToken<TcState>,
> { > {
self.sendable_failure_no_step( self.sendable_failure_no_step(
src_data_buf, src_data_buf,
@ -747,12 +754,12 @@ impl VerificationReporterCore {
) )
} }
pub fn send_step_or_completion_success<E>( pub fn send_step_or_completion_success<E, TcState: WasAtLeastAccepted + Copy>(
&self, &self,
mut sendable: VerificationSendable<'_, TcStateStarted, VerifSuccess>, mut sendable: VerificationSendable<'_, TcState, VerifSuccess>,
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized), seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> {
sender sender
.send_tm(sendable.pus_tm.take().unwrap()) .send_tm(sendable.pus_tm.take().unwrap())
.map_err(|e| { .map_err(|e| {
@ -765,12 +772,12 @@ impl VerificationReporterCore {
Ok(()) Ok(())
} }
pub fn send_step_or_completion_failure<E>( pub fn send_step_or_completion_failure<E, TcState: WasAtLeastAccepted + Copy>(
&self, &self,
mut sendable: VerificationSendable<'_, TcStateStarted, VerifFailure>, mut sendable: VerificationSendable<'_, TcState, VerifFailure>,
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized), seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> {
sender sender
.send_tm(sendable.pus_tm.take().unwrap()) .send_tm(sendable.pus_tm.take().unwrap())
.map_err(|e| { .map_err(|e| {
@ -1087,12 +1094,12 @@ mod alloc_mod {
/// ///
/// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// Requires a token previously acquired by calling [Self::start_success]. It consumes the
/// token because verification handling is done. /// token because verification handling is done.
pub fn completion_success<E>( pub fn completion_success<E, TcState: WasAtLeastAccepted + Copy>(
&mut self, &mut self,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcState>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> {
let sendable = self.reporter.completion_success( let sendable = self.reporter.completion_success(
self.source_data_buf.as_mut_slice(), self.source_data_buf.as_mut_slice(),
token, token,
@ -1110,12 +1117,12 @@ mod alloc_mod {
/// ///
/// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// Requires a token previously acquired by calling [Self::start_success]. It consumes the
/// token because verification handling is done. /// token because verification handling is done.
pub fn completion_failure<E>( pub fn completion_failure<E, TcState: WasAtLeastAccepted + Copy>(
&mut self, &mut self,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcState>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> {
let sendable = self.reporter.completion_failure( let sendable = self.reporter.completion_failure(
self.source_data_buf.as_mut_slice(), self.source_data_buf.as_mut_slice(),
token, token,
@ -1226,20 +1233,20 @@ mod alloc_mod {
.step_failure(token, self.sender.as_mut(), params) .step_failure(token, self.sender.as_mut(), params)
} }
pub fn completion_success( pub fn completion_success<TcState: WasAtLeastAccepted + Copy>(
&mut self, &mut self,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcState>,
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> {
self.reporter self.reporter
.completion_success(token, self.sender.as_mut(), time_stamp) .completion_success(token, self.sender.as_mut(), time_stamp)
} }
pub fn completion_failure( pub fn completion_failure<TcState: WasAtLeastAccepted + Copy>(
&mut self, &mut self,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcState>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> {
self.reporter self.reporter
.completion_failure(token, self.sender.as_mut(), params) .completion_failure(token, self.sender.as_mut(), params)
} }

View File

@ -5,7 +5,7 @@ use satrs_core::events::EventU32;
use satrs_core::hk::{CollectionIntervalFactor, HkRequest}; use satrs_core::hk::{CollectionIntervalFactor, HkRequest};
use satrs_core::mode::{ModeAndSubmode, ModeRequest}; use satrs_core::mode::{ModeAndSubmode, ModeRequest};
use satrs_core::params::Params; 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::event_man::{EventRequest, EventRequestWithToken};
use satrs_core::pus::hk; use satrs_core::pus::hk;
use satrs_core::pus::mode; use satrs_core::pus::mode;
@ -18,6 +18,7 @@ use satrs_core::pus::verification::{
use satrs_core::pus::{event, GenericTcCheckError}; use satrs_core::pus::{event, GenericTcCheckError};
use satrs_core::res_code::ResultU16; use satrs_core::res_code::ResultU16;
use satrs_core::spacepackets::ecss::{scheduling, PusServiceId}; use satrs_core::spacepackets::ecss::{scheduling, PusServiceId};
use satrs_core::spacepackets::time::CcsdsTimeProvider;
use satrs_core::tmtc::tm_helper::PusTmWithCdsShortHelper; use satrs_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
use satrs_core::tmtc::{AddressableId, PusServiceProvider, TargetId}; use satrs_core::tmtc::{AddressableId, PusServiceProvider, TargetId};
use satrs_core::{ use satrs_core::{
@ -29,7 +30,7 @@ use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::rc::Rc; use std::rc::Rc;
use std::sync::mpsc::Sender; use std::sync::mpsc::{Receiver, Sender};
pub struct PusReceiver { pub struct PusReceiver {
pub tm_helper: PusTmWithCdsShortHelper, pub tm_helper: PusTmWithCdsShortHelper,
@ -53,6 +54,43 @@ impl PusTmArgs {
} }
} }
pub struct PusTcHandlerBase {
pub tc_store: Box<dyn PoolProvider>,
pub receiver: Receiver<(StoreAddr, VerificationToken<TcStateAccepted>)>,
pub verif_reporter: StdVerifReporterWithSender,
pub time_provider: Box<dyn CcsdsTimeProvider>,
}
pub trait TestHandlerNoPing {
fn handle_no_ping_tc(&mut self, tc: PusTc);
}
pub struct PusTestTcHandler {
pub base: PusTcHandlerBase,
handler: Option<Box<dyn TestHandlerNoPing>>,
}
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 struct PusTcArgs {
pub event_request_tx: Sender<EventRequestWithToken>, pub event_request_tx: Sender<EventRequestWithToken>,
/// Request routing helper. Maps targeted requests to their recipient. /// Request routing helper. Maps targeted requests to their recipient.