Simplify low level PUS API #145

Merged
muellerr merged 1 commits from simplify-low-level-pus-api into main 2024-03-29 23:41:14 +01:00
18 changed files with 547 additions and 736 deletions

View File

@ -25,7 +25,7 @@ path = "../satrs"
[dependencies.satrs-mib] [dependencies.satrs-mib]
version = "0.1.1" version = "0.1.1"
# path = "../satrs-mib" path = "../satrs-mib"
[features] [features]
dyn_tmtc = [] dyn_tmtc = []

View File

@ -9,7 +9,7 @@ use satrs::{
hk::HkRequest, hk::HkRequest,
spacepackets::{ spacepackets::{
ecss::tm::{PusTmCreator, PusTmSecondaryHeader}, ecss::tm::{PusTmCreator, PusTmSecondaryHeader},
time::cds::{DaysLen16Bits, TimeProvider}, time::cds::{CdsTime, DaysLen16Bits},
SequenceFlags, SpHeader, SequenceFlags, SpHeader,
}, },
}; };
@ -23,7 +23,7 @@ use crate::{
pub struct AcsTask<VerificationReporter: VerificationReportingProvider> { pub struct AcsTask<VerificationReporter: VerificationReportingProvider> {
timestamp: [u8; 7], timestamp: [u8; 7],
time_provider: TimeProvider<DaysLen16Bits>, time_provider: CdsTime<DaysLen16Bits>,
verif_reporter: VerificationReporter, verif_reporter: VerificationReporter,
tm_sender: Box<dyn EcssTmSender>, tm_sender: Box<dyn EcssTmSender>,
request_rx: mpsc::Receiver<RequestWithToken>, request_rx: mpsc::Receiver<RequestWithToken>,
@ -37,7 +37,7 @@ impl<VerificationReporter: VerificationReportingProvider> AcsTask<VerificationRe
) -> Self { ) -> Self {
Self { Self {
timestamp: [0; 7], timestamp: [0; 7],
time_provider: TimeProvider::new_with_u16_days(0, 0), time_provider: CdsTime::new_with_u16_days(0, 0),
verif_reporter, verif_reporter,
tm_sender: Box::new(tm_sender), tm_sender: Box::new(tm_sender),
request_rx, request_rx,

View File

@ -14,7 +14,7 @@ use satrs::{
verification::{TcStateStarted, VerificationReportingProvider, VerificationToken}, verification::{TcStateStarted, VerificationReportingProvider, VerificationToken},
EcssTmSender, EcssTmSender,
}, },
spacepackets::time::cds::{self, TimeProvider}, spacepackets::time::cds::{self, CdsTime},
}; };
use satrs_example::config::PUS_APID; use satrs_example::config::PUS_APID;
@ -25,7 +25,7 @@ pub struct PusEventHandler<VerificationReporter: VerificationReportingProvider>
pus_event_dispatcher: DefaultPusEventU32Dispatcher<()>, pus_event_dispatcher: DefaultPusEventU32Dispatcher<()>,
pus_event_man_rx: mpsc::Receiver<(EventU32, Option<Params>)>, pus_event_man_rx: mpsc::Receiver<(EventU32, Option<Params>)>,
tm_sender: Box<dyn EcssTmSender>, tm_sender: Box<dyn EcssTmSender>,
time_provider: TimeProvider, time_provider: CdsTime,
timestamp: [u8; 7], timestamp: [u8; 7],
verif_handler: VerificationReporter, verif_handler: VerificationReporter,
} }
@ -57,7 +57,7 @@ impl<VerificationReporter: VerificationReportingProvider> PusEventHandler<Verifi
event_request_rx, event_request_rx,
pus_event_dispatcher, pus_event_dispatcher,
pus_event_man_rx, pus_event_man_rx,
time_provider: cds::TimeProvider::new_with_u16_days(0, 0), time_provider: cds::CdsTime::new_with_u16_days(0, 0),
timestamp: [0; 7], timestamp: [0; 7],
verif_handler, verif_handler,
tm_sender: Box::new(tm_sender), tm_sender: Box::new(tm_sender),

View File

@ -45,7 +45,7 @@ use crate::udp::{StaticUdpTmHandler, UdpTmtcServer};
use satrs::pus::event_man::EventRequestWithToken; use satrs::pus::event_man::EventRequestWithToken;
use satrs::pus::verification::{VerificationReporterCfg, VerificationReporterWithSender}; use satrs::pus::verification::{VerificationReporterCfg, VerificationReporterWithSender};
use satrs::pus::{EcssTmSender, TmAsVecSenderWithId, TmInSharedPoolSenderWithId}; use satrs::pus::{EcssTmSender, TmAsVecSenderWithId, TmInSharedPoolSenderWithId};
use satrs::spacepackets::{time::cds::TimeProvider, time::TimeWriter}; use satrs::spacepackets::{time::cds::CdsTime, time::TimeWriter};
use satrs::tmtc::CcsdsDistributor; use satrs::tmtc::CcsdsDistributor;
use satrs::ChannelId; use satrs::ChannelId;
use std::net::{IpAddr, SocketAddr}; use std::net::{IpAddr, SocketAddr};
@ -513,7 +513,7 @@ fn main() {
dyn_tmtc_pool_main(); dyn_tmtc_pool_main();
} }
pub fn update_time(time_provider: &mut TimeProvider, timestamp: &mut [u8]) { pub fn update_time(time_provider: &mut CdsTime, timestamp: &mut [u8]) {
time_provider time_provider
.update_from_now() .update_from_now()
.expect("Could not get current time"); .expect("Could not get current time");

View File

@ -6,7 +6,7 @@ use satrs::pus::{
}; };
use satrs::spacepackets::ecss::tc::PusTcReader; use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::PusServiceId; use satrs::spacepackets::ecss::PusServiceId;
use satrs::spacepackets::time::cds::TimeProvider; use satrs::spacepackets::time::cds::CdsTime;
use satrs::spacepackets::time::TimeWriter; use satrs::spacepackets::time::TimeWriter;
use satrs_example::config::{tmtc_err, CustomPusServiceId}; use satrs_example::config::{tmtc_err, CustomPusServiceId};
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
@ -33,14 +33,14 @@ pub struct PusReceiver<VerificationReporter: VerificationReportingProvider> {
} }
struct TimeStampHelper { struct TimeStampHelper {
stamper: TimeProvider, stamper: CdsTime,
time_stamp: [u8; 7], time_stamp: [u8; 7],
} }
impl TimeStampHelper { impl TimeStampHelper {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
stamper: TimeProvider::new_with_u16_days(0, 0), stamper: CdsTime::new_with_u16_days(0, 0),
time_stamp: [0; 7], time_stamp: [0; 7],
} }
} }

View File

@ -14,7 +14,7 @@ use satrs::pus::{
}; };
use satrs::spacepackets::ecss::tc::PusTcReader; use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::PusPacket; use satrs::spacepackets::ecss::PusPacket;
use satrs::spacepackets::time::cds::TimeProvider; use satrs::spacepackets::time::cds::CdsTime;
use satrs::spacepackets::time::TimeWriter; use satrs::spacepackets::time::TimeWriter;
use satrs::tmtc::tm_helper::SharedTmPool; use satrs::tmtc::tm_helper::SharedTmPool;
use satrs::ChannelId; use satrs::ChannelId;
@ -139,7 +139,7 @@ impl<
.tc_slice_raw(), .tc_slice_raw(),
) )
.unwrap(); .unwrap();
let time_stamper = TimeProvider::from_now_with_u16_days().unwrap(); let time_stamper = CdsTime::now_with_u16_days().unwrap();
let mut stamp_buf: [u8; 7] = [0; 7]; let mut stamp_buf: [u8; 7] = [0; 7];
time_stamper.write_to_bytes(&mut stamp_buf).unwrap(); time_stamper.write_to_bytes(&mut stamp_buf).unwrap();
if subservice == 128 { if subservice == 128 {

View File

@ -23,6 +23,7 @@ version = "1"
optional = true optional = true
[dependencies.satrs-shared] [dependencies.satrs-shared]
path = "../satrs-shared"
version = "0.1.2" version = "0.1.2"
features = ["serde"] features = ["serde"]

View File

@ -26,7 +26,10 @@ features = ["full"]
[dev-dependencies] [dev-dependencies]
trybuild = { version = "1", features = ["diff"] } trybuild = { version = "1", features = ["diff"] }
satrs-shared = "0.1.2"
[dev-dependencies.satrs-shared]
version = "0.1.2"
path = "../../satrs-shared"
[dev-dependencies.satrs-mib] [dev-dependencies.satrs-mib]
path = ".." path = ".."

View File

@ -18,7 +18,9 @@ default-features = false
optional = true optional = true
[dependencies.spacepackets] [dependencies.spacepackets]
version = "0.10" git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git"
version = "0.11.0-rc.0"
branch = "main"
default-features = false default-features = false
[features] [features]

View File

@ -17,7 +17,10 @@ delegate = ">0.7, <=0.10"
paste = "1" paste = "1"
smallvec = "1" smallvec = "1"
crc = "3" crc = "3"
satrs-shared = "0.1.2"
[dependencies.satrs-shared]
version = "0.1.2"
path = "../satrs-shared"
[dependencies.num_enum] [dependencies.num_enum]
version = ">0.5, <=0.7" version = ">0.5, <=0.7"
@ -68,7 +71,9 @@ features = ["all"]
optional = true optional = true
[dependencies.spacepackets] [dependencies.spacepackets]
version = "0.10" git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git"
version = "0.11.0-rc.0"
branch = "main"
default-features = false default-features = false
[dependencies.cobs] [dependencies.cobs]

View File

@ -2,6 +2,7 @@ use crate::pus::{source_buffer_large_enough, EcssTmtcError};
use spacepackets::ecss::tm::PusTmCreator; use spacepackets::ecss::tm::PusTmCreator;
use spacepackets::ecss::tm::PusTmSecondaryHeader; use spacepackets::ecss::tm::PusTmSecondaryHeader;
use spacepackets::ecss::{EcssEnumeration, PusError}; use spacepackets::ecss::{EcssEnumeration, PusError};
use spacepackets::ByteConversionError;
use spacepackets::{SpHeader, MAX_APID}; use spacepackets::{SpHeader, MAX_APID};
use crate::pus::EcssTmSenderCore; use crate::pus::EcssTmSenderCore;
@ -9,145 +10,125 @@ use crate::pus::EcssTmSenderCore;
pub use alloc_mod::EventReporter; pub use alloc_mod::EventReporter;
pub use spacepackets::ecss::event::*; pub use spacepackets::ecss::event::*;
pub struct EventReporterBase { pub struct EventReportCreator {
msg_count: u16,
apid: u16, apid: u16,
pub dest_id: u16, pub dest_id: u16,
} }
impl EventReporterBase { impl EventReportCreator {
pub fn new(apid: u16) -> Option<Self> { pub fn new(apid: u16) -> Option<Self> {
if apid > MAX_APID { if apid > MAX_APID {
return None; return None;
} }
Some(Self { Some(Self {
msg_count: 0, // msg_count: 0,
dest_id: 0, dest_id: 0,
apid, apid,
}) })
} }
pub fn event_info( pub fn event_info<'time, 'src_data>(
&mut self, &mut self,
buf: &mut [u8], src_data_buf: &'src_data mut [u8],
sender: &mut (impl EcssTmSenderCore + ?Sized), time_stamp: &'time [u8],
time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&'src_data [u8]>,
) -> Result<(), EcssTmtcError> { ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
self.generate_and_send_generic_tm( self.generate_and_send_generic_tm(
buf, src_data_buf,
Subservice::TmInfoReport, Subservice::TmInfoReport,
sender,
time_stamp, time_stamp,
event_id, event_id,
aux_data, aux_data,
) )
} }
pub fn event_low_severity( pub fn event_low_severity<'time, 'src_data>(
&mut self, &mut self,
buf: &mut [u8], src_data_buf: &'src_data mut [u8],
sender: &mut (impl EcssTmSenderCore + ?Sized), time_stamp: &'time [u8],
time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&'src_data [u8]>,
) -> Result<(), EcssTmtcError> { ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
self.generate_and_send_generic_tm( self.generate_and_send_generic_tm(
buf, src_data_buf,
Subservice::TmLowSeverityReport, Subservice::TmLowSeverityReport,
sender,
time_stamp, time_stamp,
event_id, event_id,
aux_data, aux_data,
) )
} }
pub fn event_medium_severity( pub fn event_medium_severity<'time, 'src_data>(
&mut self, &mut self,
buf: &mut [u8], buf: &'src_data mut [u8],
sender: &mut (impl EcssTmSenderCore + ?Sized), time_stamp: &'time [u8],
time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&'src_data [u8]>,
) -> Result<(), EcssTmtcError> { ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
self.generate_and_send_generic_tm( self.generate_and_send_generic_tm(
buf, buf,
Subservice::TmMediumSeverityReport, Subservice::TmMediumSeverityReport,
sender,
time_stamp, time_stamp,
event_id, event_id,
aux_data, aux_data,
) )
} }
pub fn event_high_severity( pub fn event_high_severity<'time, 'src_data>(
&mut self, &mut self,
buf: &mut [u8], src_data_buf: &'src_data mut [u8],
sender: &mut (impl EcssTmSenderCore + ?Sized), time_stamp: &'time [u8],
time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&'src_data [u8]>,
) -> Result<(), EcssTmtcError> { ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
self.generate_and_send_generic_tm( self.generate_and_send_generic_tm(
buf, src_data_buf,
Subservice::TmHighSeverityReport, Subservice::TmHighSeverityReport,
sender,
time_stamp, time_stamp,
event_id, event_id,
aux_data, aux_data,
) )
} }
fn generate_and_send_generic_tm( fn generate_and_send_generic_tm<'time, 'src_data>(
&mut self, &mut self,
buf: &mut [u8], src_data_buf: &'src_data mut [u8],
subservice: Subservice, subservice: Subservice,
sender: &mut (impl EcssTmSenderCore + ?Sized), time_stamp: &'time [u8],
time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&'src_data [u8]>,
) -> Result<(), EcssTmtcError> { ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
let tm = self.generate_generic_event_tm(buf, subservice, time_stamp, event_id, aux_data)?; self.generate_generic_event_tm(src_data_buf, subservice, time_stamp, event_id, aux_data)
sender.send_tm(tm.into())?;
self.msg_count += 1;
Ok(())
} }
fn generate_generic_event_tm<'a>( fn generate_generic_event_tm<'time, 'src_data>(
&'a self, &self,
buf: &'a mut [u8], src_data_buf: &'src_data mut [u8],
subservice: Subservice, subservice: Subservice,
time_stamp: &'a [u8], time_stamp: &'time [u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&'src_data [u8]>,
) -> Result<PusTmCreator, EcssTmtcError> { ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
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();
} }
source_buffer_large_enough(buf.len(), src_data_len)?; source_buffer_large_enough(src_data_buf.len(), src_data_len)?;
let mut sp_header = SpHeader::tm_unseg(self.apid, 0, 0).unwrap(); let mut sp_header = SpHeader::tm_unseg(self.apid, 0, 0).unwrap();
let sec_header = PusTmSecondaryHeader::new( let sec_header =
5, PusTmSecondaryHeader::new(5, subservice.into(), 0, self.dest_id, Some(time_stamp));
subservice.into(),
self.msg_count,
self.dest_id,
Some(time_stamp),
);
let mut current_idx = 0; let mut current_idx = 0;
event_id event_id.write_to_be_bytes(&mut src_data_buf[0..event_id.size()])?;
.write_to_be_bytes(&mut buf[0..event_id.size()])
.map_err(PusError::ByteConversion)?;
current_idx += event_id.size(); current_idx += event_id.size();
if let Some(aux_data) = aux_data { if let Some(aux_data) = aux_data {
buf[current_idx..current_idx + aux_data.len()].copy_from_slice(aux_data); src_data_buf[current_idx..current_idx + aux_data.len()].copy_from_slice(aux_data);
current_idx += aux_data.len(); current_idx += aux_data.len();
} }
Ok(PusTmCreator::new( Ok(PusTmCreator::new(
&mut sp_header, &mut sp_header,
sec_header, sec_header,
&buf[0..current_idx], &src_data_buf[0..current_idx],
true, true,
)) ))
} }
@ -161,12 +142,12 @@ mod alloc_mod {
pub struct EventReporter { pub struct EventReporter {
source_data_buf: Vec<u8>, source_data_buf: Vec<u8>,
pub reporter: EventReporterBase, pub reporter: EventReportCreator,
} }
impl EventReporter { impl EventReporter {
pub fn new(apid: u16, max_event_id_and_aux_data_size: usize) -> Option<Self> { pub fn new(apid: u16, max_event_id_and_aux_data_size: usize) -> Option<Self> {
let reporter = EventReporterBase::new(apid)?; let reporter = EventReportCreator::new(apid)?;
Some(Self { Some(Self {
source_data_buf: vec![0; max_event_id_and_aux_data_size], source_data_buf: vec![0; max_event_id_and_aux_data_size],
reporter, reporter,
@ -179,13 +160,17 @@ mod alloc_mod {
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcError> { ) -> Result<(), EcssTmtcError> {
self.reporter.event_info( let tm_creator = self
.reporter
.event_info(
self.source_data_buf.as_mut_slice(), self.source_data_buf.as_mut_slice(),
sender,
time_stamp, time_stamp,
event_id, event_id,
aux_data, aux_data,
) )
.map_err(PusError::ByteConversion)?;
sender.send_tm(tm_creator.into())?;
Ok(())
} }
pub fn event_low_severity( pub fn event_low_severity(
@ -195,13 +180,17 @@ mod alloc_mod {
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcError> { ) -> Result<(), EcssTmtcError> {
self.reporter.event_low_severity( let tm_creator = self
.reporter
.event_low_severity(
self.source_data_buf.as_mut_slice(), self.source_data_buf.as_mut_slice(),
sender,
time_stamp, time_stamp,
event_id, event_id,
aux_data, aux_data,
) )
.map_err(PusError::ByteConversion)?;
sender.send_tm(tm_creator.into())?;
Ok(())
} }
pub fn event_medium_severity( pub fn event_medium_severity(
@ -211,13 +200,17 @@ mod alloc_mod {
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcError> { ) -> Result<(), EcssTmtcError> {
self.reporter.event_medium_severity( let tm_creator = self
.reporter
.event_medium_severity(
self.source_data_buf.as_mut_slice(), self.source_data_buf.as_mut_slice(),
sender,
time_stamp, time_stamp,
event_id, event_id,
aux_data, aux_data,
) )
.map_err(PusError::ByteConversion)?;
sender.send_tm(tm_creator.into())?;
Ok(())
} }
pub fn event_high_severity( pub fn event_high_severity(
@ -227,13 +220,17 @@ mod alloc_mod {
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
) -> Result<(), EcssTmtcError> { ) -> Result<(), EcssTmtcError> {
self.reporter.event_high_severity( let tm_creator = self
.reporter
.event_high_severity(
self.source_data_buf.as_mut_slice(), self.source_data_buf.as_mut_slice(),
sender,
time_stamp, time_stamp,
event_id, event_id,
aux_data, aux_data,
) )
.map_err(PusError::ByteConversion)?;
sender.send_tm(tm_creator.into())?;
Ok(())
} }
} }
} }

View File

@ -40,19 +40,19 @@ pub use alloc_mod::*;
pub use std_mod::*; pub use std_mod::*;
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
pub enum PusTmWrapper<'tm> { pub enum PusTmWrapper<'time, 'src_data> {
InStore(StoreAddr), InStore(StoreAddr),
Direct(PusTmCreator<'tm>), Direct(PusTmCreator<'time, 'src_data>),
} }
impl From<StoreAddr> for PusTmWrapper<'_> { impl From<StoreAddr> for PusTmWrapper<'_, '_> {
fn from(value: StoreAddr) -> Self { fn from(value: StoreAddr) -> Self {
Self::InStore(value) Self::InStore(value)
} }
} }
impl<'tm> From<PusTmCreator<'tm>> for PusTmWrapper<'tm> { impl<'time, 'src_data> From<PusTmCreator<'time, 'src_data>> for PusTmWrapper<'time, 'src_data> {
fn from(value: PusTmCreator<'tm>) -> Self { fn from(value: PusTmCreator<'time, 'src_data>) -> Self {
Self::Direct(value) Self::Direct(value)
} }
} }
@ -380,7 +380,7 @@ pub mod std_mod {
use spacepackets::ecss::tc::PusTcReader; use spacepackets::ecss::tc::PusTcReader;
use spacepackets::ecss::tm::PusTmCreator; use spacepackets::ecss::tm::PusTmCreator;
use spacepackets::ecss::{PusError, WritablePusPacket}; use spacepackets::ecss::{PusError, WritablePusPacket};
use spacepackets::time::cds::TimeProvider; use spacepackets::time::cds::CdsTime;
use spacepackets::time::StdTimestampError; use spacepackets::time::StdTimestampError;
use spacepackets::time::TimeWriter; use spacepackets::time::TimeWriter;
use std::string::String; use std::string::String;
@ -860,8 +860,7 @@ pub mod std_mod {
partial_error: &mut Option<PartialPusHandlingError>, partial_error: &mut Option<PartialPusHandlingError>,
) -> [u8; 7] { ) -> [u8; 7] {
let mut time_stamp: [u8; 7] = [0; 7]; let mut time_stamp: [u8; 7] = [0; 7];
let time_provider = let time_provider = CdsTime::now_with_u16_days().map_err(PartialPusHandlingError::Time);
TimeProvider::from_now_with_u16_days().map_err(PartialPusHandlingError::Time);
if let Ok(time_provider) = time_provider { if let Ok(time_provider) = time_provider {
// Can't fail, we have a buffer with the exact required size. // Can't fail, we have a buffer with the exact required size.
time_provider.write_to_bytes(&mut time_stamp).unwrap(); time_provider.write_to_bytes(&mut time_stamp).unwrap();
@ -981,15 +980,16 @@ 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<(), ByteConversionError> {
if len > cap { if len > cap {
return Err( return Err(ByteConversionError::ToSliceTooSmall {
PusError::ByteConversion(ByteConversionError::ToSliceTooSmall {
found: cap, found: cap,
expected: len, expected: len,
}) }
.into(), .into());
);
} }
Ok(()) Ok(())
} }

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@ use crate::pool::PoolProvider;
use crate::pus::{PusPacketHandlerResult, PusPacketHandlingError}; use crate::pus::{PusPacketHandlerResult, PusPacketHandlingError};
use alloc::string::ToString; use alloc::string::ToString;
use spacepackets::ecss::{scheduling, PusPacket}; use spacepackets::ecss::{scheduling, PusPacket};
use spacepackets::time::cds::TimeProvider; use spacepackets::time::cds::CdsTime;
/// This is a helper class for [std] environments to handle generic PUS 11 (scheduling service) /// This is a helper class for [std] environments to handle generic PUS 11 (scheduling service)
/// packets. This handler is able to handle the most important PUS requests for a scheduling /// packets. This handler is able to handle the most important PUS requests for a scheduling
@ -168,7 +168,7 @@ impl<
// let mut pool = self.sched_tc_pool.write().expect("locking pool failed"); // let mut pool = self.sched_tc_pool.write().expect("locking pool failed");
self.scheduler self.scheduler
.insert_wrapped_tc::<TimeProvider>(&tc, sched_tc_pool) .insert_wrapped_tc::<CdsTime>(&tc, sched_tc_pool)
.expect("insertion of activity into pool failed"); .expect("insertion of activity into pool failed");
self.service_helper self.service_helper
@ -303,7 +303,7 @@ mod tests {
} }
impl PusSchedulerProvider for TestScheduler { impl PusSchedulerProvider for TestScheduler {
type TimeProvider = cds::TimeProvider; type TimeProvider = cds::CdsTime;
fn reset( fn reset(
&mut self, &mut self,
@ -329,7 +329,7 @@ mod tests {
fn insert_unwrapped_and_stored_tc( fn insert_unwrapped_and_stored_tc(
&mut self, &mut self,
_time_stamp: spacepackets::time::UnixTimestamp, _time_stamp: spacepackets::time::UnixTime,
info: crate::pus::scheduler::TcInfo, info: crate::pus::scheduler::TcInfo,
) -> Result<(), crate::pus::scheduler::ScheduleError> { ) -> Result<(), crate::pus::scheduler::ScheduleError> {
self.inserted_tcs.push_back(info); self.inserted_tcs.push_back(info);
@ -390,7 +390,7 @@ mod tests {
let mut sec_header = PusTcSecondaryHeader::new_simple(17, 1); let mut sec_header = PusTcSecondaryHeader::new_simple(17, 1);
let ping_tc = PusTcCreator::new(&mut reply_header, sec_header, &[], true); let ping_tc = PusTcCreator::new(&mut reply_header, sec_header, &[], true);
let req_id_ping_tc = scheduler::RequestId::from_tc(&ping_tc); let req_id_ping_tc = scheduler::RequestId::from_tc(&ping_tc);
let stamper = cds::TimeProvider::from_now_with_u16_days().expect("time provider failed"); let stamper = cds::CdsTime::now_with_u16_days().expect("time provider failed");
let mut sched_app_data: [u8; 64] = [0; 64]; let mut sched_app_data: [u8; 64] = [0; 64];
let mut written_len = stamper.write_to_bytes(&mut sched_app_data).unwrap(); let mut written_len = stamper.write_to_bytes(&mut sched_app_data).unwrap();
let ping_raw = ping_tc.to_vec().expect("generating raw tc failed"); let ping_raw = ping_tc.to_vec().expect("generating raw tc failed");

View File

@ -87,8 +87,8 @@ use delegate::delegate;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use spacepackets::ecss::tc::IsPusTelecommand; use spacepackets::ecss::tc::IsPusTelecommand;
use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader}; use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
use spacepackets::ecss::{EcssEnumeration, PusError, WritablePusPacket}; use spacepackets::ecss::{EcssEnumeration, PusError};
use spacepackets::{CcsdsPacket, PacketId, PacketSequenceCtrl}; use spacepackets::{ByteConversionError, CcsdsPacket, PacketId, PacketSequenceCtrl};
use spacepackets::{SpHeader, MAX_APID}; use spacepackets::{SpHeader, MAX_APID};
pub use crate::seq_count::SeqCountProviderSimple; pub use crate::seq_count::SeqCountProviderSimple;
@ -328,87 +328,6 @@ impl<'stamp, 'fargs> FailParamsWithStep<'stamp, 'fargs> {
} }
} }
#[derive(Clone)]
pub struct VerificationReporterCore {
pub dest_id: u16,
apid: u16,
}
pub enum VerifSuccess {}
pub enum VerifFailure {}
/// Abstraction for a sendable PUS TM. The user is expected to send the TM packet to a TM sink.
///
/// This struct generally mutably borrows the source data buffer.
pub struct VerificationSendable<'src_data, State, SuccessOrFailure> {
token: Option<VerificationToken<State>>,
pus_tm: Option<PusTmCreator<'src_data>>,
phantom: PhantomData<SuccessOrFailure>,
}
impl<'src_data, State, SuccessOrFailure> VerificationSendable<'src_data, State, SuccessOrFailure> {
pub(crate) fn new(pus_tm: PusTmCreator<'src_data>, token: VerificationToken<State>) -> Self {
Self {
token: Some(token),
pus_tm: Some(pus_tm),
phantom: PhantomData,
}
}
pub(crate) fn new_no_token(pus_tm: PusTmCreator<'src_data>) -> Self {
Self {
token: None,
pus_tm: Some(pus_tm),
phantom: PhantomData,
}
}
pub fn len_packed(&self) -> usize {
self.pus_tm.as_ref().unwrap().len_written()
}
pub fn pus_tm(&self) -> &PusTmCreator<'src_data> {
self.pus_tm.as_ref().unwrap()
}
pub fn pus_tm_mut(&mut self) -> &mut PusTmCreator<'src_data> {
self.pus_tm.as_mut().unwrap()
}
}
impl<'src_data, State> VerificationSendable<'src_data, State, VerifFailure> {
pub fn send_success_verif_failure(self) {}
}
impl<'src_data, State> VerificationSendable<'src_data, State, VerifFailure> {
pub fn send_failure(self) -> (PusTmCreator<'src_data>, VerificationToken<State>) {
(self.pus_tm.unwrap(), self.token.unwrap())
}
}
impl<'src_data> VerificationSendable<'src_data, TcStateNone, VerifSuccess> {
pub fn send_success_acceptance_success(self) -> VerificationToken<TcStateAccepted> {
VerificationToken {
state: PhantomData,
req_id: self.token.unwrap().req_id(),
}
}
}
impl<'src_data> VerificationSendable<'src_data, TcStateAccepted, VerifSuccess> {
pub fn send_success_start_success(self) -> VerificationToken<TcStateStarted> {
VerificationToken {
state: PhantomData,
req_id: self.token.unwrap().req_id(),
}
}
}
impl<'src_data, TcState: WasAtLeastAccepted + Copy>
VerificationSendable<'src_data, TcState, VerifSuccess>
{
pub fn send_success_step_or_completion_success(self) {}
}
pub trait VerificationReportingProvider { pub trait VerificationReportingProvider {
fn add_tc( fn add_tc(
&mut self, &mut self,
@ -423,25 +342,25 @@ pub trait VerificationReportingProvider {
&self, &self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateNone>>; ) -> Result<VerificationToken<TcStateAccepted>, EcssTmtcError>;
fn acceptance_failure( fn acceptance_failure(
&self, &self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<TcStateNone>>; ) -> Result<(), EcssTmtcError>;
fn start_success( fn start_success(
&self, &self,
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<TcStateStarted>, VerificationOrSendErrorWithToken<TcStateAccepted>>; ) -> Result<VerificationToken<TcStateStarted>, EcssTmtcError>;
fn start_failure( fn start_failure(
&self, &self,
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<TcStateAccepted>>; ) -> Result<(), EcssTmtcError>;
fn step_success( fn step_success(
&self, &self,
@ -454,29 +373,35 @@ pub trait VerificationReportingProvider {
&self, &self,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
params: FailParamsWithStep, params: FailParamsWithStep,
) -> Result<(), VerificationOrSendErrorWithToken<TcStateStarted>>; ) -> Result<(), EcssTmtcError>;
fn completion_success<TcState: WasAtLeastAccepted + Copy>( fn completion_success<TcState: WasAtLeastAccepted + Copy>(
&self, &self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<(), VerificationOrSendErrorWithToken<TcState>>; ) -> Result<(), EcssTmtcError>;
fn completion_failure<TcState: WasAtLeastAccepted + Copy>( fn completion_failure<TcState: WasAtLeastAccepted + Copy>(
&self, &self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<TcState>>; ) -> Result<(), EcssTmtcError>;
} }
/// Primary verification handler. It provides an API to send PUS 1 verification telemetry packets /// Primary verification handler. It provides an API to generate PUS 1 verification telemetry
/// and verify the various steps of telecommand handling as specified in the PUS standard. /// packets and verify the various steps of telecommand handling as specified in the PUS standard.
/// ///
/// This is the core component which can be used without [`alloc`] support. Please note that /// This is the core component which can be used without [`alloc`] support. Please note that
/// the buffer passed to the API exposes by this struct will be used to serialize the source data. /// the buffer passed to the API exposes by this struct will be used to serialize the source data.
/// This buffer may not be re-used to serialize the whole telemetry because that would overwrite /// This buffer may not be re-used to serialize the whole telemetry because that would overwrite
/// the source data itself. /// the source data itself.
impl VerificationReporterCore { #[derive(Clone)]
pub struct VerificationReportCreator {
pub dest_id: u16,
apid: u16,
}
impl VerificationReportCreator {
pub fn new(apid: u16) -> Option<Self> { pub fn new(apid: u16) -> Option<Self> {
if apid > MAX_APID { if apid > MAX_APID {
return None; return None;
@ -519,20 +444,16 @@ impl VerificationReporterCore {
VerificationToken::<TcStateNone>::new(req_id) VerificationToken::<TcStateNone>::new(req_id)
} }
fn sendable_success_no_step<'src_data, State: Copy>( fn success_verification_no_step<'time, 'src_data, State: Copy>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
subservice: u8, subservice: u8,
token: VerificationToken<State>, token: VerificationToken<State>,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
time_stamp: &'src_data [u8], time_stamp: &'time [u8],
) -> Result< ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
VerificationSendable<'src_data, State, VerifSuccess>, let tm_creator = self.create_pus_verif_success_tm(
VerificationErrorWithToken<State>,
> {
Ok(VerificationSendable::new(
self.create_pus_verif_success_tm(
src_data_buf, src_data_buf,
subservice, subservice,
seq_count, seq_count,
@ -540,15 +461,13 @@ impl VerificationReporterCore {
&token.req_id, &token.req_id,
time_stamp, time_stamp,
None::<&dyn EcssEnumeration>, None::<&dyn EcssEnumeration>,
) )?;
.map_err(|e| VerificationErrorWithToken(e, token))?, Ok(tm_creator)
token,
))
} }
// Internal helper function, too many arguments is acceptable for this case. // Internal helper function, too many arguments is acceptable for this case.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn sendable_failure_no_step<'src_data, State: Copy>( fn failure_verification_no_step<'time, 'src_data, State: Copy>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
subservice: u8, subservice: u8,
@ -556,13 +475,9 @@ impl VerificationReporterCore {
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
step: Option<&(impl EcssEnumeration + ?Sized)>, step: Option<&(impl EcssEnumeration + ?Sized)>,
params: &FailParams<'src_data, '_>, params: &FailParams<'time, '_>,
) -> Result< ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
VerificationSendable<'src_data, State, VerifFailure>, let tm_creator = self.create_pus_verif_fail_tm(
VerificationErrorWithToken<State>,
> {
Ok(VerificationSendable::new(
self.create_pus_verif_fail_tm(
src_data_buf, src_data_buf,
subservice, subservice,
seq_count, seq_count,
@ -570,71 +485,52 @@ impl VerificationReporterCore {
&token.req_id, &token.req_id,
step, step,
params, params,
) )?;
.map_err(|e| VerificationErrorWithToken(e, token))?, Ok(tm_creator)
token,
))
} }
/// Package a PUS TM\[1, 1\] packet, see 8.1.2.1 of the PUS standard. /// Package a PUS TM\[1, 1\] packet, see 8.1.2.1 of the PUS standard.
pub fn acceptance_success<'src_data>( pub fn acceptance_success<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
time_stamp: &'src_data [u8], time_stamp: &'time [u8],
) -> Result< ) -> Result<
VerificationSendable<'src_data, TcStateNone, VerifSuccess>, (
VerificationErrorWithToken<TcStateNone>, PusTmCreator<'time, 'src_data>,
VerificationToken<TcStateAccepted>,
),
ByteConversionError,
> { > {
self.sendable_success_no_step( let tm_creator = self.success_verification_no_step(
src_data_buf, src_data_buf,
Subservice::TmAcceptanceSuccess.into(), Subservice::TmAcceptanceSuccess.into(),
token, token,
seq_count, seq_count,
msg_count, msg_count,
time_stamp, time_stamp,
) )?;
} Ok((
tm_creator,
pub fn send_acceptance_success( VerificationToken {
&self, state: PhantomData,
mut sendable: VerificationSendable<'_, TcStateNone, VerifSuccess>, req_id: token.req_id,
sender: &(impl EcssTmSenderCore + ?Sized), },
) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateNone>> ))
{
sender
.send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| VerificationOrSendErrorWithToken(e, sendable.token.unwrap()))?;
Ok(sendable.send_success_acceptance_success())
}
pub fn send_acceptance_failure(
&self,
mut sendable: VerificationSendable<'_, TcStateNone, VerifFailure>,
sender: &(impl EcssTmSenderCore + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<TcStateNone>> {
sender
.send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| VerificationOrSendErrorWithToken(e, sendable.token.unwrap()))?;
sendable.send_success_verif_failure();
Ok(())
} }
/// Package a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard. /// Package a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard.
pub fn acceptance_failure<'src_data>( pub fn acceptance_failure<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
params: FailParams<'src_data, '_>, params: FailParams<'time, '_>,
) -> Result< ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
VerificationSendable<'src_data, TcStateNone, VerifFailure>, self.failure_verification_no_step(
VerificationErrorWithToken<TcStateNone>,
> {
self.sendable_failure_no_step(
src_data_buf, src_data_buf,
Subservice::TmAcceptanceFailure.into(), Subservice::TmAcceptanceFailure.into(),
token, token,
@ -648,55 +544,50 @@ impl VerificationReporterCore {
/// Package and send a PUS TM\[1, 3\] packet, see 8.1.2.3 of the PUS standard. /// Package and send a PUS TM\[1, 3\] packet, see 8.1.2.3 of the PUS standard.
/// ///
/// Requires a token previously acquired by calling [Self::acceptance_success]. /// Requires a token previously acquired by calling [Self::acceptance_success].
pub fn start_success<'src_data>( pub fn start_success<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
time_stamp: &'src_data [u8], time_stamp: &'time [u8],
) -> Result< ) -> Result<
VerificationSendable<'src_data, TcStateAccepted, VerifSuccess>, (
VerificationErrorWithToken<TcStateAccepted>, PusTmCreator<'time, 'src_data>,
VerificationToken<TcStateStarted>,
),
ByteConversionError,
> { > {
self.sendable_success_no_step( let tm_creator = self.success_verification_no_step(
src_data_buf, src_data_buf,
Subservice::TmStartSuccess.into(), Subservice::TmStartSuccess.into(),
token, token,
seq_count, seq_count,
msg_count, msg_count,
time_stamp, time_stamp,
) )?;
} Ok((
tm_creator,
pub fn send_start_success( VerificationToken {
&self, state: PhantomData,
mut sendable: VerificationSendable<'_, TcStateAccepted, VerifSuccess>, req_id: token.req_id,
sender: &(impl EcssTmSenderCore + ?Sized), },
) -> Result<VerificationToken<TcStateStarted>, VerificationOrSendErrorWithToken<TcStateAccepted>> ))
{
sender
.send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| VerificationOrSendErrorWithToken(e, sendable.token.unwrap()))?;
Ok(sendable.send_success_start_success())
} }
/// Package and send a PUS TM\[1, 4\] packet, see 8.1.2.4 of the PUS standard. /// Package and send a PUS TM\[1, 4\] packet, see 8.1.2.4 of the PUS standard.
/// ///
/// Requires a token previously acquired by calling [Self::acceptance_success]. It consumes /// Requires a token previously acquired by calling [Self::acceptance_success]. It consumes
/// the token because verification handling is done. /// the token because verification handling is done.
pub fn start_failure<'src_data>( pub fn start_failure<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
params: FailParams<'src_data, '_>, params: FailParams<'time, '_>,
) -> Result< ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
VerificationSendable<'src_data, TcStateAccepted, VerifFailure>, self.failure_verification_no_step(
VerificationErrorWithToken<TcStateAccepted>,
> {
self.sendable_failure_no_step(
src_data_buf, src_data_buf,
Subservice::TmStartFailure.into(), Subservice::TmStartFailure.into(),
token, token,
@ -707,31 +598,18 @@ impl VerificationReporterCore {
) )
} }
pub fn send_start_failure(
&self,
mut sendable: VerificationSendable<'_, TcStateAccepted, VerifFailure>,
sender: &(impl EcssTmSenderCore + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<TcStateAccepted>> {
sender
.send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| VerificationOrSendErrorWithToken(e, sendable.token.unwrap()))?;
sendable.send_success_verif_failure();
Ok(())
}
/// Package and send a PUS TM\[1, 5\] packet, see 8.1.2.5 of the PUS standard. /// Package and send a PUS TM\[1, 5\] packet, see 8.1.2.5 of the PUS standard.
/// ///
/// Requires a token previously acquired by calling [Self::start_success]. /// Requires a token previously acquired by calling [Self::start_success].
pub fn step_success<'src_data>( pub fn step_success<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: &VerificationToken<TcStateStarted>, token: &VerificationToken<TcStateStarted>,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
time_stamp: &'src_data [u8], time_stamp: &'time [u8],
step: impl EcssEnumeration, step: impl EcssEnumeration,
) -> Result<VerificationSendable<'src_data, TcStateStarted, VerifSuccess>, EcssTmtcError> { ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
Ok(VerificationSendable::new_no_token(
self.create_pus_verif_success_tm( self.create_pus_verif_success_tm(
src_data_buf, src_data_buf,
Subservice::TmStepSuccess.into(), Subservice::TmStepSuccess.into(),
@ -740,26 +618,21 @@ impl VerificationReporterCore {
&token.req_id, &token.req_id,
time_stamp, time_stamp,
Some(&step), Some(&step),
)?, )
))
} }
/// Package and send a PUS TM\[1, 6\] packet, see 8.1.2.6 of the PUS standard. /// Package and send a PUS TM\[1, 6\] packet, see 8.1.2.6 of the PUS standard.
/// ///
/// 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 step_failure<'src_data>( pub fn step_failure<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
params: FailParamsWithStep<'src_data, '_>, params: FailParamsWithStep<'time, '_>,
) -> Result< ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
VerificationSendable<'src_data, TcStateStarted, VerifFailure>,
VerificationErrorWithToken<TcStateStarted>,
> {
Ok(VerificationSendable::new(
self.create_pus_verif_fail_tm( self.create_pus_verif_fail_tm(
src_data_buf, src_data_buf,
Subservice::TmStepFailure.into(), Subservice::TmStepFailure.into(),
@ -769,27 +642,21 @@ impl VerificationReporterCore {
Some(params.step), Some(params.step),
&params.bp, &params.bp,
) )
.map_err(|e| VerificationErrorWithToken(e, token))?,
token,
))
} }
/// Package and send a PUS TM\[1, 7\] packet, see 8.1.2.7 of the PUS standard. /// Package and send a PUS TM\[1, 7\] packet, see 8.1.2.7 of the PUS standard.
/// ///
/// 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, TcState: WasAtLeastAccepted + Copy>( pub fn completion_success<'time, 'src_data, TcState: WasAtLeastAccepted + Copy>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
seq_counter: u16, seq_counter: u16,
msg_counter: u16, msg_counter: u16,
time_stamp: &'src_data [u8], time_stamp: &'time [u8],
) -> Result< ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
VerificationSendable<'src_data, TcState, VerifSuccess>, self.success_verification_no_step(
VerificationErrorWithToken<TcState>,
> {
self.sendable_success_no_step(
src_data_buf, src_data_buf,
Subservice::TmCompletionSuccess.into(), Subservice::TmCompletionSuccess.into(),
token, token,
@ -803,18 +670,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, TcState: WasAtLeastAccepted + Copy>( pub fn completion_failure<'time, 'src_data, TcState: WasAtLeastAccepted + Copy>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
params: FailParams<'src_data, '_>, params: FailParams<'time, '_>,
) -> Result< ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
VerificationSendable<'src_data, TcState, VerifFailure>, self.failure_verification_no_step(
VerificationErrorWithToken<TcState>,
> {
self.sendable_failure_no_step(
src_data_buf, src_data_buf,
Subservice::TmCompletionFailure.into(), Subservice::TmCompletionFailure.into(),
token, token,
@ -825,42 +689,18 @@ impl VerificationReporterCore {
) )
} }
pub fn send_step_or_completion_success<TcState: WasAtLeastAccepted + Copy>(
&self,
mut sendable: VerificationSendable<'_, TcState, VerifSuccess>,
sender: &(impl EcssTmSenderCore + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
sender
.send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| VerificationOrSendErrorWithToken(e, sendable.token.unwrap()))?;
sendable.send_success_step_or_completion_success();
Ok(())
}
pub fn send_step_or_completion_failure<TcState: WasAtLeastAccepted + Copy>(
&self,
mut sendable: VerificationSendable<'_, TcState, VerifFailure>,
sender: &(impl EcssTmSenderCore + ?Sized),
) -> Result<(), VerificationOrSendErrorWithToken<TcState>> {
sender
.send_tm(sendable.pus_tm.take().unwrap().into())
.map_err(|e| VerificationOrSendErrorWithToken(e, sendable.token.unwrap()))?;
sendable.send_success_verif_failure();
Ok(())
}
// Internal helper function, too many arguments is acceptable for this case. // Internal helper function, too many arguments is acceptable for this case.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn create_pus_verif_success_tm<'src_data>( fn create_pus_verif_success_tm<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
subservice: u8, subservice: u8,
seq_count: u16, seq_count: u16,
msg_counter: u16, msg_counter: u16,
req_id: &RequestId, req_id: &RequestId,
time_stamp: &'src_data [u8], time_stamp: &'time [u8],
step: Option<&(impl EcssEnumeration + ?Sized)>, step: Option<&(impl EcssEnumeration + ?Sized)>,
) -> Result<PusTmCreator<'src_data>, EcssTmtcError> { ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
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();
@ -887,7 +727,7 @@ impl VerificationReporterCore {
// Internal helper function, too many arguments is acceptable for this case. // Internal helper function, too many arguments is acceptable for this case.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn create_pus_verif_fail_tm<'src_data>( fn create_pus_verif_fail_tm<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
subservice: u8, subservice: u8,
@ -895,8 +735,8 @@ impl VerificationReporterCore {
msg_counter: u16, msg_counter: u16,
req_id: &RequestId, req_id: &RequestId,
step: Option<&(impl EcssEnumeration + ?Sized)>, step: Option<&(impl EcssEnumeration + ?Sized)>,
params: &FailParams<'src_data, '_>, params: &FailParams<'time, '_>,
) -> Result<PusTmCreator<'src_data>, EcssTmtcError> { ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
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 {
@ -914,8 +754,7 @@ impl VerificationReporterCore {
} }
params params
.failure_code .failure_code
.write_to_be_bytes(&mut src_data_buf[idx..idx + params.failure_code.size()]) .write_to_be_bytes(&mut src_data_buf[idx..idx + params.failure_code.size()])?;
.map_err(PusError::ByteConversion)?;
idx += params.failure_code.size(); idx += params.failure_code.size();
src_data_buf[idx..idx + params.failure_data.len()].copy_from_slice(params.failure_data); src_data_buf[idx..idx + params.failure_data.len()].copy_from_slice(params.failure_data);
let mut sp_header = SpHeader::tm_unseg(self.apid(), seq_count, 0).unwrap(); let mut sp_header = SpHeader::tm_unseg(self.apid(), seq_count, 0).unwrap();
@ -929,15 +768,15 @@ impl VerificationReporterCore {
)) ))
} }
fn create_pus_verif_tm_base<'src_data>( fn create_pus_verif_tm_base<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
subservice: u8, subservice: u8,
msg_counter: u16, msg_counter: u16,
sp_header: &mut SpHeader, sp_header: &mut SpHeader,
time_stamp: &'src_data [u8], time_stamp: &'time [u8],
source_data_len: usize, source_data_len: usize,
) -> PusTmCreator<'src_data> { ) -> PusTmCreator<'time, 'src_data> {
let tm_sec_header = let tm_sec_header =
PusTmSecondaryHeader::new(1, subservice, msg_counter, self.dest_id, Some(time_stamp)); PusTmSecondaryHeader::new(1, subservice, msg_counter, self.dest_id, Some(time_stamp));
PusTmCreator::new( PusTmCreator::new(
@ -953,7 +792,7 @@ impl VerificationReporterCore {
pub mod alloc_mod { pub mod alloc_mod {
use super::*; use super::*;
use crate::{ use crate::{
pus::{TmAsVecSenderWithId, TmInSharedPoolSenderWithId}, pus::{PusTmWrapper, TmAsVecSenderWithId, TmInSharedPoolSenderWithId},
seq_count::SequenceCountProvider, seq_count::SequenceCountProvider,
}; };
use core::cell::RefCell; use core::cell::RefCell;
@ -994,12 +833,12 @@ pub mod alloc_mod {
source_data_buf: RefCell<alloc::vec::Vec<u8>>, source_data_buf: RefCell<alloc::vec::Vec<u8>>,
pub seq_count_provider: Option<alloc::boxed::Box<dyn SequenceCountProvider<u16> + Send>>, pub seq_count_provider: Option<alloc::boxed::Box<dyn SequenceCountProvider<u16> + Send>>,
pub msg_count_provider: Option<alloc::boxed::Box<dyn SequenceCountProvider<u16> + Send>>, pub msg_count_provider: Option<alloc::boxed::Box<dyn SequenceCountProvider<u16> + Send>>,
pub reporter: VerificationReporterCore, pub reporter: VerificationReportCreator,
} }
impl VerificationReporter { impl VerificationReporter {
pub fn new(cfg: &VerificationReporterCfg) -> Self { pub fn new(cfg: &VerificationReporterCfg) -> Self {
let reporter = VerificationReporterCore::new(cfg.apid).unwrap(); let reporter = VerificationReportCreator::new(cfg.apid).unwrap();
Self { Self {
source_data_buf: RefCell::new(alloc::vec![ source_data_buf: RefCell::new(alloc::vec![
0; 0;
@ -1035,8 +874,7 @@ pub mod alloc_mod {
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
sender: &(impl EcssTmSenderCore + ?Sized), sender: &(impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateNone>> ) -> Result<VerificationToken<TcStateAccepted>, EcssTmtcError> {
{
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1046,14 +884,18 @@ pub mod alloc_mod {
.as_ref() .as_ref()
.map_or(0, |v| v.get_and_increment()); .map_or(0, |v| v.get_and_increment());
let mut source_data_buf = self.source_data_buf.borrow_mut(); let mut source_data_buf = self.source_data_buf.borrow_mut();
let sendable = self.reporter.acceptance_success( let (tm_creator, token) = self
.reporter
.acceptance_success(
source_data_buf.as_mut_slice(), source_data_buf.as_mut_slice(),
token, token,
seq_count, seq_count,
msg_count, msg_count,
time_stamp, time_stamp,
)?; )
self.reporter.send_acceptance_success(sendable, sender) .map_err(PusError::ByteConversion)?;
sender.send_tm(PusTmWrapper::Direct(tm_creator))?;
Ok(token)
} }
/// Package and send a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard /// Package and send a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard
@ -1062,7 +904,7 @@ pub mod alloc_mod {
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
sender: &(impl EcssTmSenderCore + ?Sized), sender: &(impl EcssTmSenderCore + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<TcStateNone>> { ) -> Result<(), EcssTmtcError> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1072,14 +914,12 @@ pub mod alloc_mod {
.as_ref() .as_ref()
.map_or(0, |v| v.get_and_increment()); .map_or(0, |v| v.get_and_increment());
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let sendable = self.reporter.acceptance_failure( let sendable = self
buf.as_mut_slice(), .reporter
token, .acceptance_failure(buf.as_mut_slice(), token, seq_count, msg_count, params)
seq_count, .map_err(PusError::ByteConversion)?;
msg_count, sender.send_tm(PusTmWrapper::Direct(sendable))?;
params, Ok(())
)?;
self.reporter.send_acceptance_failure(sendable, sender)
} }
/// Package and send a PUS TM\[1, 3\] packet, see 8.1.2.3 of the PUS standard. /// Package and send a PUS TM\[1, 3\] packet, see 8.1.2.3 of the PUS standard.
@ -1090,10 +930,7 @@ pub mod alloc_mod {
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &(impl EcssTmSenderCore + ?Sized), sender: &(impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result< ) -> Result<VerificationToken<TcStateStarted>, EcssTmtcError> {
VerificationToken<TcStateStarted>,
VerificationOrSendErrorWithToken<TcStateAccepted>,
> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1103,14 +940,13 @@ pub mod alloc_mod {
.as_ref() .as_ref()
.map_or(0, |v| v.get_and_increment()); .map_or(0, |v| v.get_and_increment());
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let sendable = self.reporter.start_success( let (tm_creator, started_token) = self
buf.as_mut_slice(), .reporter
token, .start_success(buf.as_mut_slice(), token, seq_count, msg_count, time_stamp)
seq_count, .map_err(PusError::ByteConversion)?;
msg_count, sender.send_tm(PusTmWrapper::Direct(tm_creator))?;
time_stamp, Ok(started_token)
)?; //self.reporter.send_start_success(sendable, sender)
self.reporter.send_start_success(sendable, sender)
} }
/// Package and send a PUS TM\[1, 4\] packet, see 8.1.2.4 of the PUS standard. /// Package and send a PUS TM\[1, 4\] packet, see 8.1.2.4 of the PUS standard.
@ -1122,7 +958,7 @@ pub mod alloc_mod {
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &(impl EcssTmSenderCore + ?Sized), sender: &(impl EcssTmSenderCore + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<TcStateAccepted>> { ) -> Result<(), EcssTmtcError> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1132,14 +968,12 @@ pub mod alloc_mod {
.as_ref() .as_ref()
.map_or(0, |v| v.get_and_increment()); .map_or(0, |v| v.get_and_increment());
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let sendable = self.reporter.start_failure( let sendable = self
buf.as_mut_slice(), .reporter
token, .start_failure(buf.as_mut_slice(), token, seq_count, msg_count, params)
seq_count, .map_err(PusError::ByteConversion)?;
msg_count, sender.send_tm(PusTmWrapper::Direct(sendable))?;
params, Ok(())
)?;
self.reporter.send_start_failure(sendable, sender)
} }
/// Package and send a PUS TM\[1, 5\] packet, see 8.1.2.5 of the PUS standard. /// Package and send a PUS TM\[1, 5\] packet, see 8.1.2.5 of the PUS standard.
@ -1161,17 +995,19 @@ pub mod alloc_mod {
.as_ref() .as_ref()
.map_or(0, |v| v.get_and_increment()); .map_or(0, |v| v.get_and_increment());
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let sendable = self.reporter.step_success( let sendable = self
.reporter
.step_success(
buf.as_mut_slice(), buf.as_mut_slice(),
token, token,
seq_count, seq_count,
msg_count, msg_count,
time_stamp, time_stamp,
step, step,
)?; )
self.reporter .map_err(PusError::ByteConversion)?;
.send_step_or_completion_success(sendable, sender) sender.send_tm(PusTmWrapper::Direct(sendable))?;
.map_err(|e| e.0) Ok(())
} }
/// Package and send a PUS TM\[1, 6\] packet, see 8.1.2.6 of the PUS standard. /// Package and send a PUS TM\[1, 6\] packet, see 8.1.2.6 of the PUS standard.
@ -1183,7 +1019,7 @@ pub mod alloc_mod {
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
sender: &(impl EcssTmSenderCore + ?Sized), sender: &(impl EcssTmSenderCore + ?Sized),
params: FailParamsWithStep, params: FailParamsWithStep,
) -> Result<(), VerificationOrSendErrorWithToken<TcStateStarted>> { ) -> Result<(), EcssTmtcError> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1193,15 +1029,12 @@ pub mod alloc_mod {
.as_ref() .as_ref()
.map_or(0, |v| v.get_and_increment()); .map_or(0, |v| v.get_and_increment());
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let sendable = self.reporter.step_failure( let sendable = self
buf.as_mut_slice(), .reporter
token, .step_failure(buf.as_mut_slice(), token, seq_count, msg_count, params)
seq_count, .map_err(PusError::ByteConversion)?;
msg_count, sender.send_tm(PusTmWrapper::Direct(sendable))?;
params, Ok(())
)?;
self.reporter
.send_step_or_completion_failure(sendable, sender)
} }
/// Package and send a PUS TM\[1, 7\] packet, see 8.1.2.7 of the PUS standard. /// Package and send a PUS TM\[1, 7\] packet, see 8.1.2.7 of the PUS standard.
@ -1213,7 +1046,7 @@ pub mod alloc_mod {
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
sender: &(impl EcssTmSenderCore + ?Sized), sender: &(impl EcssTmSenderCore + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<(), VerificationOrSendErrorWithToken<TcState>> { ) -> Result<(), EcssTmtcError> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1223,15 +1056,12 @@ pub mod alloc_mod {
.as_ref() .as_ref()
.map_or(0, |v| v.get_and_increment()); .map_or(0, |v| v.get_and_increment());
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let sendable = self.reporter.completion_success( let sendable = self
buf.as_mut_slice(), .reporter
token, .completion_success(buf.as_mut_slice(), token, seq_count, msg_count, time_stamp)
seq_count, .map_err(PusError::ByteConversion)?;
msg_count, sender.send_tm(PusTmWrapper::Direct(sendable))?;
time_stamp, Ok(())
)?;
self.reporter
.send_step_or_completion_success(sendable, sender)
} }
/// Package and send a PUS TM\[1, 8\] packet, see 8.1.2.8 of the PUS standard. /// Package and send a PUS TM\[1, 8\] packet, see 8.1.2.8 of the PUS standard.
@ -1243,7 +1073,7 @@ pub mod alloc_mod {
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
sender: &(impl EcssTmSenderCore + ?Sized), sender: &(impl EcssTmSenderCore + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<TcState>> { ) -> Result<(), EcssTmtcError> {
let seq_count = self let seq_count = self
.seq_count_provider .seq_count_provider
.as_ref() .as_ref()
@ -1253,15 +1083,12 @@ pub mod alloc_mod {
.as_ref() .as_ref()
.map_or(0, |v| v.get_and_increment()); .map_or(0, |v| v.get_and_increment());
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let sendable = self.reporter.completion_failure( let sendable = self
buf.as_mut_slice(), .reporter
token, .completion_failure(buf.as_mut_slice(), token, seq_count, msg_count, params)
seq_count, .map_err(PusError::ByteConversion)?;
msg_count, sender.send_tm(PusTmWrapper::Direct(sendable))?;
params, Ok(())
)?;
self.reporter
.send_step_or_completion_failure(sendable, sender)
} }
} }
@ -1310,8 +1137,7 @@ pub mod alloc_mod {
&self, &self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<TcStateAccepted>, VerificationOrSendErrorWithToken<TcStateNone>> ) -> Result<VerificationToken<TcStateAccepted>, EcssTmtcError> {
{
self.reporter self.reporter
.acceptance_success(token, &self.sender, time_stamp) .acceptance_success(token, &self.sender, time_stamp)
} }
@ -1320,7 +1146,7 @@ pub mod alloc_mod {
&self, &self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<TcStateNone>> { ) -> Result<(), EcssTmtcError> {
self.reporter self.reporter
.acceptance_failure(token, &self.sender, params) .acceptance_failure(token, &self.sender, params)
} }
@ -1329,10 +1155,7 @@ pub mod alloc_mod {
&self, &self,
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
time_stamp: &[u8], time_stamp: &[u8],
) -> Result< ) -> Result<VerificationToken<TcStateStarted>, EcssTmtcError> {
VerificationToken<TcStateStarted>,
VerificationOrSendErrorWithToken<TcStateAccepted>,
> {
self.reporter.start_success(token, &self.sender, time_stamp) self.reporter.start_success(token, &self.sender, time_stamp)
} }
@ -1340,7 +1163,7 @@ pub mod alloc_mod {
&self, &self,
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<TcStateAccepted>> { ) -> Result<(), EcssTmtcError> {
self.reporter.start_failure(token, &self.sender, params) self.reporter.start_failure(token, &self.sender, params)
} }
@ -1358,7 +1181,7 @@ pub mod alloc_mod {
&self, &self,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
params: FailParamsWithStep, params: FailParamsWithStep,
) -> Result<(), VerificationOrSendErrorWithToken<TcStateStarted>> { ) -> Result<(), EcssTmtcError> {
self.reporter.step_failure(token, &self.sender, params) self.reporter.step_failure(token, &self.sender, params)
} }
@ -1366,7 +1189,7 @@ pub mod alloc_mod {
&self, &self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<(), VerificationOrSendErrorWithToken<TcState>> { ) -> Result<(), EcssTmtcError> {
self.reporter self.reporter
.completion_success(token, &self.sender, time_stamp) .completion_success(token, &self.sender, time_stamp)
} }
@ -1375,7 +1198,7 @@ pub mod alloc_mod {
&self, &self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationOrSendErrorWithToken<TcState>> { ) -> Result<(), EcssTmtcError> {
self.reporter self.reporter
.completion_failure(token, &self.sender, params) .completion_failure(token, &self.sender, params)
} }
@ -1490,10 +1313,7 @@ pub mod tests {
&self, &self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
_time_stamp: &[u8], _time_stamp: &[u8],
) -> Result< ) -> Result<VerificationToken<super::TcStateAccepted>, EcssTmtcError> {
VerificationToken<super::TcStateAccepted>,
super::VerificationOrSendErrorWithToken<TcStateNone>,
> {
let verif_map = self.verification_map.lock().unwrap(); let verif_map = self.verification_map.lock().unwrap();
match verif_map.borrow_mut().get_mut(&token.req_id) { match verif_map.borrow_mut().get_mut(&token.req_id) {
Some(entry) => entry.accepted = Some(true), Some(entry) => entry.accepted = Some(true),
@ -1512,7 +1332,7 @@ pub mod tests {
&self, &self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
params: FailParams, params: FailParams,
) -> Result<(), super::VerificationOrSendErrorWithToken<TcStateNone>> { ) -> Result<(), EcssTmtcError> {
let verif_map = self.verification_map.lock().unwrap(); let verif_map = self.verification_map.lock().unwrap();
match verif_map.borrow_mut().get_mut(&token.req_id) { match verif_map.borrow_mut().get_mut(&token.req_id) {
Some(entry) => { Some(entry) => {
@ -1532,10 +1352,7 @@ pub mod tests {
&self, &self,
token: VerificationToken<super::TcStateAccepted>, token: VerificationToken<super::TcStateAccepted>,
_time_stamp: &[u8], _time_stamp: &[u8],
) -> Result< ) -> Result<VerificationToken<super::TcStateStarted>, EcssTmtcError> {
VerificationToken<super::TcStateStarted>,
super::VerificationOrSendErrorWithToken<super::TcStateAccepted>,
> {
let verif_map = self.verification_map.lock().unwrap(); let verif_map = self.verification_map.lock().unwrap();
match verif_map.borrow_mut().get_mut(&token.req_id) { match verif_map.borrow_mut().get_mut(&token.req_id) {
Some(entry) => entry.started = Some(true), Some(entry) => entry.started = Some(true),
@ -1551,7 +1368,7 @@ pub mod tests {
&self, &self,
token: VerificationToken<super::TcStateAccepted>, token: VerificationToken<super::TcStateAccepted>,
params: FailParams, params: FailParams,
) -> Result<(), super::VerificationOrSendErrorWithToken<super::TcStateAccepted>> { ) -> Result<(), EcssTmtcError> {
let verif_map = self.verification_map.lock().unwrap(); let verif_map = self.verification_map.lock().unwrap();
match verif_map.borrow_mut().get_mut(&token.req_id) { match verif_map.borrow_mut().get_mut(&token.req_id) {
Some(entry) => { Some(entry) => {
@ -1585,7 +1402,7 @@ pub mod tests {
&self, &self,
token: VerificationToken<super::TcStateStarted>, token: VerificationToken<super::TcStateStarted>,
_params: FailParamsWithStep, _params: FailParamsWithStep,
) -> Result<(), super::VerificationOrSendErrorWithToken<super::TcStateStarted>> { ) -> Result<(), EcssTmtcError> {
let verif_map = self.verification_map.lock().unwrap(); let verif_map = self.verification_map.lock().unwrap();
match verif_map.borrow_mut().get_mut(&token.req_id) { match verif_map.borrow_mut().get_mut(&token.req_id) {
Some(entry) => { Some(entry) => {
@ -1600,7 +1417,7 @@ pub mod tests {
&self, &self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
_time_stamp: &[u8], _time_stamp: &[u8],
) -> Result<(), super::VerificationOrSendErrorWithToken<TcState>> { ) -> Result<(), EcssTmtcError> {
let verif_map = self.verification_map.lock().unwrap(); let verif_map = self.verification_map.lock().unwrap();
match verif_map.borrow_mut().get_mut(&token.req_id) { match verif_map.borrow_mut().get_mut(&token.req_id) {
Some(entry) => entry.completed = Some(true), Some(entry) => entry.completed = Some(true),
@ -1616,7 +1433,7 @@ pub mod tests {
&self, &self,
token: VerificationToken<TcState>, token: VerificationToken<TcState>,
params: FailParams, params: FailParams,
) -> Result<(), super::VerificationOrSendErrorWithToken<TcState>> { ) -> Result<(), EcssTmtcError> {
let verif_map = self.verification_map.lock().unwrap(); let verif_map = self.verification_map.lock().unwrap();
match verif_map.borrow_mut().get_mut(&token.req_id) { match verif_map.borrow_mut().get_mut(&token.req_id) {
Some(entry) => { Some(entry) => {
@ -1860,8 +1677,7 @@ pub mod tests {
let res = b.helper.acceptance_failure(tok, fail_params); let res = b.helper.acceptance_failure(tok, fail_params);
assert!(res.is_err()); assert!(res.is_err());
let err_with_token = res.unwrap_err(); let err_with_token = res.unwrap_err();
assert_eq!(err_with_token.1, tok); match err_with_token {
match err_with_token.0 {
EcssTmtcError::Pus(PusError::ByteConversion(e)) => match e { EcssTmtcError::Pus(PusError::ByteConversion(e)) => match e {
ByteConversionError::ToSliceTooSmall { found, expected } => { ByteConversionError::ToSliceTooSmall { found, expected } => {
assert_eq!( assert_eq!(
@ -1875,7 +1691,7 @@ pub mod tests {
} }
}, },
_ => { _ => {
panic!("{}", format!("Unexpected error {:?}", err_with_token.0)) panic!("{}", format!("Unexpected error {:?}", err_with_token))
} }
} }
} }

View File

@ -22,7 +22,7 @@
//! use satrs::tmtc::{ReceivesTc, ReceivesTcCore}; //! use satrs::tmtc::{ReceivesTc, ReceivesTcCore};
//! use spacepackets::{CcsdsPacket, SpHeader}; //! use spacepackets::{CcsdsPacket, SpHeader};
//! use spacepackets::ecss::WritablePusPacket; //! use spacepackets::ecss::WritablePusPacket;
//! use spacepackets::ecss::tc::{PusTc, PusTcCreator}; //! use spacepackets::ecss::tc::PusTcCreator;
//! //!
//! #[derive (Default)] //! #[derive (Default)]
//! struct ConcreteApidHandler { //! struct ConcreteApidHandler {

View File

@ -1,5 +1,5 @@
use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader}; use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
use spacepackets::time::cds::TimeProvider; use spacepackets::time::cds::CdsTime;
use spacepackets::time::TimeWriter; use spacepackets::time::TimeWriter;
use spacepackets::SpHeader; use spacepackets::SpHeader;
@ -66,7 +66,7 @@ impl PusTmWithCdsShortHelper {
source_data: &'a [u8], source_data: &'a [u8],
seq_count: u16, seq_count: u16,
) -> PusTmCreator { ) -> PusTmCreator {
let time_stamp = TimeProvider::from_now_with_u16_days().unwrap(); let time_stamp = CdsTime::now_with_u16_days().unwrap();
time_stamp.write_to_bytes(&mut self.cds_short_buf).unwrap(); time_stamp.write_to_bytes(&mut self.cds_short_buf).unwrap();
self.create_pus_tm_common(service, subservice, source_data, seq_count) self.create_pus_tm_common(service, subservice, source_data, seq_count)
} }
@ -76,7 +76,7 @@ impl PusTmWithCdsShortHelper {
service: u8, service: u8,
subservice: u8, subservice: u8,
source_data: &'a [u8], source_data: &'a [u8],
stamper: &TimeProvider, stamper: &CdsTime,
seq_count: u16, seq_count: u16,
) -> PusTmCreator { ) -> PusTmCreator {
stamper.write_to_bytes(&mut self.cds_short_buf).unwrap(); stamper.write_to_bytes(&mut self.cds_short_buf).unwrap();
@ -98,14 +98,14 @@ impl PusTmWithCdsShortHelper {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use spacepackets::{ecss::PusPacket, time::cds::TimeProvider, CcsdsPacket}; use spacepackets::{ecss::PusPacket, time::cds::CdsTime, CcsdsPacket};
use super::PusTmWithCdsShortHelper; use super::PusTmWithCdsShortHelper;
#[test] #[test]
fn test_helper_with_stamper() { fn test_helper_with_stamper() {
let mut pus_tm_helper = PusTmWithCdsShortHelper::new(0x123); let mut pus_tm_helper = PusTmWithCdsShortHelper::new(0x123);
let stamper = TimeProvider::new_with_u16_days(0, 0); let stamper = CdsTime::new_with_u16_days(0, 0);
let tm = pus_tm_helper.create_pus_tm_with_stamper(17, 1, &[1, 2, 3, 4], &stamper, 25); let tm = pus_tm_helper.create_pus_tm_with_stamper(17, 1, &[1, 2, 3, 4], &stamper, 25);
assert_eq!(tm.service(), 17); assert_eq!(tm.service(), 17);
assert_eq!(tm.subservice(), 1); assert_eq!(tm.subservice(), 1);

View File

@ -2,7 +2,7 @@
use core::mem::size_of; use core::mem::size_of;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use spacepackets::ecss::{PfcReal, PfcUnsigned, Ptc}; use spacepackets::ecss::{PfcReal, PfcUnsigned, Ptc};
use spacepackets::time::cds::TimeProvider; use spacepackets::time::cds::CdsTime;
use spacepackets::time::{CcsdsTimeProvider, TimeWriter}; use spacepackets::time::{CcsdsTimeProvider, TimeWriter};
enum NumOfParamsInfo { enum NumOfParamsInfo {
@ -36,7 +36,7 @@ struct TestMgmHkWithIndividualValidity {
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct TestMgmHkWithGroupValidity { struct TestMgmHkWithGroupValidity {
last_valid_stamp: TimeProvider, last_valid_stamp: CdsTime,
valid: bool, valid: bool,
temp: f32, temp: f32,
mgm_vals: [u16; 3], mgm_vals: [u16; 3],
@ -150,7 +150,7 @@ pub fn main() {
// The easiest and probably best approach, trading off big advantages for TM downlink capacity: // The easiest and probably best approach, trading off big advantages for TM downlink capacity:
// Use a JSON format // Use a JSON format
let mgm_hk_group_validity = TestMgmHkWithGroupValidity { let mgm_hk_group_validity = TestMgmHkWithGroupValidity {
last_valid_stamp: TimeProvider::from_now_with_u16_days().unwrap(), last_valid_stamp: CdsTime::now_with_u16_days().unwrap(),
valid: false, valid: false,
temp: 20.0, temp: 20.0,
mgm_vals: [0x1f1f, 0x2f2f, 0x3f3f], mgm_vals: [0x1f1f, 0x2f2f, 0x3f3f],