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

View File

@ -95,13 +95,13 @@ pub struct EventRequestWithToken<Event: GenericEvent = EventU32> {
} }
#[derive(Debug)] #[derive(Debug)]
pub enum EventManError<SenderE> { pub enum EventManError {
EcssTmtcError(EcssTmtcErrorWithSend<SenderE>), EcssTmtcError(EcssTmtcErrorWithSend),
SeverityMissmatch(Severity, Severity), SeverityMissmatch(Severity, Severity),
} }
impl<SenderE> From<EcssTmtcErrorWithSend<SenderE>> for EventManError<SenderE> { impl From<EcssTmtcErrorWithSend> for EventManError {
fn from(v: EcssTmtcErrorWithSend<SenderE>) -> Self { fn from(v: EcssTmtcErrorWithSend) -> Self {
Self::EcssTmtcError(v) Self::EcssTmtcError(v)
} }
} }
@ -175,11 +175,11 @@ pub mod alloc_mod {
pub fn generate_pus_event_tm_generic<E>( pub fn generate_pus_event_tm_generic<E>(
&mut self, &mut self,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event: Event, event: Event,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
) -> Result<bool, EventManError<E>> { ) -> Result<bool, EventManError> {
if !self.backend.event_enabled(&event) { if !self.backend.event_enabled(&event) {
return Ok(false); return Ok(false);
} }
@ -225,11 +225,11 @@ pub mod alloc_mod {
pub fn generate_pus_event_tm<E, Severity: HasSeverity>( pub fn generate_pus_event_tm<E, Severity: HasSeverity>(
&mut self, &mut self,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event: EventU32TypedSev<Severity>, event: EventU32TypedSev<Severity>,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
) -> Result<bool, EventManError<E>> { ) -> Result<bool, EventManError> {
self.generate_pus_event_tm_generic(sender, time_stamp, event.into(), aux_data) 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. /// Generic error type for PUS TM handling.
#[derive(Debug, Clone)] #[derive(Debug, Copy, Clone)]
pub enum EcssTmtcError { pub enum EcssTmtcSendError {
/// Errors related to the time stamp format of the telemetry RxDisconnected,
Timestamp(TimestampError), QueueFull(u32),
/// Errors related to byte conversion, for example insufficient buffer size for given data
ByteConversion(ByteConversionError),
/// Errors related to PUS packet format
Pus(PusError),
} }
impl From<PusError> for EcssTmtcError { // /// Generic error type for PUS TMTC handling.
fn from(e: PusError) -> Self { // #[derive(Debug, Clone)]
EcssTmtcError::Pus(e) // 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
impl From<ByteConversionError> for EcssTmtcError { // ByteConversion(ByteConversionError),
fn from(e: ByteConversionError) -> Self { // /// Errors related to PUS packet format
EcssTmtcError::ByteConversion(e) // 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 { pub trait EcssSender: Send {
/// Each sender can have an ID associated with it /// Each sender can have an ID associated with it
@ -93,24 +88,6 @@ pub trait EcssSender: Send {
"unset" "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")] #[cfg(feature = "alloc")]
mod alloc_mod { mod alloc_mod {
@ -133,8 +110,8 @@ mod alloc_mod {
/// Blanket implementation for all types which implement [EcssTmSenderCore] and are clonable. /// Blanket implementation for all types which implement [EcssTmSenderCore] and are clonable.
impl<T> EcssTmSender for T where T: EcssTmSenderCore + Clone + 'static {} impl<T> EcssTmSender for T where T: EcssTmSenderCore + Clone + 'static {}
dyn_clone::clone_trait_object!(<T> EcssTmSender<Error=T>); dyn_clone::clone_trait_object!(EcssTmSender);
impl_downcast!(EcssTmSender assoc Error); impl_downcast!(EcssTmSender);
/// Extension trait for [EcssTcSenderCore]. /// Extension trait for [EcssTcSenderCore].
/// ///
@ -153,21 +130,22 @@ mod alloc_mod {
/// Blanket implementation for all types which implement [EcssTcSenderCore] and are clonable. /// Blanket implementation for all types which implement [EcssTcSenderCore] and are clonable.
impl<T> EcssTcSender for T where T: EcssTcSenderCore + Clone + 'static {} impl<T> EcssTcSender for T where T: EcssTcSenderCore + Clone + 'static {}
dyn_clone::clone_trait_object!(<T> EcssTcSender<Error=T>); dyn_clone::clone_trait_object!(EcssTcSender);
impl_downcast!(EcssTcSender assoc Error); impl_downcast!(EcssTcSender);
} }
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub mod std_mod { pub mod std_mod {
use crate::pool::{ShareablePoolProvider, SharedPool, StoreAddr, StoreError}; use crate::pool::{ShareablePoolProvider, SharedPool, StoreAddr, StoreError};
use crate::pus::verification::{ 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::tmtc::tm_helper::SharedTmStore;
use crate::SenderId; use crate::SenderId;
use alloc::vec::Vec; use alloc::vec::Vec;
use spacepackets::ecss::{PusError, SerializablePusPacket}; use spacepackets::ecss::{PusError, SerializablePusPacket};
use spacepackets::tc::PusTc;
use spacepackets::time::cds::TimeProvider; use spacepackets::time::cds::TimeProvider;
use spacepackets::time::{StdTimestampError, TimeWriter}; use spacepackets::time::{StdTimestampError, TimeWriter};
use std::cell::RefCell; use std::cell::RefCell;
@ -177,17 +155,36 @@ pub mod std_mod {
use thiserror::Error; use thiserror::Error;
#[derive(Debug, Clone, Error)] #[derive(Debug, Clone, Error)]
pub enum MpscTmInStoreSenderError { pub enum EcssTmtcErrorWithSend {
#[error("RwGuard lock error")] #[error("store locking error")]
StoreLock, StoreLock,
#[error("Generic PUS error: {0}")] #[error("generic store error: {0}")]
Pus(#[from] PusError),
#[error("Generic store error: {0}")]
Store(#[from] StoreError), Store(#[from] StoreError),
#[error("MPSC channel send error: {0}")] #[error("generic PUS error: {0}")]
Send(#[from] mpsc::SendError<StoreAddr>), Pus(#[from] PusError),
#[error("RX handle has disconnected")] #[error("not able to send address {0}")]
RxDisconnected, 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)] #[derive(Clone)]
@ -213,7 +210,7 @@ pub mod std_mod {
pub fn send_direct_tm( pub fn send_direct_tm(
&self, &self,
tmtc: impl SerializablePusPacket, tmtc: impl SerializablePusPacket,
) -> Result<(), MpscTmInStoreSenderError> { ) -> Result<(), EcssTmtcErrorWithSend> {
let operation = |mut store: RwLockWriteGuard<ShareablePoolProvider>| { let operation = |mut store: RwLockWriteGuard<ShareablePoolProvider>| {
let (addr, slice) = store.free_element(tmtc.len_packed())?; let (addr, slice) = store.free_element(tmtc.len_packed())?;
tmtc.write_to_bytes(slice)?; tmtc.write_to_bytes(slice)?;
@ -226,7 +223,9 @@ pub mod std_mod {
if self.ignore_poison_errors { if self.ignore_poison_errors {
operation(e.into_inner()) operation(e.into_inner())
} else { } else {
Err(MpscTmInStoreSenderError::StoreLock) Err(EcssTmtcErrorWithSend::Send(
EcssTmtcSendError::RxDisconnected,
))
} }
} }
} }
@ -234,14 +233,11 @@ pub mod std_mod {
} }
impl EcssTmSenderCore for MpscTmInStoreSender { impl EcssTmSenderCore for MpscTmInStoreSender {
type Error = MpscTmInStoreSenderError; fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcErrorWithSend> {
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), Self::Error> {
match tm { match tm {
PusTmWrapper::InStore(addr) => self PusTmWrapper::InStore(addr) => self.sender.send(addr).map_err(
.sender EcssTmtcErrorWithSend::Send(EcssTmtcSendError::RxDisconnected),
.send(addr) ),
.map_err(MpscTmInStoreSenderError::Send),
PusTmWrapper::Direct(tm) => self.send_direct_tm(tm), PusTmWrapper::Direct(tm) => self.send_direct_tm(tm),
} }
} }
@ -303,11 +299,9 @@ pub mod std_mod {
} }
impl EcssTmSenderCore for MpscTmAsVecSender { impl EcssTmSenderCore for MpscTmAsVecSender {
type Error = MpscTmAsVecSenderError; fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcErrorWithSend> {
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), Self::Error> {
match tm { match tm {
PusTmWrapper::InStore(addr) => Err(MpscTmAsVecSenderError::CantSendAddr(addr)), PusTmWrapper::InStore(addr) => Err(EcssTmtcErrorWithSend::CantSendAddr(addr)),
PusTmWrapper::Direct(tm) => { PusTmWrapper::Direct(tm) => {
let mut vec = Vec::new(); let mut vec = Vec::new();
tm.append_to_vec(&mut vec) 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 { if len > cap {
return Err(EcssTmtcError::ByteConversion( return Err(EcssTmtcErrorWithSend::ByteConversion(
ByteConversionError::ToSliceTooSmall(SizeMissmatch { ByteConversionError::ToSliceTooSmall(SizeMissmatch {
found: cap, found: cap,
expected: len, 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) //! 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 //! for the verification module contains examples how this module could be used in a more complex
//! context involving multiple threads //! context involving multiple threads
use crate::pus::{ use crate::pus::{source_buffer_large_enough, EcssTmSenderCore, EcssTmtcErrorWithSend};
source_buffer_large_enough, EcssTmSenderCore, EcssTmtcError, EcssTmtcErrorWithSend,
};
use core::fmt::{Debug, Display, Formatter}; use core::fmt::{Debug, Display, Formatter};
use core::hash::{Hash, Hasher}; use core::hash::{Hash, Hasher};
use core::marker::PhantomData; 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 /// If a verification operation fails, the passed token will be returned as well. This allows
/// re-trying the operation at a later point. /// re-trying the operation at a later point.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct VerificationOrSendErrorWithToken<E, T>( pub struct VerificationOrSendErrorWithToken<T>(pub EcssTmtcErrorWithSend, pub VerificationToken<T>);
pub EcssTmtcErrorWithSend<E>,
pub VerificationToken<T>,
);
#[derive(Debug, Clone)] #[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 { fn from(value: VerificationErrorWithToken<T>) -> Self {
VerificationOrSendErrorWithToken(value.0.into(), value.1) VerificationOrSendErrorWithToken(value.0.into(), value.1)
} }
@ -517,8 +512,8 @@ impl VerificationReporterCore {
pub fn send_acceptance_success<E>( pub fn send_acceptance_success<E>(
&self, &self,
mut sendable: VerificationSendable<'_, TcStateNone, VerifSuccess>, mut sendable: VerificationSendable<'_, TcStateNone, VerifSuccess>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<E, TcStateNone>> ) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateNone>>
{ {
sender sender
.send_tm(sendable.pus_tm.take().unwrap().into()) .send_tm(sendable.pus_tm.take().unwrap().into())
@ -534,8 +529,8 @@ impl VerificationReporterCore {
pub fn send_acceptance_failure<E>( pub fn send_acceptance_failure<E>(
&self, &self,
mut sendable: VerificationSendable<'_, TcStateNone, VerifFailure>, mut sendable: VerificationSendable<'_, TcStateNone, VerifFailure>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateNone>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcStateNone>> {
sender sender
.send_tm(sendable.pus_tm.take().unwrap().into()) .send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| { .map_err(|e| {
@ -598,11 +593,9 @@ impl VerificationReporterCore {
pub fn send_start_success<E>( pub fn send_start_success<E>(
&self, &self,
mut sendable: VerificationSendable<'_, TcStateAccepted, VerifSuccess>, mut sendable: VerificationSendable<'_, TcStateAccepted, VerifSuccess>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
) -> Result< ) -> Result<VerificationToken<TcStateStarted>, VerificationOrSendErrorWithToken<TcStateAccepted>>
VerificationToken<TcStateStarted>, {
VerificationOrSendErrorWithToken<E, TcStateAccepted>,
> {
sender sender
.send_tm(sendable.pus_tm.take().unwrap().into()) .send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| { .map_err(|e| {
@ -643,8 +636,8 @@ impl VerificationReporterCore {
pub fn send_start_failure<E>( pub fn send_start_failure<E>(
&self, &self,
mut sendable: VerificationSendable<'_, TcStateAccepted, VerifFailure>, mut sendable: VerificationSendable<'_, TcStateAccepted, VerifFailure>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateAccepted>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcStateAccepted>> {
sender sender
.send_tm(sendable.pus_tm.take().unwrap().into()) .send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| { .map_err(|e| {
@ -668,7 +661,8 @@ impl VerificationReporterCore {
msg_count: u16, msg_count: u16,
time_stamp: Option<&'src_data [u8]>, time_stamp: Option<&'src_data [u8]>,
step: impl EcssEnumeration, step: impl EcssEnumeration,
) -> Result<VerificationSendable<'src_data, TcStateStarted, VerifSuccess>, EcssTmtcError> { ) -> Result<VerificationSendable<'src_data, TcStateStarted, VerifSuccess>, EcssTmtcErrorWithSend>
{
Ok(VerificationSendable::new_no_token( Ok(VerificationSendable::new_no_token(
self.create_pus_verif_success_tm( self.create_pus_verif_success_tm(
src_data_buf, 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, &self,
mut sendable: VerificationSendable<'_, TcState, VerifSuccess>, mut sendable: VerificationSendable<'_, TcState, VerifSuccess>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
sender sender
.send_tm(sendable.pus_tm.take().unwrap().into()) .send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| { .map_err(|e| {
@ -780,11 +774,11 @@ impl VerificationReporterCore {
Ok(()) Ok(())
} }
pub fn send_step_or_completion_failure<E, TcState: WasAtLeastAccepted + Copy>( pub fn send_step_or_completion_failure<TcState: WasAtLeastAccepted + Copy>(
&self, &self,
mut sendable: VerificationSendable<'_, TcState, VerifFailure>, mut sendable: VerificationSendable<'_, TcState, VerifFailure>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
sender sender
.send_tm(sendable.pus_tm.take().unwrap().into()) .send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| { .map_err(|e| {
@ -808,7 +802,7 @@ impl VerificationReporterCore {
req_id: &RequestId, req_id: &RequestId,
time_stamp: Option<&'src_data [u8]>, time_stamp: Option<&'src_data [u8]>,
step: Option<&(impl EcssEnumeration + ?Sized)>, step: Option<&(impl EcssEnumeration + ?Sized)>,
) -> Result<PusTm<'src_data>, EcssTmtcError> { ) -> Result<PusTm<'src_data>, EcssTmtcErrorWithSend> {
let mut source_data_len = size_of::<u32>(); let mut source_data_len = size_of::<u32>();
if let Some(step) = step { if let Some(step) = step {
source_data_len += step.size(); source_data_len += step.size();
@ -844,7 +838,7 @@ impl VerificationReporterCore {
req_id: &RequestId, req_id: &RequestId,
step: Option<&(impl EcssEnumeration + ?Sized)>, step: Option<&(impl EcssEnumeration + ?Sized)>,
params: &FailParams<'src_data, '_>, params: &FailParams<'src_data, '_>,
) -> Result<PusTm<'src_data>, EcssTmtcError> { ) -> Result<PusTm<'src_data>, EcssTmtcErrorWithSend> {
let mut idx = 0; let mut idx = 0;
let mut source_data_len = RequestId::SIZE_AS_BYTES + params.failure_code.size(); let mut source_data_len = RequestId::SIZE_AS_BYTES + params.failure_code.size();
if let Some(step) = step { 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 /// 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, &mut self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
) -> Result< ) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateNone>>
VerificationToken<TcStateAccepted>, {
VerificationOrSendErrorWithToken<E, TcStateNone>,
> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1012,9 +1004,9 @@ mod alloc_mod {
pub fn acceptance_failure<E>( pub fn acceptance_failure<E>(
&mut self, &mut self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateNone>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcStateNone>> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1039,11 +1031,11 @@ mod alloc_mod {
pub fn start_success<E>( pub fn start_success<E>(
&mut self, &mut self,
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
) -> Result< ) -> Result<
VerificationToken<TcStateStarted>, VerificationToken<TcStateStarted>,
VerificationOrSendErrorWithToken<E, TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateAccepted>,
> { > {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
@ -1070,9 +1062,9 @@ mod alloc_mod {
pub fn start_failure<E>( pub fn start_failure<E>(
&mut self, &mut self,
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateAccepted>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcStateAccepted>> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1097,10 +1089,10 @@ mod alloc_mod {
pub fn step_success<E>( pub fn step_success<E>(
&mut self, &mut self,
token: &VerificationToken<TcStateStarted>, token: &VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
step: impl EcssEnumeration, step: impl EcssEnumeration,
) -> Result<(), EcssTmtcErrorWithSend<E>> { ) -> Result<(), EcssTmtcErrorWithSend> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1129,9 +1121,9 @@ mod alloc_mod {
pub fn step_failure<E>( pub fn step_failure<E>(
&mut self, &mut self,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
params: FailParamsWithStep, params: FailParamsWithStep,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcStateStarted>> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1155,12 +1147,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, TcState: WasAtLeastAccepted + Copy>( pub fn completion_success<TcState: WasAtLeastAccepted + Copy>(
&mut self, &mut self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1184,12 +1176,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, TcState: WasAtLeastAccepted + Copy>( pub fn completion_failure<TcState: WasAtLeastAccepted + Copy>(
&mut self, &mut self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1213,23 +1205,20 @@ mod alloc_mod {
/// Helper object which caches the sender passed as a trait object. Provides the same /// Helper object which caches the sender passed as a trait object. Provides the same
/// API as [VerificationReporter] but without the explicit sender arguments. /// API as [VerificationReporter] but without the explicit sender arguments.
#[derive(Clone)] #[derive(Clone)]
pub struct VerificationReporterWithSender<E> { pub struct VerificationReporterWithSender {
pub reporter: VerificationReporter, pub reporter: VerificationReporter,
pub sender: Box<dyn EcssTmSender<Error = E>>, pub sender: Box<dyn EcssTmSender>,
} }
impl<E: 'static> VerificationReporterWithSender<E> { impl VerificationReporterWithSender {
pub fn new( pub fn new(cfg: &VerificationReporterCfg, sender: Box<dyn EcssTmSender>) -> Self {
cfg: &VerificationReporterCfg,
sender: Box<dyn EcssTmSender<Error = E>>,
) -> Self {
let reporter = VerificationReporter::new(cfg); let reporter = VerificationReporter::new(cfg);
Self::new_from_reporter(reporter, sender) Self::new_from_reporter(reporter, sender)
} }
pub fn new_from_reporter( pub fn new_from_reporter(
reporter: VerificationReporter, reporter: VerificationReporter,
sender: Box<dyn EcssTmSender<Error = E>>, sender: Box<dyn EcssTmSender>,
) -> Self { ) -> Self {
Self { reporter, sender } Self { reporter, sender }
} }
@ -1249,10 +1238,8 @@ mod alloc_mod {
&mut self, &mut self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
) -> Result< ) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateNone>>
VerificationToken<TcStateAccepted>, {
VerificationOrSendErrorWithToken<E, TcStateNone>,
> {
self.reporter self.reporter
.acceptance_success(token, self.sender.as_mut(), time_stamp) .acceptance_success(token, self.sender.as_mut(), time_stamp)
} }
@ -1261,7 +1248,7 @@ mod alloc_mod {
&mut self, &mut self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateNone>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcStateNone>> {
self.reporter self.reporter
.acceptance_failure(token, self.sender.as_mut(), params) .acceptance_failure(token, self.sender.as_mut(), params)
} }
@ -1272,7 +1259,7 @@ mod alloc_mod {
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
) -> Result< ) -> Result<
VerificationToken<TcStateStarted>, VerificationToken<TcStateStarted>,
VerificationOrSendErrorWithToken<E, TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateAccepted>,
> { > {
self.reporter self.reporter
.start_success(token, self.sender.as_mut(), time_stamp) .start_success(token, self.sender.as_mut(), time_stamp)
@ -1282,7 +1269,7 @@ mod alloc_mod {
&mut self, &mut self,
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateAccepted>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcStateAccepted>> {
self.reporter self.reporter
.start_failure(token, self.sender.as_mut(), params) .start_failure(token, self.sender.as_mut(), params)
} }
@ -1292,7 +1279,7 @@ mod alloc_mod {
token: &VerificationToken<TcStateStarted>, token: &VerificationToken<TcStateStarted>,
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
step: impl EcssEnumeration, step: impl EcssEnumeration,
) -> Result<(), EcssTmtcErrorWithSend<E>> { ) -> Result<(), EcssTmtcErrorWithSend> {
self.reporter self.reporter
.step_success(token, self.sender.as_mut(), time_stamp, step) .step_success(token, self.sender.as_mut(), time_stamp, step)
} }
@ -1301,7 +1288,7 @@ mod alloc_mod {
&mut self, &mut self,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
params: FailParamsWithStep, params: FailParamsWithStep,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcStateStarted>> {
self.reporter self.reporter
.step_failure(token, self.sender.as_mut(), params) .step_failure(token, self.sender.as_mut(), params)
} }
@ -1310,7 +1297,7 @@ mod alloc_mod {
&mut self, &mut self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
time_stamp: Option<&[u8]>, time_stamp: Option<&[u8]>,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
self.reporter self.reporter
.completion_success(token, self.sender.as_mut(), time_stamp) .completion_success(token, self.sender.as_mut(), time_stamp)
} }
@ -1319,7 +1306,7 @@ mod alloc_mod {
&mut self, &mut self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<E, TcState>> { ) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
self.reporter self.reporter
.completion_failure(token, self.sender.as_mut(), params) .completion_failure(token, self.sender.as_mut(), params)
} }
@ -1329,7 +1316,6 @@ mod alloc_mod {
#[cfg(feature = "std")] #[cfg(feature = "std")]
mod std_mod { mod std_mod {
use crate::pus::verification::VerificationReporterWithSender; use crate::pus::verification::VerificationReporterWithSender;
use crate::pus::MpscTmInStoreSenderError;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
// use super::alloc_mod::VerificationReporterWithSender; // use super::alloc_mod::VerificationReporterWithSender;
@ -1341,7 +1327,7 @@ mod std_mod {
// use spacepackets::ecss::SerializablePusPacket; // use spacepackets::ecss::SerializablePusPacket;
// use std::sync::{mpsc, Arc, Mutex, RwLockWriteGuard}; // use std::sync::{mpsc, Arc, Mutex, RwLockWriteGuard};
// //
pub type StdVerifReporterWithSender = VerificationReporterWithSender<MpscTmInStoreSenderError>; pub type StdVerifReporterWithSender = VerificationReporterWithSender;
pub type SharedStdVerifReporterWithSender = Arc<Mutex<StdVerifReporterWithSender>>; pub type SharedStdVerifReporterWithSender = Arc<Mutex<StdVerifReporterWithSender>>;
// //
// trait SendBackend: Send { // trait SendBackend: Send {
@ -1525,8 +1511,8 @@ mod tests {
use crate::pool::{LocalPool, PoolCfg, SharedPool}; use crate::pool::{LocalPool, PoolCfg, SharedPool};
use crate::pus::tests::CommonTmInfo; use crate::pus::tests::CommonTmInfo;
use crate::pus::verification::{ use crate::pus::verification::{
EcssTmSenderCore, EcssTmtcError, FailParams, FailParamsWithStep, RequestId, TcStateNone, EcssTmSenderCore, EcssTmtcErrorWithSend, FailParams, FailParamsWithStep, RequestId,
VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender, TcStateNone, VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
VerificationToken, VerificationToken,
}; };
use crate::pus::{EcssSender, EcssTmtcErrorWithSend, MpscTmInStoreSender, PusTmWrapper}; use crate::pus::{EcssSender, EcssTmtcErrorWithSend, MpscTmInStoreSender, PusTmWrapper};
@ -1819,18 +1805,20 @@ mod tests {
let err_with_token = res.unwrap_err(); let err_with_token = res.unwrap_err();
assert_eq!(err_with_token.1, tok); assert_eq!(err_with_token.1, tok);
match err_with_token.0 { match err_with_token.0 {
EcssTmtcErrorWithSend::EcssTmtcError(EcssTmtcError::ByteConversion(e)) => match e { EcssTmtcErrorWithSend::EcssTmtcError(EcssTmtcErrorWithSend::ByteConversion(e)) => {
ByteConversionError::ToSliceTooSmall(missmatch) => { match e {
assert_eq!( ByteConversionError::ToSliceTooSmall(missmatch) => {
missmatch.expected, assert_eq!(
fail_data.len() + RequestId::SIZE_AS_BYTES + fail_code.size() missmatch.expected,
); fail_data.len() + RequestId::SIZE_AS_BYTES + fail_code.size()
assert_eq!(missmatch.found, b.rep().allowed_source_data_len()); );
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)) panic!("{}", format!("Unexpected error {:?}", err_with_token.0))
} }