well this simplifies a lot..

This commit is contained in:
Robin Müller 2023-07-09 13:04:00 +02:00
parent d59718bb04
commit 1389ee462e
Signed by: muellerr
GPG Key ID: A649FB78196E3849
4 changed files with 186 additions and 203 deletions

View File

@ -1,4 +1,4 @@
use crate::pus::{source_buffer_large_enough, EcssTmtcError, EcssTmtcErrorWithSend};
use crate::pus::{source_buffer_large_enough, EcssTmtcErrorWithSend};
use spacepackets::ecss::EcssEnumeration;
use spacepackets::tm::PusTm;
use spacepackets::tm::PusTmSecondaryHeader;
@ -6,7 +6,7 @@ use spacepackets::{SpHeader, MAX_APID};
use crate::pus::EcssTmSenderCore;
#[cfg(feature = "alloc")]
pub use allocvec::EventReporter;
pub use alloc_mod::EventReporter;
pub use spacepackets::ecss::event::*;
pub struct EventReporterBase {
@ -27,14 +27,14 @@ impl EventReporterBase {
})
}
pub fn event_info<E>(
pub fn event_info(
&mut self,
buf: &mut [u8],
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcErrorWithSend<E>> {
) -> Result<(), EcssTmtcErrorWithSend> {
self.generate_and_send_generic_tm(
buf,
Subservice::TmInfoReport,
@ -45,14 +45,14 @@ impl EventReporterBase {
)
}
pub fn event_low_severity<E>(
pub fn event_low_severity(
&mut self,
buf: &mut [u8],
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcErrorWithSend<E>> {
) -> Result<(), EcssTmtcErrorWithSend> {
self.generate_and_send_generic_tm(
buf,
Subservice::TmLowSeverityReport,
@ -63,14 +63,14 @@ impl EventReporterBase {
)
}
pub fn event_medium_severity<E>(
pub fn event_medium_severity(
&mut self,
buf: &mut [u8],
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcErrorWithSend<E>> {
) -> Result<(), EcssTmtcErrorWithSend> {
self.generate_and_send_generic_tm(
buf,
Subservice::TmMediumSeverityReport,
@ -81,14 +81,14 @@ impl EventReporterBase {
)
}
pub fn event_high_severity<E>(
pub fn event_high_severity(
&mut self,
buf: &mut [u8],
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcErrorWithSend<E>> {
) -> Result<(), EcssTmtcErrorWithSend> {
self.generate_and_send_generic_tm(
buf,
Subservice::TmHighSeverityReport,
@ -103,11 +103,11 @@ impl EventReporterBase {
&mut self,
buf: &mut [u8],
subservice: Subservice,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcErrorWithSend<E>> {
) -> Result<(), EcssTmtcErrorWithSend> {
let tm = self.generate_generic_event_tm(buf, subservice, time_stamp, event_id, aux_data)?;
sender
.send_tm(tm.into())
@ -123,7 +123,7 @@ impl EventReporterBase {
time_stamp: &'a [u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<PusTm, EcssTmtcError> {
) -> Result<PusTm, EcssTmtcErrorWithSend> {
let mut src_data_len = event_id.size();
if let Some(aux_data) = aux_data {
src_data_len += aux_data.len();
@ -154,7 +154,7 @@ impl EventReporterBase {
}
#[cfg(feature = "alloc")]
mod allocvec {
mod alloc_mod {
use super::*;
use alloc::vec;
use alloc::vec::Vec;
@ -174,11 +174,11 @@ mod allocvec {
}
pub fn event_info<E>(
&mut self,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcErrorWithSend<E>> {
) -> Result<(), EcssTmtcErrorWithSend> {
self.reporter.event_info(
self.source_data_buf.as_mut_slice(),
sender,
@ -190,11 +190,11 @@ mod allocvec {
pub fn event_low_severity<E>(
&mut self,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcErrorWithSend<E>> {
) -> Result<(), EcssTmtcErrorWithSend> {
self.reporter.event_low_severity(
self.source_data_buf.as_mut_slice(),
sender,
@ -206,11 +206,11 @@ mod allocvec {
pub fn event_medium_severity<E>(
&mut self,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcErrorWithSend<E>> {
) -> Result<(), EcssTmtcErrorWithSend> {
self.reporter.event_medium_severity(
self.source_data_buf.as_mut_slice(),
sender,
@ -222,11 +222,11 @@ mod allocvec {
pub fn event_high_severity<E>(
&mut self,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcErrorWithSend<E>> {
) -> Result<(), EcssTmtcErrorWithSend> {
self.reporter.event_high_severity(
self.source_data_buf.as_mut_slice(),
sender,
@ -275,9 +275,7 @@ mod tests {
}
impl EcssTmSenderCore for TestSender {
type Error = ();
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), Self::Error> {
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcErrorWithSend> {
match tm {
PusTmWrapper::InStore(_) => {
panic!("TestSender: unexpected call with address");
@ -427,7 +425,7 @@ mod tests {
let err = reporter.event_info(sender, &time_stamp_empty, event, None);
assert!(err.is_err());
let err = err.unwrap_err();
if let EcssTmtcErrorWithSend::EcssTmtcError(EcssTmtcError::ByteConversion(
if let EcssTmtcErrorWithSend::EcssTmtcError(EcssTmtcErrorWithSend::ByteConversion(
ByteConversionError::ToSliceTooSmall(missmatch),
)) = err
{

View File

@ -95,13 +95,13 @@ pub struct EventRequestWithToken<Event: GenericEvent = EventU32> {
}
#[derive(Debug)]
pub enum EventManError<SenderE> {
EcssTmtcError(EcssTmtcErrorWithSend<SenderE>),
pub enum EventManError {
EcssTmtcError(EcssTmtcErrorWithSend),
SeverityMissmatch(Severity, Severity),
}
impl<SenderE> From<EcssTmtcErrorWithSend<SenderE>> for EventManError<SenderE> {
fn from(v: EcssTmtcErrorWithSend<SenderE>) -> Self {
impl From<EcssTmtcErrorWithSend> for EventManError {
fn from(v: EcssTmtcErrorWithSend) -> Self {
Self::EcssTmtcError(v)
}
}
@ -175,11 +175,11 @@ pub mod alloc_mod {
pub fn generate_pus_event_tm_generic<E>(
&mut self,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8],
event: Event,
aux_data: Option<&[u8]>,
) -> Result<bool, EventManError<E>> {
) -> Result<bool, EventManError> {
if !self.backend.event_enabled(&event) {
return Ok(false);
}
@ -225,11 +225,11 @@ pub mod alloc_mod {
pub fn generate_pus_event_tm<E, Severity: HasSeverity>(
&mut self,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8],
event: EventU32TypedSev<Severity>,
aux_data: Option<&[u8]>,
) -> Result<bool, EventManError<E>> {
) -> Result<bool, EventManError> {
self.generate_pus_event_tm_generic(sender, time_stamp, event.into(), aux_data)
}
}

View File

@ -50,41 +50,36 @@ impl<'tm> From<PusTm<'tm>> for PusTmWrapper<'tm> {
}
}
#[derive(Debug, Clone)]
pub enum EcssTmtcErrorWithSend<E> {
/// Errors related to sending the telemetry to a TMTC recipient
SendError(E),
EcssTmtcError(EcssTmtcError),
}
impl<E> From<EcssTmtcError> for EcssTmtcErrorWithSend<E> {
fn from(value: EcssTmtcError) -> Self {
Self::EcssTmtcError(value)
}
}
/// Generic error type for PUS TM handling.
#[derive(Debug, Clone)]
pub enum EcssTmtcError {
/// Errors related to the time stamp format of the telemetry
Timestamp(TimestampError),
/// Errors related to byte conversion, for example insufficient buffer size for given data
ByteConversion(ByteConversionError),
/// Errors related to PUS packet format
Pus(PusError),
#[derive(Debug, Copy, Clone)]
pub enum EcssTmtcSendError {
RxDisconnected,
QueueFull(u32),
}
impl From<PusError> for EcssTmtcError {
fn from(e: PusError) -> Self {
EcssTmtcError::Pus(e)
}
}
impl From<ByteConversionError> for EcssTmtcError {
fn from(e: ByteConversionError) -> Self {
EcssTmtcError::ByteConversion(e)
}
}
// /// Generic error type for PUS TMTC handling.
// #[derive(Debug, Clone)]
// pub enum EcssTmtcErrorWithSend {
// /// Errors related to the time stamp format of the telemetry
// Timestamp(TimestampError),
// /// Errors related to byte conversion, for example insufficient buffer size for given data
// ByteConversion(ByteConversionError),
// /// Errors related to PUS packet format
// Pus(PusError),
// Send(EcssTmtcSendError)
// }
//
// impl From<PusError> for EcssTmtcErrorWithSend {
// fn from(e: PusError) -> Self {
// EcssTmtcErrorWithSend::Pus(e)
// }
// }
//
// impl From<ByteConversionError> for EcssTmtcErrorWithSend {
// fn from(e: ByteConversionError) -> Self {
// EcssTmtcErrorWithSend::ByteConversion(e)
// }
// }
pub trait EcssSender: Send {
/// Each sender can have an ID associated with it
@ -93,24 +88,6 @@ pub trait EcssSender: Send {
"unset"
}
}
/// Generic trait for a user supplied sender object.
///
/// This sender object is responsible for sending PUS telemetry to a TM sink.
pub trait EcssTmSenderCore: EcssSender {
type Error;
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), Self::Error>;
}
/// Generic trait for a user supplied sender object.
///
/// This sender object is responsible for sending PUS telecommands to a TC recipient. Each
/// telecommand can optionally have a token which contains its verification state.
pub trait EcssTcSenderCore: EcssSender {
type Error;
fn send_tc(&self, tc: PusTc, token: Option<TcStateToken>) -> Result<(), Self::Error>;
}
#[cfg(feature = "alloc")]
mod alloc_mod {
@ -133,8 +110,8 @@ mod alloc_mod {
/// Blanket implementation for all types which implement [EcssTmSenderCore] and are clonable.
impl<T> EcssTmSender for T where T: EcssTmSenderCore + Clone + 'static {}
dyn_clone::clone_trait_object!(<T> EcssTmSender<Error=T>);
impl_downcast!(EcssTmSender assoc Error);
dyn_clone::clone_trait_object!(EcssTmSender);
impl_downcast!(EcssTmSender);
/// Extension trait for [EcssTcSenderCore].
///
@ -153,21 +130,22 @@ mod alloc_mod {
/// Blanket implementation for all types which implement [EcssTcSenderCore] and are clonable.
impl<T> EcssTcSender for T where T: EcssTcSenderCore + Clone + 'static {}
dyn_clone::clone_trait_object!(<T> EcssTcSender<Error=T>);
impl_downcast!(EcssTcSender assoc Error);
dyn_clone::clone_trait_object!(EcssTcSender);
impl_downcast!(EcssTcSender);
}
#[cfg(feature = "std")]
pub mod std_mod {
use crate::pool::{ShareablePoolProvider, SharedPool, StoreAddr, StoreError};
use crate::pus::verification::{
StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
StdVerifReporterWithSender, TcStateAccepted, TcStateToken, VerificationToken,
};
use crate::pus::{EcssSender, EcssTmSenderCore, PusTmWrapper};
use crate::pus::{EcssSender, EcssTmtcSendError, PusTmWrapper};
use crate::tmtc::tm_helper::SharedTmStore;
use crate::SenderId;
use alloc::vec::Vec;
use spacepackets::ecss::{PusError, SerializablePusPacket};
use spacepackets::tc::PusTc;
use spacepackets::time::cds::TimeProvider;
use spacepackets::time::{StdTimestampError, TimeWriter};
use std::cell::RefCell;
@ -177,17 +155,36 @@ pub mod std_mod {
use thiserror::Error;
#[derive(Debug, Clone, Error)]
pub enum MpscTmInStoreSenderError {
#[error("RwGuard lock error")]
pub enum EcssTmtcErrorWithSend {
#[error("store locking error")]
StoreLock,
#[error("Generic PUS error: {0}")]
Pus(#[from] PusError),
#[error("Generic store error: {0}")]
#[error("generic store error: {0}")]
Store(#[from] StoreError),
#[error("MPSC channel send error: {0}")]
Send(#[from] mpsc::SendError<StoreAddr>),
#[error("RX handle has disconnected")]
RxDisconnected,
#[error("generic PUS error: {0}")]
Pus(#[from] PusError),
#[error("not able to send address {0}")]
CantSendAddr(StoreAddr),
#[error("generic channel send error: {0}")]
Send(#[from] EcssTmtcSendError),
}
/// Generic trait for a user supplied sender object.
///
/// This sender object is responsible for sending PUS telemetry to a TM sink.
pub trait EcssTmSenderCore: EcssSender {
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcErrorWithSend>;
}
/// Generic trait for a user supplied sender object.
///
/// This sender object is responsible for sending PUS telecommands to a TC recipient. Each
/// telecommand can optionally have a token which contains its verification state.
pub trait EcssTcSenderCore: EcssSender {
fn send_tc(
&self,
tc: PusTc,
token: Option<TcStateToken>,
) -> Result<(), EcssTmtcErrorWithSend>;
}
#[derive(Clone)]
@ -213,7 +210,7 @@ pub mod std_mod {
pub fn send_direct_tm(
&self,
tmtc: impl SerializablePusPacket,
) -> Result<(), MpscTmInStoreSenderError> {
) -> Result<(), EcssTmtcErrorWithSend> {
let operation = |mut store: RwLockWriteGuard<ShareablePoolProvider>| {
let (addr, slice) = store.free_element(tmtc.len_packed())?;
tmtc.write_to_bytes(slice)?;
@ -226,7 +223,9 @@ pub mod std_mod {
if self.ignore_poison_errors {
operation(e.into_inner())
} else {
Err(MpscTmInStoreSenderError::StoreLock)
Err(EcssTmtcErrorWithSend::Send(
EcssTmtcSendError::RxDisconnected,
))
}
}
}
@ -234,14 +233,11 @@ pub mod std_mod {
}
impl EcssTmSenderCore for MpscTmInStoreSender {
type Error = MpscTmInStoreSenderError;
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), Self::Error> {
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcErrorWithSend> {
match tm {
PusTmWrapper::InStore(addr) => self
.sender
.send(addr)
.map_err(MpscTmInStoreSenderError::Send),
PusTmWrapper::InStore(addr) => self.sender.send(addr).map_err(
EcssTmtcErrorWithSend::Send(EcssTmtcSendError::RxDisconnected),
),
PusTmWrapper::Direct(tm) => self.send_direct_tm(tm),
}
}
@ -303,11 +299,9 @@ pub mod std_mod {
}
impl EcssTmSenderCore for MpscTmAsVecSender {
type Error = MpscTmAsVecSenderError;
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), Self::Error> {
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcErrorWithSend> {
match tm {
PusTmWrapper::InStore(addr) => Err(MpscTmAsVecSenderError::CantSendAddr(addr)),
PusTmWrapper::InStore(addr) => Err(EcssTmtcErrorWithSend::CantSendAddr(addr)),
PusTmWrapper::Direct(tm) => {
let mut vec = Vec::new();
tm.append_to_vec(&mut vec)
@ -470,9 +464,12 @@ pub mod std_mod {
}
}
pub(crate) fn source_buffer_large_enough(cap: usize, len: usize) -> Result<(), EcssTmtcError> {
pub(crate) fn source_buffer_large_enough(
cap: usize,
len: usize,
) -> Result<(), EcssTmtcErrorWithSend> {
if len > cap {
return Err(EcssTmtcError::ByteConversion(
return Err(EcssTmtcErrorWithSend::ByteConversion(
ByteConversionError::ToSliceTooSmall(SizeMissmatch {
found: cap,
expected: len,

View File

@ -73,9 +73,7 @@
//! The [integration test](https://egit.irs.uni-stuttgart.de/rust/fsrc-launchpad/src/branch/main/fsrc-core/tests/verification_test.rs)
//! for the verification module contains examples how this module could be used in a more complex
//! context involving multiple threads
use crate::pus::{
source_buffer_large_enough, EcssTmSenderCore, EcssTmtcError, EcssTmtcErrorWithSend,
};
use crate::pus::{source_buffer_large_enough, EcssTmSenderCore, EcssTmtcErrorWithSend};
use core::fmt::{Debug, Display, Formatter};
use core::hash::{Hash, Hasher};
use core::marker::PhantomData;
@ -174,15 +172,12 @@ impl RequestId {
/// If a verification operation fails, the passed token will be returned as well. This allows
/// re-trying the operation at a later point.
#[derive(Debug, Clone)]
pub struct VerificationOrSendErrorWithToken<E, T>(
pub EcssTmtcErrorWithSend<E>,
pub VerificationToken<T>,
);
pub struct VerificationOrSendErrorWithToken<T>(pub EcssTmtcErrorWithSend, pub VerificationToken<T>);
#[derive(Debug, Clone)]
pub struct VerificationErrorWithToken<T>(pub EcssTmtcError, pub VerificationToken<T>);
pub struct VerificationErrorWithToken<T>(pub EcssTmtcErrorWithSend, pub VerificationToken<T>);
impl<E, T> From<VerificationErrorWithToken<T>> for VerificationOrSendErrorWithToken<E, T> {
impl<T> From<VerificationErrorWithToken<T>> for VerificationOrSendErrorWithToken<T> {
fn from(value: VerificationErrorWithToken<T>) -> Self {
VerificationOrSendErrorWithToken(value.0.into(), value.1)
}
@ -517,8 +512,8 @@ impl VerificationReporterCore {
pub fn send_acceptance_success<E>(
&self,
mut sendable: VerificationSendable<'_, TcStateNone, VerifSuccess>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<E, TcStateNone>>
sender: &mut (impl EcssTmSenderCore + ?Sized),
) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateNone>>
{
sender
.send_tm(sendable.pus_tm.take().unwrap().into())
@ -534,8 +529,8 @@ impl VerificationReporterCore {
pub fn send_acceptance_failure<E>(
&self,
mut sendable: VerificationSendable<'_, TcStateNone, VerifFailure>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateNone>> {
sender: &mut (impl EcssTmSenderCore + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<TcStateNone>> {
sender
.send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| {
@ -598,11 +593,9 @@ impl VerificationReporterCore {
pub fn send_start_success<E>(
&self,
mut sendable: VerificationSendable<'_, TcStateAccepted, VerifSuccess>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
) -> Result<
VerificationToken<TcStateStarted>,
VerificationOrSendErrorWithToken<E, TcStateAccepted>,
> {
sender: &mut (impl EcssTmSenderCore + ?Sized),
) -> Result<VerificationToken<TcStateStarted>, VerificationOrSendErrorWithToken<TcStateAccepted>>
{
sender
.send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| {
@ -643,8 +636,8 @@ impl VerificationReporterCore {
pub fn send_start_failure<E>(
&self,
mut sendable: VerificationSendable<'_, TcStateAccepted, VerifFailure>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateAccepted>> {
sender: &mut (impl EcssTmSenderCore + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<TcStateAccepted>> {
sender
.send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| {
@ -668,7 +661,8 @@ impl VerificationReporterCore {
msg_count: u16,
time_stamp: Option<&'src_data [u8]>,
step: impl EcssEnumeration,
) -> Result<VerificationSendable<'src_data, TcStateStarted, VerifSuccess>, EcssTmtcError> {
) -> Result<VerificationSendable<'src_data, TcStateStarted, VerifSuccess>, EcssTmtcErrorWithSend>
{
Ok(VerificationSendable::new_no_token(
self.create_pus_verif_success_tm(
src_data_buf,
@ -763,11 +757,11 @@ impl VerificationReporterCore {
)
}
pub fn send_step_or_completion_success<E, TcState: WasAtLeastAccepted + Copy>(
pub fn send_step_or_completion_success<TcState: WasAtLeastAccepted + Copy>(
&self,
mut sendable: VerificationSendable<'_, TcState, VerifSuccess>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> {
sender: &mut (impl EcssTmSenderCore + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
sender
.send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| {
@ -780,11 +774,11 @@ impl VerificationReporterCore {
Ok(())
}
pub fn send_step_or_completion_failure<E, TcState: WasAtLeastAccepted + Copy>(
pub fn send_step_or_completion_failure<TcState: WasAtLeastAccepted + Copy>(
&self,
mut sendable: VerificationSendable<'_, TcState, VerifFailure>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> {
sender: &mut (impl EcssTmSenderCore + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
sender
.send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| {
@ -808,7 +802,7 @@ impl VerificationReporterCore {
req_id: &RequestId,
time_stamp: Option<&'src_data [u8]>,
step: Option<&(impl EcssEnumeration + ?Sized)>,
) -> Result<PusTm<'src_data>, EcssTmtcError> {
) -> Result<PusTm<'src_data>, EcssTmtcErrorWithSend> {
let mut source_data_len = size_of::<u32>();
if let Some(step) = step {
source_data_len += step.size();
@ -844,7 +838,7 @@ impl VerificationReporterCore {
req_id: &RequestId,
step: Option<&(impl EcssEnumeration + ?Sized)>,
params: &FailParams<'src_data, '_>,
) -> Result<PusTm<'src_data>, EcssTmtcError> {
) -> Result<PusTm<'src_data>, EcssTmtcErrorWithSend> {
let mut idx = 0;
let mut source_data_len = RequestId::SIZE_AS_BYTES + params.failure_code.size();
if let Some(step) = step {
@ -981,15 +975,13 @@ mod alloc_mod {
}
/// Package and send a PUS TM\[1, 1\] packet, see 8.1.2.1 of the PUS standard
pub fn acceptance_success<E>(
pub fn acceptance_success(
&mut self,
token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: Option<&[u8]>,
) -> Result<
VerificationToken<TcStateAccepted>,
VerificationOrSendErrorWithToken<E, TcStateNone>,
> {
) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateNone>>
{
let seq_count = self
.seq_count_provider
.as_ref()
@ -1012,9 +1004,9 @@ mod alloc_mod {
pub fn acceptance_failure<E>(
&mut self,
token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateNone>> {
) -> Result<(), VerificationOrSendErrorWithToken<TcStateNone>> {
let seq_count = self
.seq_count_provider
.as_ref()
@ -1039,11 +1031,11 @@ mod alloc_mod {
pub fn start_success<E>(
&mut self,
token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: Option<&[u8]>,
) -> Result<
VerificationToken<TcStateStarted>,
VerificationOrSendErrorWithToken<E, TcStateAccepted>,
VerificationOrSendErrorWithToken<TcStateAccepted>,
> {
let seq_count = self
.seq_count_provider
@ -1070,9 +1062,9 @@ mod alloc_mod {
pub fn start_failure<E>(
&mut self,
token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateAccepted>> {
) -> Result<(), VerificationOrSendErrorWithToken<TcStateAccepted>> {
let seq_count = self
.seq_count_provider
.as_ref()
@ -1097,10 +1089,10 @@ mod alloc_mod {
pub fn step_success<E>(
&mut self,
token: &VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: Option<&[u8]>,
step: impl EcssEnumeration,
) -> Result<(), EcssTmtcErrorWithSend<E>> {
) -> Result<(), EcssTmtcErrorWithSend> {
let seq_count = self
.seq_count_provider
.as_ref()
@ -1129,9 +1121,9 @@ mod alloc_mod {
pub fn step_failure<E>(
&mut self,
token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
params: FailParamsWithStep,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateStarted>> {
) -> Result<(), VerificationOrSendErrorWithToken<TcStateStarted>> {
let seq_count = self
.seq_count_provider
.as_ref()
@ -1155,12 +1147,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<E, TcState: WasAtLeastAccepted + Copy>(
pub fn completion_success<TcState: WasAtLeastAccepted + Copy>(
&mut self,
token: VerificationToken<TcState>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: Option<&[u8]>,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> {
) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
let seq_count = self
.seq_count_provider
.as_ref()
@ -1184,12 +1176,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<E, TcState: WasAtLeastAccepted + Copy>(
pub fn completion_failure<TcState: WasAtLeastAccepted + Copy>(
&mut self,
token: VerificationToken<TcState>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
sender: &mut (impl EcssTmSenderCore + ?Sized),
params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> {
) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
let seq_count = self
.seq_count_provider
.as_ref()
@ -1213,23 +1205,20 @@ mod alloc_mod {
/// Helper object which caches the sender passed as a trait object. Provides the same
/// API as [VerificationReporter] but without the explicit sender arguments.
#[derive(Clone)]
pub struct VerificationReporterWithSender<E> {
pub struct VerificationReporterWithSender {
pub reporter: VerificationReporter,
pub sender: Box<dyn EcssTmSender<Error = E>>,
pub sender: Box<dyn EcssTmSender>,
}
impl<E: 'static> VerificationReporterWithSender<E> {
pub fn new(
cfg: &VerificationReporterCfg,
sender: Box<dyn EcssTmSender<Error = E>>,
) -> Self {
impl VerificationReporterWithSender {
pub fn new(cfg: &VerificationReporterCfg, sender: Box<dyn EcssTmSender>) -> Self {
let reporter = VerificationReporter::new(cfg);
Self::new_from_reporter(reporter, sender)
}
pub fn new_from_reporter(
reporter: VerificationReporter,
sender: Box<dyn EcssTmSender<Error = E>>,
sender: Box<dyn EcssTmSender>,
) -> Self {
Self { reporter, sender }
}
@ -1249,10 +1238,8 @@ mod alloc_mod {
&mut self,
token: VerificationToken<TcStateNone>,
time_stamp: Option<&[u8]>,
) -> Result<
VerificationToken<TcStateAccepted>,
VerificationOrSendErrorWithToken<E, TcStateNone>,
> {
) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateNone>>
{
self.reporter
.acceptance_success(token, self.sender.as_mut(), time_stamp)
}
@ -1261,7 +1248,7 @@ mod alloc_mod {
&mut self,
token: VerificationToken<TcStateNone>,
params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateNone>> {
) -> Result<(), VerificationOrSendErrorWithToken<TcStateNone>> {
self.reporter
.acceptance_failure(token, self.sender.as_mut(), params)
}
@ -1272,7 +1259,7 @@ mod alloc_mod {
time_stamp: Option<&[u8]>,
) -> Result<
VerificationToken<TcStateStarted>,
VerificationOrSendErrorWithToken<E, TcStateAccepted>,
VerificationOrSendErrorWithToken<TcStateAccepted>,
> {
self.reporter
.start_success(token, self.sender.as_mut(), time_stamp)
@ -1282,7 +1269,7 @@ mod alloc_mod {
&mut self,
token: VerificationToken<TcStateAccepted>,
params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateAccepted>> {
) -> Result<(), VerificationOrSendErrorWithToken<TcStateAccepted>> {
self.reporter
.start_failure(token, self.sender.as_mut(), params)
}
@ -1292,7 +1279,7 @@ mod alloc_mod {
token: &VerificationToken<TcStateStarted>,
time_stamp: Option<&[u8]>,
step: impl EcssEnumeration,
) -> Result<(), EcssTmtcErrorWithSend<E>> {
) -> Result<(), EcssTmtcErrorWithSend> {
self.reporter
.step_success(token, self.sender.as_mut(), time_stamp, step)
}
@ -1301,7 +1288,7 @@ mod alloc_mod {
&mut self,
token: VerificationToken<TcStateStarted>,
params: FailParamsWithStep,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateStarted>> {
) -> Result<(), VerificationOrSendErrorWithToken<TcStateStarted>> {
self.reporter
.step_failure(token, self.sender.as_mut(), params)
}
@ -1310,7 +1297,7 @@ mod alloc_mod {
&mut self,
token: VerificationToken<TcState>,
time_stamp: Option<&[u8]>,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> {
) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
self.reporter
.completion_success(token, self.sender.as_mut(), time_stamp)
}
@ -1319,7 +1306,7 @@ mod alloc_mod {
&mut self,
token: VerificationToken<TcState>,
params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> {
) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
self.reporter
.completion_failure(token, self.sender.as_mut(), params)
}
@ -1329,7 +1316,6 @@ mod alloc_mod {
#[cfg(feature = "std")]
mod std_mod {
use crate::pus::verification::VerificationReporterWithSender;
use crate::pus::MpscTmInStoreSenderError;
use std::sync::{Arc, Mutex};
// use super::alloc_mod::VerificationReporterWithSender;
@ -1341,7 +1327,7 @@ mod std_mod {
// use spacepackets::ecss::SerializablePusPacket;
// use std::sync::{mpsc, Arc, Mutex, RwLockWriteGuard};
//
pub type StdVerifReporterWithSender = VerificationReporterWithSender<MpscTmInStoreSenderError>;
pub type StdVerifReporterWithSender = VerificationReporterWithSender;
pub type SharedStdVerifReporterWithSender = Arc<Mutex<StdVerifReporterWithSender>>;
//
// trait SendBackend: Send {
@ -1525,8 +1511,8 @@ mod tests {
use crate::pool::{LocalPool, PoolCfg, SharedPool};
use crate::pus::tests::CommonTmInfo;
use crate::pus::verification::{
EcssTmSenderCore, EcssTmtcError, FailParams, FailParamsWithStep, RequestId, TcStateNone,
VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
EcssTmSenderCore, EcssTmtcErrorWithSend, FailParams, FailParamsWithStep, RequestId,
TcStateNone, VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
VerificationToken,
};
use crate::pus::{EcssSender, EcssTmtcErrorWithSend, MpscTmInStoreSender, PusTmWrapper};
@ -1819,18 +1805,20 @@ mod tests {
let err_with_token = res.unwrap_err();
assert_eq!(err_with_token.1, tok);
match err_with_token.0 {
EcssTmtcErrorWithSend::EcssTmtcError(EcssTmtcError::ByteConversion(e)) => match e {
ByteConversionError::ToSliceTooSmall(missmatch) => {
assert_eq!(
missmatch.expected,
fail_data.len() + RequestId::SIZE_AS_BYTES + fail_code.size()
);
assert_eq!(missmatch.found, b.rep().allowed_source_data_len());
EcssTmtcErrorWithSend::EcssTmtcError(EcssTmtcErrorWithSend::ByteConversion(e)) => {
match e {
ByteConversionError::ToSliceTooSmall(missmatch) => {
assert_eq!(
missmatch.expected,
fail_data.len() + RequestId::SIZE_AS_BYTES + fail_code.size()
);
assert_eq!(missmatch.found, b.rep().allowed_source_data_len());
}
_ => {
panic!("{}", format!("Unexpected error {:?}", e))
}
}
_ => {
panic!("{}", format!("Unexpected error {:?}", e))
}
},
}
_ => {
panic!("{}", format!("Unexpected error {:?}", err_with_token.0))
}