spacepackets update #51

Merged
muellerr merged 8 commits from update-for-spacepackets into main 2023-07-11 22:28:03 +02:00
23 changed files with 197 additions and 390 deletions

View File

@ -64,7 +64,7 @@ optional = true
# version = "0.6" # version = "0.6"
# path = "../spacepackets" # path = "../spacepackets"
git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git" git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git"
rev = "784564a20ed" rev = "62df510147b"
default-features = false default-features = false
[dev-dependencies] [dev-dependencies]

View File

@ -22,7 +22,7 @@ use std::vec::Vec;
/// use satrs_core::hal::host::udp_server::UdpTcServer; /// use satrs_core::hal::host::udp_server::UdpTcServer;
/// use satrs_core::tmtc::{ReceivesTc, ReceivesTcCore}; /// use satrs_core::tmtc::{ReceivesTc, ReceivesTcCore};
/// use spacepackets::SpHeader; /// use spacepackets::SpHeader;
/// use spacepackets::tc::PusTc; /// use spacepackets::ecss::tc::PusTcCreator;
/// ///
/// #[derive (Default)] /// #[derive (Default)]
/// struct PingReceiver {} /// struct PingReceiver {}
@ -40,7 +40,7 @@ use std::vec::Vec;
/// let mut udp_tc_server = UdpTcServer::new(dest_addr, 2048, Box::new(ping_receiver)) /// let mut udp_tc_server = UdpTcServer::new(dest_addr, 2048, Box::new(ping_receiver))
/// .expect("Creating UDP TMTC server failed"); /// .expect("Creating UDP TMTC server failed");
/// let mut sph = SpHeader::tc_unseg(0x02, 0, 0).unwrap(); /// let mut sph = SpHeader::tc_unseg(0x02, 0, 0).unwrap();
/// let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true); /// let pus_tc = PusTcCreator::new_simple(&mut sph, 17, 1, None, true);
/// let len = pus_tc /// let len = pus_tc
/// .write_to_bytes(&mut buf) /// .write_to_bytes(&mut buf)
/// .expect("Error writing PUS TC packet"); /// .expect("Error writing PUS TC packet");
@ -142,8 +142,8 @@ impl<E: 'static> UdpTcServer<E> {
mod tests { mod tests {
use crate::hal::host::udp_server::{ReceiveResult, UdpTcServer}; use crate::hal::host::udp_server::{ReceiveResult, UdpTcServer};
use crate::tmtc::ReceivesTcCore; use crate::tmtc::ReceivesTcCore;
use spacepackets::ecss::tc::PusTcCreator;
use spacepackets::ecss::SerializablePusPacket; use spacepackets::ecss::SerializablePusPacket;
use spacepackets::tc::PusTc;
use spacepackets::SpHeader; use spacepackets::SpHeader;
use std::boxed::Box; use std::boxed::Box;
use std::collections::VecDeque; use std::collections::VecDeque;
@ -178,7 +178,7 @@ mod tests {
.expect("Creating UDP TMTC server failed"); .expect("Creating UDP TMTC server failed");
is_send(&udp_tc_server); is_send(&udp_tc_server);
let mut sph = SpHeader::tc_unseg(0x02, 0, 0).unwrap(); let mut sph = SpHeader::tc_unseg(0x02, 0, 0).unwrap();
let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true); let pus_tc = PusTcCreator::new_simple(&mut sph, 17, 1, None, true);
let len = pus_tc let len = pus_tc
.write_to_bytes(&mut buf) .write_to_bytes(&mut buf)
.expect("Error writing PUS TC packet"); .expect("Error writing PUS TC packet");

View File

@ -1,7 +1,7 @@
use crate::pus::{source_buffer_large_enough, EcssTmtcError}; use crate::pus::{source_buffer_large_enough, EcssTmtcError};
use spacepackets::ecss::tm::PusTmCreator;
use spacepackets::ecss::tm::PusTmSecondaryHeader;
use spacepackets::ecss::{EcssEnumeration, PusError}; use spacepackets::ecss::{EcssEnumeration, PusError};
use spacepackets::tm::PusTm;
use spacepackets::tm::PusTmSecondaryHeader;
use spacepackets::{SpHeader, MAX_APID}; use spacepackets::{SpHeader, MAX_APID};
use crate::pus::EcssTmSenderCore; use crate::pus::EcssTmSenderCore;
@ -121,7 +121,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<PusTmCreator, EcssTmtcError> {
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();
@ -144,7 +144,7 @@ impl EventReporterBase {
buf[current_idx..current_idx + aux_data.len()].copy_from_slice(aux_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(PusTm::new( Ok(PusTmCreator::new(
&mut sp_header, &mut sp_header,
sec_header, sec_header,
Some(&buf[0..current_idx]), Some(&buf[0..current_idx]),
@ -281,8 +281,8 @@ mod tests {
panic!("TestSender: unexpected call with address"); panic!("TestSender: unexpected call with address");
} }
PusTmWrapper::Direct(tm) => { PusTmWrapper::Direct(tm) => {
assert!(tm.source_data().is_some()); assert!(!tm.source_data().is_empty());
let src_data = tm.source_data().unwrap(); let src_data = tm.source_data();
assert!(src_data.len() >= 4); assert!(src_data.len() >= 4);
let event = let event =
EventU32::from(u32::from_be_bytes(src_data[0..4].try_into().unwrap())); EventU32::from(u32::from_be_bytes(src_data[0..4].try_into().unwrap()));

View File

@ -9,8 +9,8 @@ use crate::pus::{
PusPacketHandlingError, PusServiceBase, PusServiceHandler, PusPacketHandlingError, PusServiceBase, PusServiceHandler,
}; };
use spacepackets::ecss::event::Subservice; use spacepackets::ecss::event::Subservice;
use spacepackets::ecss::tc::PusTcReader;
use spacepackets::ecss::PusPacket; use spacepackets::ecss::PusPacket;
use spacepackets::tc::PusTc;
use std::boxed::Box; use std::boxed::Box;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
@ -55,7 +55,7 @@ impl PusServiceHandler for PusService5EventHandler {
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> { ) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
self.copy_tc_to_buf(addr)?; self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTc::from_bytes(&self.psb.pus_buf)?; let (tc, _) = PusTcReader::new(&self.psb.pus_buf)?;
let subservice = tc.subservice(); let subservice = tc.subservice();
let srv = Subservice::try_from(subservice); let srv = Subservice::try_from(subservice);
if srv.is_err() { if srv.is_err() {
@ -65,12 +65,12 @@ impl PusServiceHandler for PusService5EventHandler {
)); ));
} }
let handle_enable_disable_request = |enable: bool, stamp: [u8; 7]| { let handle_enable_disable_request = |enable: bool, stamp: [u8; 7]| {
if tc.user_data().is_none() || tc.user_data().unwrap().len() < 4 { if tc.user_data().len() < 4 {
return Err(PusPacketHandlingError::NotEnoughAppData( return Err(PusPacketHandlingError::NotEnoughAppData(
"At least 4 bytes event ID expected".into(), "At least 4 bytes event ID expected".into(),
)); ));
} }
let user_data = tc.user_data().unwrap(); let user_data = tc.user_data();
let event_u32 = EventU32::from(u32::from_be_bytes(user_data[0..4].try_into().unwrap())); let event_u32 = EventU32::from(u32::from_be_bytes(user_data[0..4].try_into().unwrap()));
let start_token = self let start_token = self
.psb .psb

View File

@ -8,9 +8,9 @@ use core::fmt::{Display, Formatter};
use downcast_rs::{impl_downcast, Downcast}; use downcast_rs::{impl_downcast, Downcast};
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use dyn_clone::DynClone; use dyn_clone::DynClone;
use spacepackets::ecss::tc::{PusTcCreator, PusTcReader};
use spacepackets::ecss::tm::PusTmCreator;
use spacepackets::ecss::PusError; use spacepackets::ecss::PusError;
use spacepackets::tc::PusTc;
use spacepackets::tm::PusTm;
use spacepackets::{ByteConversionError, SizeMissmatch, SpHeader}; use spacepackets::{ByteConversionError, SizeMissmatch, SpHeader};
use std::error::Error; use std::error::Error;
@ -36,7 +36,7 @@ pub use std_mod::*;
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
pub enum PusTmWrapper<'tm> { pub enum PusTmWrapper<'tm> {
InStore(StoreAddr), InStore(StoreAddr),
Direct(PusTm<'tm>), Direct(PusTmCreator<'tm>),
} }
impl From<StoreAddr> for PusTmWrapper<'_> { impl From<StoreAddr> for PusTmWrapper<'_> {
@ -45,8 +45,8 @@ impl From<StoreAddr> for PusTmWrapper<'_> {
} }
} }
impl<'tm> From<PusTm<'tm>> for PusTmWrapper<'tm> { impl<'tm> From<PusTmCreator<'tm>> for PusTmWrapper<'tm> {
fn from(value: PusTm<'tm>) -> Self { fn from(value: PusTmCreator<'tm>) -> Self {
Self::Direct(value) Self::Direct(value)
} }
} }
@ -193,7 +193,7 @@ pub trait EcssTmSenderCore: EcssChannel {
/// This sender object is responsible for sending PUS telecommands to a TC recipient. Each /// 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. /// telecommand can optionally have a token which contains its verification state.
pub trait EcssTcSenderCore: EcssChannel { pub trait EcssTcSenderCore: EcssChannel {
fn send_tc(&self, tc: PusTc, token: Option<TcStateToken>) -> Result<(), EcssTmtcError>; fn send_tc(&self, tc: PusTcCreator, token: Option<TcStateToken>) -> Result<(), EcssTmtcError>;
} }
pub struct ReceivedTcWrapper { pub struct ReceivedTcWrapper {
@ -232,10 +232,12 @@ pub trait EcssTcReceiverCore: EcssChannel {
/// Generic trait for objects which can receive ECSS PUS telecommands. This trait is /// Generic trait for objects which can receive ECSS PUS telecommands. This trait is
/// implemented by the [crate::tmtc::pus_distrib::PusDistributor] objects to allow passing PUS TC /// implemented by the [crate::tmtc::pus_distrib::PusDistributor] objects to allow passing PUS TC
/// packets into it. /// packets into it. It is generally assumed that the telecommand is stored in some pool structure,
/// and the store address is passed as well. This allows efficient zero-copy forwarding of
/// telecommands.
pub trait ReceivesEcssPusTc { pub trait ReceivesEcssPusTc {
type Error; type Error;
fn pass_pus_tc(&mut self, header: &SpHeader, pus_tc: &PusTc) -> Result<(), Self::Error>; fn pass_pus_tc(&mut self, header: &SpHeader, pus_tc: &PusTcReader) -> Result<(), Self::Error>;
} }
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
@ -317,11 +319,11 @@ pub mod std_mod {
use crate::ChannelId; use crate::ChannelId;
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::vec::Vec; use alloc::vec::Vec;
use spacepackets::ecss::tm::PusTmCreator;
use spacepackets::ecss::PusError; use spacepackets::ecss::PusError;
use spacepackets::time::cds::TimeProvider; use spacepackets::time::cds::TimeProvider;
use spacepackets::time::StdTimestampError; use spacepackets::time::StdTimestampError;
use spacepackets::time::TimeWriter; use spacepackets::time::TimeWriter;
use spacepackets::tm::PusTm;
use std::cell::RefCell; use std::cell::RefCell;
use std::string::String; use std::string::String;
use std::sync::mpsc; use std::sync::mpsc;
@ -353,7 +355,7 @@ pub mod std_mod {
} }
} }
impl MpscTmInStoreSender { impl MpscTmInStoreSender {
pub fn send_direct_tm(&self, tm: PusTm) -> Result<(), EcssTmtcError> { pub fn send_direct_tm(&self, tm: PusTmCreator) -> Result<(), EcssTmtcError> {
let addr = self.shared_tm_store.add_pus_tm(&tm)?; let addr = self.shared_tm_store.add_pus_tm(&tm)?;
self.sender self.sender
.send(addr) .send(addr)
@ -641,7 +643,7 @@ pub(crate) fn source_buffer_large_enough(cap: usize, len: usize) -> Result<(), E
#[cfg(test)] #[cfg(test)]
pub(crate) mod tests { pub(crate) mod tests {
use spacepackets::tm::{GenericPusTmSecondaryHeader, PusTm}; use spacepackets::ecss::tm::{GenericPusTmSecondaryHeader, PusTmCreator};
use spacepackets::CcsdsPacket; use spacepackets::CcsdsPacket;
#[derive(Debug, Eq, PartialEq, Clone)] #[derive(Debug, Eq, PartialEq, Clone)]
@ -654,9 +656,9 @@ pub(crate) mod tests {
} }
impl CommonTmInfo { impl CommonTmInfo {
pub fn new_from_tm(tm: &PusTm) -> Self { pub fn new_from_tm(tm: &PusTmCreator) -> Self {
let mut time_stamp = [0; 7]; let mut time_stamp = [0; 7];
time_stamp.clone_from_slice(&tm.timestamp().unwrap()[0..7]); time_stamp.clone_from_slice(&tm.timestamp()[0..7]);
Self { Self {
subservice: tm.subservice(), subservice: tm.subservice(),
apid: tm.apid(), apid: tm.apid(),

View File

@ -8,8 +8,8 @@ use core::time::Duration;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use spacepackets::ecss::scheduling::TimeWindowType; use spacepackets::ecss::scheduling::TimeWindowType;
use spacepackets::ecss::tc::{GenericPusTcSecondaryHeader, IsPusTelecommand};
use spacepackets::ecss::PusError; use spacepackets::ecss::PusError;
use spacepackets::tc::{GenericPusTcSecondaryHeader, PusTc};
use spacepackets::time::{CcsdsTimeProvider, TimestampError, UnixTimestamp}; use spacepackets::time::{CcsdsTimeProvider, TimestampError, UnixTimestamp};
use spacepackets::CcsdsPacket; use spacepackets::CcsdsPacket;
#[cfg(feature = "std")] #[cfg(feature = "std")]
@ -46,7 +46,9 @@ impl RequestId {
self.seq_count self.seq_count
} }
pub fn from_tc(tc: &PusTc) -> Self { pub fn from_tc(
tc: &(impl CcsdsPacket + GenericPusTcSecondaryHeader + IsPusTelecommand),
) -> Self {
RequestId { RequestId {
source_id: tc.source_id(), source_id: tc.source_id(),
apid: tc.apid(), apid: tc.apid(),
@ -57,22 +59,6 @@ impl RequestId {
pub fn as_u64(&self) -> u64 { pub fn as_u64(&self) -> u64 {
((self.source_id as u64) << 32) | ((self.apid as u64) << 16) | self.seq_count as u64 ((self.source_id as u64) << 32) | ((self.apid as u64) << 16) | self.seq_count as u64
} }
/*
pub fn from_bytes(buf: &[u8]) -> Result<Self, ByteConversionError> {
if buf.len() < core::mem::size_of::<u64>() {
return Err(ByteConversionError::FromSliceTooSmall(SizeMissmatch {
found: buf.len(),
expected: core::mem::size_of::<u64>(),
}));
}
Ok(Self {
source_id: u16::from_be_bytes(buf[0..2].try_into().unwrap()),
apid: u16::from_be_bytes(buf[2..4].try_into().unwrap()),
seq_count: u16::from_be_bytes(buf[4..6].try_into().unwrap()),
})
}
*/
} }
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
@ -239,8 +225,10 @@ pub mod alloc_mod {
use alloc::vec::Vec; use alloc::vec::Vec;
use core::time::Duration; use core::time::Duration;
use spacepackets::ecss::scheduling::TimeWindowType; use spacepackets::ecss::scheduling::TimeWindowType;
use spacepackets::ecss::tc::{
GenericPusTcSecondaryHeader, IsPusTelecommand, PusTc, PusTcReader,
};
use spacepackets::ecss::PusPacket; use spacepackets::ecss::PusPacket;
use spacepackets::tc::PusTc;
use spacepackets::time::cds::DaysLen24Bits; use spacepackets::time::cds::DaysLen24Bits;
use spacepackets::time::{cds, CcsdsTimeProvider, TimeReader, UnixTimestamp}; use spacepackets::time::{cds, CcsdsTimeProvider, TimeReader, UnixTimestamp};
@ -387,7 +375,7 @@ pub mod alloc_mod {
tc: &[u8], tc: &[u8],
pool: &mut (impl PoolProvider + ?Sized), pool: &mut (impl PoolProvider + ?Sized),
) -> Result<TcInfo, ScheduleError> { ) -> Result<TcInfo, ScheduleError> {
let check_tc = PusTc::from_bytes(tc)?; let check_tc = PusTcReader::new(tc)?;
if PusPacket::service(&check_tc.0) == 11 && PusPacket::subservice(&check_tc.0) == 4 { if PusPacket::service(&check_tc.0) == 11 && PusPacket::subservice(&check_tc.0) == 4 {
return Err(ScheduleError::NestedScheduledTc); return Err(ScheduleError::NestedScheduledTc);
} }
@ -407,7 +395,7 @@ pub mod alloc_mod {
/// provider needs to be supplied via a generic. /// provider needs to be supplied via a generic.
pub fn insert_wrapped_tc<TimeStamp: CcsdsTimeProvider + TimeReader>( pub fn insert_wrapped_tc<TimeStamp: CcsdsTimeProvider + TimeReader>(
&mut self, &mut self,
pus_tc: &PusTc, pus_tc: &(impl IsPusTelecommand + PusPacket + GenericPusTcSecondaryHeader),
pool: &mut (impl PoolProvider + ?Sized), pool: &mut (impl PoolProvider + ?Sized),
) -> Result<TcInfo, ScheduleError> { ) -> Result<TcInfo, ScheduleError> {
if PusPacket::service(pus_tc) != 11 { if PusPacket::service(pus_tc) != 11 {
@ -416,14 +404,14 @@ pub mod alloc_mod {
if PusPacket::subservice(pus_tc) != 4 { if PusPacket::subservice(pus_tc) != 4 {
return Err(ScheduleError::WrongSubservice); return Err(ScheduleError::WrongSubservice);
} }
return if let Some(user_data) = pus_tc.user_data() { if pus_tc.user_data().is_empty() {
return Err(ScheduleError::TcDataEmpty);
}
let user_data = pus_tc.user_data();
let stamp: TimeStamp = TimeReader::from_bytes(user_data)?; let stamp: TimeStamp = TimeReader::from_bytes(user_data)?;
let unix_stamp = stamp.unix_stamp(); let unix_stamp = stamp.unix_stamp();
let stamp_len = stamp.len_as_bytes(); let stamp_len = stamp.len_as_bytes();
self.insert_unwrapped_tc(unix_stamp, &user_data[stamp_len..], pool) self.insert_unwrapped_tc(unix_stamp, &user_data[stamp_len..], pool)
} else {
Err(ScheduleError::TcDataEmpty)
};
} }
/// Insert a telecommand based on the fully wrapped time-tagged telecommand using a CDS /// Insert a telecommand based on the fully wrapped time-tagged telecommand using a CDS
@ -641,8 +629,8 @@ mod tests {
use super::*; use super::*;
use crate::pool::{LocalPool, PoolCfg, PoolProvider, StoreAddr, StoreError}; use crate::pool::{LocalPool, PoolCfg, PoolProvider, StoreAddr, StoreError};
use alloc::collections::btree_map::Range; use alloc::collections::btree_map::Range;
use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader};
use spacepackets::ecss::SerializablePusPacket; use spacepackets::ecss::SerializablePusPacket;
use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
use spacepackets::time::{cds, TimeWriter, UnixTimestamp}; use spacepackets::time::{cds, TimeWriter, UnixTimestamp};
use spacepackets::SpHeader; use spacepackets::SpHeader;
use std::time::Duration; use std::time::Duration;
@ -662,32 +650,32 @@ mod tests {
) )
} }
fn scheduled_tc(timestamp: UnixTimestamp, buf: &mut [u8]) -> PusTc { fn scheduled_tc(timestamp: UnixTimestamp, buf: &mut [u8]) -> PusTcCreator {
let (mut sph, len_app_data) = pus_tc_base(timestamp, buf); let (mut sph, len_app_data) = pus_tc_base(timestamp, buf);
PusTc::new_simple(&mut sph, 11, 4, Some(&buf[..len_app_data]), true) PusTcCreator::new_simple(&mut sph, 11, 4, Some(&buf[..len_app_data]), true)
} }
fn wrong_tc_service(timestamp: UnixTimestamp, buf: &mut [u8]) -> PusTc { fn wrong_tc_service(timestamp: UnixTimestamp, buf: &mut [u8]) -> PusTcCreator {
let (mut sph, len_app_data) = pus_tc_base(timestamp, buf); let (mut sph, len_app_data) = pus_tc_base(timestamp, buf);
PusTc::new_simple(&mut sph, 12, 4, Some(&buf[..len_app_data]), true) PusTcCreator::new_simple(&mut sph, 12, 4, Some(&buf[..len_app_data]), true)
} }
fn wrong_tc_subservice(timestamp: UnixTimestamp, buf: &mut [u8]) -> PusTc { fn wrong_tc_subservice(timestamp: UnixTimestamp, buf: &mut [u8]) -> PusTcCreator {
let (mut sph, len_app_data) = pus_tc_base(timestamp, buf); let (mut sph, len_app_data) = pus_tc_base(timestamp, buf);
PusTc::new_simple(&mut sph, 11, 5, Some(&buf[..len_app_data]), true) PusTcCreator::new_simple(&mut sph, 11, 5, Some(&buf[..len_app_data]), true)
} }
fn double_wrapped_time_tagged_tc(timestamp: UnixTimestamp, buf: &mut [u8]) -> PusTc { fn double_wrapped_time_tagged_tc(timestamp: UnixTimestamp, buf: &mut [u8]) -> PusTcCreator {
let cds_time = cds::TimeProvider::from_unix_secs_with_u16_days(&timestamp).unwrap(); let cds_time = cds::TimeProvider::from_unix_secs_with_u16_days(&timestamp).unwrap();
let len_time_stamp = cds_time.write_to_bytes(buf).unwrap(); let len_time_stamp = cds_time.write_to_bytes(buf).unwrap();
let mut sph = SpHeader::tc_unseg(0x02, 0x34, 0).unwrap(); let mut sph = SpHeader::tc_unseg(0x02, 0x34, 0).unwrap();
// app data should not matter, double wrapped time-tagged commands should be rejected right // app data should not matter, double wrapped time-tagged commands should be rejected right
// away // away
let inner_time_tagged_tc = PusTc::new_simple(&mut sph, 11, 4, None, true); let inner_time_tagged_tc = PusTcCreator::new_simple(&mut sph, 11, 4, None, true);
let packet_len = inner_time_tagged_tc let packet_len = inner_time_tagged_tc
.write_to_bytes(&mut buf[len_time_stamp..]) .write_to_bytes(&mut buf[len_time_stamp..])
.expect("writing inner time tagged tc failed"); .expect("writing inner time tagged tc failed");
PusTc::new_simple( PusTcCreator::new_simple(
&mut sph, &mut sph,
11, 11,
4, 4,
@ -696,14 +684,17 @@ mod tests {
) )
} }
fn invalid_time_tagged_cmd() -> PusTc<'static> { fn invalid_time_tagged_cmd() -> PusTcCreator<'static> {
let mut sph = SpHeader::tc_unseg(0x02, 0x34, 1).unwrap(); let mut sph = SpHeader::tc_unseg(0x02, 0x34, 1).unwrap();
PusTc::new_simple(&mut sph, 11, 4, None, true) PusTcCreator::new_simple(&mut sph, 11, 4, None, true)
} }
fn base_ping_tc_simple_ctor(seq_count: u16, app_data: Option<&'static [u8]>) -> PusTc<'static> { fn base_ping_tc_simple_ctor(
seq_count: u16,
app_data: Option<&'static [u8]>,
) -> PusTcCreator<'static> {
let mut sph = SpHeader::tc_unseg(0x02, seq_count, 0).unwrap(); let mut sph = SpHeader::tc_unseg(0x02, seq_count, 0).unwrap();
PusTc::new_simple(&mut sph, 17, 1, app_data, true) PusTcCreator::new_simple(&mut sph, 17, 1, app_data, true)
} }
fn ping_tc_to_store( fn ping_tc_to_store(
@ -870,7 +861,7 @@ mod tests {
let mut sp_header = SpHeader::tc_unseg(apid_to_set, 105, 0).unwrap(); let mut sp_header = SpHeader::tc_unseg(apid_to_set, 105, 0).unwrap();
let mut sec_header = PusTcSecondaryHeader::new_simple(17, 1); let mut sec_header = PusTcSecondaryHeader::new_simple(17, 1);
sec_header.source_id = src_id_to_set; sec_header.source_id = src_id_to_set;
let ping_tc = PusTc::new(&mut sp_header, sec_header, None, true); let ping_tc = PusTcCreator::new(&mut sp_header, sec_header, None, true);
let req_id = RequestId::from_tc(&ping_tc); let req_id = RequestId::from_tc(&ping_tc);
assert_eq!(req_id.source_id(), src_id_to_set); assert_eq!(req_id.source_id(), src_id_to_set);
assert_eq!(req_id.apid(), apid_to_set); assert_eq!(req_id.apid(), apid_to_set);
@ -1085,7 +1076,7 @@ mod tests {
assert!(pool.has_element_at(&tc_info_0.addr()).unwrap()); assert!(pool.has_element_at(&tc_info_0.addr()).unwrap());
let data = pool.read(&tc_info_0.addr()).unwrap(); let data = pool.read(&tc_info_0.addr()).unwrap();
let check_tc = PusTc::from_bytes(&data).expect("incorrect Pus tc raw data"); let check_tc = PusTcReader::new(&data).expect("incorrect Pus tc raw data");
assert_eq!(check_tc.0, base_ping_tc_simple_ctor(0, None)); assert_eq!(check_tc.0, base_ping_tc_simple_ctor(0, None));
assert_eq!(scheduler.num_scheduled_telecommands(), 1); assert_eq!(scheduler.num_scheduled_telecommands(), 1);
@ -1107,7 +1098,7 @@ mod tests {
.unwrap(); .unwrap();
let data = pool.read(&addr_vec[0]).unwrap(); let data = pool.read(&addr_vec[0]).unwrap();
let check_tc = PusTc::from_bytes(&data).expect("incorrect Pus tc raw data"); let check_tc = PusTcReader::new(&data).expect("incorrect Pus tc raw data");
assert_eq!(check_tc.0, base_ping_tc_simple_ctor(0, None)); assert_eq!(check_tc.0, base_ping_tc_simple_ctor(0, None));
} }
@ -1131,7 +1122,7 @@ mod tests {
assert!(pool.has_element_at(&info.addr).unwrap()); assert!(pool.has_element_at(&info.addr).unwrap());
let data = pool.read(&info.addr).unwrap(); let data = pool.read(&info.addr).unwrap();
let check_tc = PusTc::from_bytes(&data).expect("incorrect Pus tc raw data"); let check_tc = PusTcReader::new(&data).expect("incorrect Pus tc raw data");
assert_eq!(check_tc.0, base_ping_tc_simple_ctor(0, None)); assert_eq!(check_tc.0, base_ping_tc_simple_ctor(0, None));
assert_eq!(scheduler.num_scheduled_telecommands(), 1); assert_eq!(scheduler.num_scheduled_telecommands(), 1);
@ -1153,7 +1144,7 @@ mod tests {
.unwrap(); .unwrap();
let data = pool.read(&addr_vec[0]).unwrap(); let data = pool.read(&addr_vec[0]).unwrap();
let check_tc = PusTc::from_bytes(&data).expect("incorrect Pus tc raw data"); let check_tc = PusTcReader::new(&data).expect("incorrect PUS tc raw data");
assert_eq!(check_tc.0, base_ping_tc_simple_ctor(0, None)); assert_eq!(check_tc.0, base_ping_tc_simple_ctor(0, None));
} }

View File

@ -5,8 +5,8 @@ use crate::pus::{
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase, EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase,
PusServiceHandler, PusServiceHandler,
}; };
use spacepackets::ecss::tc::PusTcReader;
use spacepackets::ecss::{scheduling, PusPacket}; use spacepackets::ecss::{scheduling, PusPacket};
use spacepackets::tc::PusTc;
use spacepackets::time::cds::TimeProvider; use spacepackets::time::cds::TimeProvider;
use std::boxed::Box; use std::boxed::Box;
@ -67,7 +67,7 @@ impl PusServiceHandler for PusService11SchedHandler {
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> { ) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
self.copy_tc_to_buf(addr)?; self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTc::from_bytes(&self.psb.pus_buf)?; let (tc, _) = PusTcReader::new(&self.psb.pus_buf)?;
let subservice = tc.subservice(); let subservice = tc.subservice();
let std_service = scheduling::Subservice::try_from(subservice); let std_service = scheduling::Subservice::try_from(subservice);
if std_service.is_err() { if std_service.is_err() {

View File

@ -4,9 +4,9 @@ use crate::pus::{
EcssTcReceiver, EcssTmSender, PartialPusHandlingError, PusPacketHandlerResult, EcssTcReceiver, EcssTmSender, PartialPusHandlingError, PusPacketHandlerResult,
PusPacketHandlingError, PusServiceBase, PusServiceHandler, PusTmWrapper, PusPacketHandlingError, PusServiceBase, PusServiceHandler, PusTmWrapper,
}; };
use spacepackets::ecss::tc::PusTcReader;
use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
use spacepackets::ecss::PusPacket; use spacepackets::ecss::PusPacket;
use spacepackets::tc::PusTc;
use spacepackets::tm::{PusTm, PusTmSecondaryHeader};
use spacepackets::SpHeader; use spacepackets::SpHeader;
use std::boxed::Box; use std::boxed::Box;
@ -50,7 +50,7 @@ impl PusServiceHandler for PusService17TestHandler {
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> { ) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
self.copy_tc_to_buf(addr)?; self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTc::from_bytes(&self.psb.pus_buf)?; let (tc, _) = PusTcReader::new(&self.psb.pus_buf)?;
if tc.service() != 17 { if tc.service() != 17 {
return Err(PusPacketHandlingError::WrongService(tc.service())); return Err(PusPacketHandlingError::WrongService(tc.service()));
} }
@ -72,7 +72,7 @@ impl PusServiceHandler for PusService17TestHandler {
// Sequence count will be handled centrally in TM funnel. // Sequence count will be handled centrally in TM funnel.
let mut reply_header = SpHeader::tm_unseg(self.psb.tm_apid, 0, 0).unwrap(); let mut reply_header = SpHeader::tm_unseg(self.psb.tm_apid, 0, 0).unwrap();
let tc_header = PusTmSecondaryHeader::new_simple(17, 2, &time_stamp); let tc_header = PusTmSecondaryHeader::new_simple(17, 2, &time_stamp);
let ping_reply = PusTm::new(&mut reply_header, tc_header, None, true); let ping_reply = PusTmCreator::new(&mut reply_header, tc_header, None, true);
let result = self let result = self
.psb .psb
.tm_sender .tm_sender
@ -116,9 +116,9 @@ mod tests {
}; };
use crate::pus::{MpscTcInStoreReceiver, MpscTmInStoreSender, PusServiceHandler}; use crate::pus::{MpscTcInStoreReceiver, MpscTmInStoreSender, PusServiceHandler};
use crate::tmtc::tm_helper::SharedTmStore; use crate::tmtc::tm_helper::SharedTmStore;
use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader};
use spacepackets::ecss::tm::PusTmReader;
use spacepackets::ecss::{PusPacket, SerializablePusPacket}; use spacepackets::ecss::{PusPacket, SerializablePusPacket};
use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
use spacepackets::tm::PusTm;
use spacepackets::{SequenceFlags, SpHeader}; use spacepackets::{SequenceFlags, SpHeader};
use std::boxed::Box; use std::boxed::Box;
use std::sync::{mpsc, RwLock}; use std::sync::{mpsc, RwLock};
@ -154,7 +154,7 @@ mod tests {
// Create a ping TC, verify acceptance. // Create a ping TC, verify acceptance.
let mut sp_header = SpHeader::tc(TEST_APID, SequenceFlags::Unsegmented, 0, 0).unwrap(); let mut sp_header = SpHeader::tc(TEST_APID, SequenceFlags::Unsegmented, 0, 0).unwrap();
let sec_header = PusTcSecondaryHeader::new_simple(17, 1); let sec_header = PusTcSecondaryHeader::new_simple(17, 1);
let ping_tc = PusTc::new(&mut sp_header, sec_header, None, true); let ping_tc = PusTcCreator::new(&mut sp_header, sec_header, None, true);
let token = verification_handler.add_tc(&ping_tc); let token = verification_handler.add_tc(&ping_tc);
let token = verification_handler let token = verification_handler
.acceptance_success(token, None) .acceptance_success(token, None)
@ -174,10 +174,10 @@ mod tests {
let mut tm_addr = next_msg.unwrap(); let mut tm_addr = next_msg.unwrap();
let tm_pool = tm_pool_shared.read().unwrap(); let tm_pool = tm_pool_shared.read().unwrap();
let tm_raw = tm_pool.read(&tm_addr).unwrap(); let tm_raw = tm_pool.read(&tm_addr).unwrap();
let (tm, _) = PusTm::from_bytes(&tm_raw, 0).unwrap(); let (tm, _) = PusTmReader::new(&tm_raw, 0).unwrap();
assert_eq!(tm.service(), 1); assert_eq!(tm.service(), 1);
assert_eq!(tm.subservice(), 1); assert_eq!(tm.subservice(), 1);
let req_id = RequestId::from_bytes(tm.user_data().unwrap()).unwrap(); let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
assert_eq!(req_id, token.req_id()); assert_eq!(req_id, token.req_id());
// Acceptance TM // Acceptance TM
@ -186,10 +186,10 @@ mod tests {
tm_addr = next_msg.unwrap(); tm_addr = next_msg.unwrap();
let tm_raw = tm_pool.read(&tm_addr).unwrap(); let tm_raw = tm_pool.read(&tm_addr).unwrap();
// Is generated with CDS short timestamp. // Is generated with CDS short timestamp.
let (tm, _) = PusTm::from_bytes(&tm_raw, 7).unwrap(); let (tm, _) = PusTmReader::new(&tm_raw, 7).unwrap();
assert_eq!(tm.service(), 1); assert_eq!(tm.service(), 1);
assert_eq!(tm.subservice(), 3); assert_eq!(tm.subservice(), 3);
let req_id = RequestId::from_bytes(tm.user_data().unwrap()).unwrap(); let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
assert_eq!(req_id, token.req_id()); assert_eq!(req_id, token.req_id());
// Ping reply // Ping reply
@ -198,10 +198,10 @@ mod tests {
tm_addr = next_msg.unwrap(); tm_addr = next_msg.unwrap();
let tm_raw = tm_pool.read(&tm_addr).unwrap(); let tm_raw = tm_pool.read(&tm_addr).unwrap();
// Is generated with CDS short timestamp. // Is generated with CDS short timestamp.
let (tm, _) = PusTm::from_bytes(&tm_raw, 7).unwrap(); let (tm, _) = PusTmReader::new(&tm_raw, 7).unwrap();
assert_eq!(tm.service(), 17); assert_eq!(tm.service(), 17);
assert_eq!(tm.subservice(), 2); assert_eq!(tm.subservice(), 2);
assert!(tm.user_data().is_none()); assert!(tm.user_data().is_empty());
// TM completion // TM completion
next_msg = tm_rx.try_recv(); next_msg = tm_rx.try_recv();
@ -209,10 +209,10 @@ mod tests {
tm_addr = next_msg.unwrap(); tm_addr = next_msg.unwrap();
let tm_raw = tm_pool.read(&tm_addr).unwrap(); let tm_raw = tm_pool.read(&tm_addr).unwrap();
// Is generated with CDS short timestamp. // Is generated with CDS short timestamp.
let (tm, _) = PusTm::from_bytes(&tm_raw, 7).unwrap(); let (tm, _) = PusTmReader::new(&tm_raw, 7).unwrap();
assert_eq!(tm.service(), 1); assert_eq!(tm.service(), 1);
assert_eq!(tm.subservice(), 7); assert_eq!(tm.subservice(), 7);
let req_id = RequestId::from_bytes(tm.user_data().unwrap()).unwrap(); let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
assert_eq!(req_id, token.req_id()); assert_eq!(req_id, token.req_id());
} }
} }

View File

@ -22,8 +22,8 @@
//! use satrs_core::tmtc::tm_helper::SharedTmStore; //! use satrs_core::tmtc::tm_helper::SharedTmStore;
//! use spacepackets::ecss::PusPacket; //! use spacepackets::ecss::PusPacket;
//! use spacepackets::SpHeader; //! use spacepackets::SpHeader;
//! use spacepackets::tc::{PusTc, PusTcSecondaryHeader}; //! use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader};
//! use spacepackets::tm::PusTm; //! use spacepackets::ecss::tm::PusTmReader;
//! //!
//! const EMPTY_STAMP: [u8; 7] = [0; 7]; //! const EMPTY_STAMP: [u8; 7] = [0; 7];
//! const TEST_APID: u16 = 0x02; //! const TEST_APID: u16 = 0x02;
@ -39,7 +39,7 @@
//! //!
//! let mut sph = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); //! let mut sph = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
//! let tc_header = PusTcSecondaryHeader::new_simple(17, 1); //! let tc_header = PusTcSecondaryHeader::new_simple(17, 1);
//! let pus_tc_0 = PusTc::new(&mut sph, tc_header, None, true); //! let pus_tc_0 = PusTcCreator::new(&mut sph, tc_header, None, true);
//! let init_token = reporter.add_tc(&pus_tc_0); //! let init_token = reporter.add_tc(&pus_tc_0);
//! //!
//! // Complete success sequence for a telecommand //! // Complete success sequence for a telecommand
@ -60,7 +60,7 @@
//! tm_len = slice.len(); //! tm_len = slice.len();
//! tm_buf[0..tm_len].copy_from_slice(slice); //! tm_buf[0..tm_len].copy_from_slice(slice);
//! } //! }
//! let (pus_tm, _) = PusTm::from_bytes(&tm_buf[0..tm_len], 7) //! let (pus_tm, _) = PusTmReader::new(&tm_buf[0..tm_len], 7)
//! .expect("Error reading verification TM"); //! .expect("Error reading verification TM");
//! if packet_idx == 0 { //! if packet_idx == 0 {
//! assert_eq!(pus_tm.subservice(), 1); //! assert_eq!(pus_tm.subservice(), 1);
@ -85,9 +85,9 @@ use core::mem::size_of;
use delegate::delegate; use delegate::delegate;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use spacepackets::ecss::tc::IsPusTelecommand;
use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
use spacepackets::ecss::{EcssEnumeration, PusError, SerializablePusPacket}; use spacepackets::ecss::{EcssEnumeration, PusError, SerializablePusPacket};
use spacepackets::tc::PusTc;
use spacepackets::tm::{PusTm, PusTmSecondaryHeader};
use spacepackets::{CcsdsPacket, PacketId, PacketSequenceCtrl}; use spacepackets::{CcsdsPacket, PacketId, PacketSequenceCtrl};
use spacepackets::{SpHeader, MAX_APID}; use spacepackets::{SpHeader, MAX_APID};
@ -163,7 +163,7 @@ impl RequestId {
} }
impl RequestId { impl RequestId {
/// This allows extracting the request ID from a given PUS telecommand. /// This allows extracting the request ID from a given PUS telecommand.
pub fn new(tc: &PusTc) -> Self { pub fn new(tc: &(impl CcsdsPacket + IsPusTelecommand)) -> Self {
RequestId { RequestId {
version_number: tc.ccsds_version(), version_number: tc.ccsds_version(),
packet_id: tc.packet_id(), packet_id: tc.packet_id(),
@ -332,19 +332,19 @@ pub enum VerifFailure {}
/// This struct generally mutably borrows the source data buffer. /// This struct generally mutably borrows the source data buffer.
pub struct VerificationSendable<'src_data, State, SuccessOrFailure> { pub struct VerificationSendable<'src_data, State, SuccessOrFailure> {
token: Option<VerificationToken<State>>, token: Option<VerificationToken<State>>,
pus_tm: Option<PusTm<'src_data>>, pus_tm: Option<PusTmCreator<'src_data>>,
phantom: PhantomData<SuccessOrFailure>, phantom: PhantomData<SuccessOrFailure>,
} }
impl<'src_data, State, SuccessOrFailure> VerificationSendable<'src_data, State, SuccessOrFailure> { impl<'src_data, State, SuccessOrFailure> VerificationSendable<'src_data, State, SuccessOrFailure> {
pub(crate) fn new(pus_tm: PusTm<'src_data>, token: VerificationToken<State>) -> Self { pub(crate) fn new(pus_tm: PusTmCreator<'src_data>, token: VerificationToken<State>) -> Self {
Self { Self {
token: Some(token), token: Some(token),
pus_tm: Some(pus_tm), pus_tm: Some(pus_tm),
phantom: PhantomData, phantom: PhantomData,
} }
} }
pub(crate) fn new_no_token(pus_tm: PusTm<'src_data>) -> Self { pub(crate) fn new_no_token(pus_tm: PusTmCreator<'src_data>) -> Self {
Self { Self {
token: None, token: None,
pus_tm: Some(pus_tm), pus_tm: Some(pus_tm),
@ -356,11 +356,11 @@ impl<'src_data, State, SuccessOrFailure> VerificationSendable<'src_data, State,
self.pus_tm.as_ref().unwrap().len_packed() self.pus_tm.as_ref().unwrap().len_packed()
} }
pub fn pus_tm(&self) -> &PusTm<'src_data> { pub fn pus_tm(&self) -> &PusTmCreator<'src_data> {
self.pus_tm.as_ref().unwrap() self.pus_tm.as_ref().unwrap()
} }
pub fn pus_tm_mut(&mut self) -> &mut PusTm<'src_data> { pub fn pus_tm_mut(&mut self) -> &mut PusTmCreator<'src_data> {
self.pus_tm.as_mut().unwrap() self.pus_tm.as_mut().unwrap()
} }
} }
@ -370,7 +370,7 @@ impl<'src_data, State> VerificationSendable<'src_data, State, VerifFailure> {
} }
impl<'src_data, State> VerificationSendable<'src_data, State, VerifFailure> { impl<'src_data, State> VerificationSendable<'src_data, State, VerifFailure> {
pub fn send_failure(self) -> (PusTm<'src_data>, VerificationToken<State>) { pub fn send_failure(self) -> (PusTmCreator<'src_data>, VerificationToken<State>) {
(self.pus_tm.unwrap(), self.token.unwrap()) (self.pus_tm.unwrap(), self.token.unwrap())
} }
} }
@ -436,7 +436,10 @@ impl VerificationReporterCore {
/// Initialize verification handling by passing a TC reference. This returns a token required /// Initialize verification handling by passing a TC reference. This returns a token required
/// to call the acceptance functions /// to call the acceptance functions
pub fn add_tc(&mut self, pus_tc: &PusTc) -> VerificationToken<TcStateNone> { pub fn add_tc(
&mut self,
pus_tc: &(impl CcsdsPacket + IsPusTelecommand),
) -> VerificationToken<TcStateNone> {
self.add_tc_with_req_id(RequestId::new(pus_tc)) self.add_tc_with_req_id(RequestId::new(pus_tc))
} }
@ -787,7 +790,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<PusTmCreator<'src_data>, EcssTmtcError> {
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();
@ -823,7 +826,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<PusTmCreator<'src_data>, EcssTmtcError> {
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 {
@ -868,10 +871,10 @@ impl VerificationReporterCore {
sp_header: &mut SpHeader, sp_header: &mut SpHeader,
time_stamp: Option<&'src_data [u8]>, time_stamp: Option<&'src_data [u8]>,
source_data_len: usize, source_data_len: usize,
) -> PusTm<'src_data> { ) -> PusTmCreator<'src_data> {
let tm_sec_header = let tm_sec_header =
PusTmSecondaryHeader::new(1, subservice, msg_counter, self.dest_id, time_stamp); PusTmSecondaryHeader::new(1, subservice, msg_counter, self.dest_id, time_stamp);
PusTm::new( PusTmCreator::new(
sp_header, sp_header,
tm_sec_header, tm_sec_header,
Some(&src_data_buf[0..source_data_len]), Some(&src_data_buf[0..source_data_len]),
@ -888,6 +891,7 @@ mod alloc_mod {
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::vec; use alloc::vec;
use alloc::vec::Vec; use alloc::vec::Vec;
use spacepackets::ecss::tc::IsPusTelecommand;
#[derive(Clone)] #[derive(Clone)]
pub struct VerificationReporterCfg { pub struct VerificationReporterCfg {
@ -949,7 +953,7 @@ mod alloc_mod {
to self.reporter { to self.reporter {
pub fn set_apid(&mut self, apid: u16) -> bool; pub fn set_apid(&mut self, apid: u16) -> bool;
pub fn apid(&self) -> u16; pub fn apid(&self) -> u16;
pub fn add_tc(&mut self, pus_tc: &PusTc) -> VerificationToken<TcStateNone>; pub fn add_tc(&mut self, pus_tc: &(impl CcsdsPacket + IsPusTelecommand)) -> VerificationToken<TcStateNone>;
pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone>; pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone>;
pub fn dest_id(&self) -> u16; pub fn dest_id(&self) -> u16;
pub fn set_dest_id(&mut self, dest_id: u16); pub fn set_dest_id(&mut self, dest_id: u16);
@ -1213,7 +1217,7 @@ mod alloc_mod {
to self.reporter { to self.reporter {
pub fn set_apid(&mut self, apid: u16) -> bool; pub fn set_apid(&mut self, apid: u16) -> bool;
pub fn apid(&self) -> u16; pub fn apid(&self) -> u16;
pub fn add_tc(&mut self, pus_tc: &PusTc) -> VerificationToken<TcStateNone>; pub fn add_tc(&mut self, pus_tc: &(impl CcsdsPacket + IsPusTelecommand)) -> VerificationToken<TcStateNone>;
pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone>; pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone>;
pub fn dest_id(&self) -> u16; pub fn dest_id(&self) -> u16;
pub fn set_dest_id(&mut self, dest_id: u16); pub fn set_dest_id(&mut self, dest_id: u16);
@ -1304,192 +1308,8 @@ mod std_mod {
use crate::pus::verification::VerificationReporterWithSender; use crate::pus::verification::VerificationReporterWithSender;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
// use super::alloc_mod::VerificationReporterWithSender;
// use super::*;
// use crate::pool::{ShareablePoolProvider, SharedPool, StoreAddr};
// use crate::pus::{EcssSender, MpscPusInStoreSendError, PusTmWrapper};
// use crate::SenderId;
// use delegate::delegate;
// use spacepackets::ecss::SerializablePusPacket;
// use std::sync::{mpsc, Arc, Mutex, RwLockWriteGuard};
//
pub type StdVerifReporterWithSender = VerificationReporterWithSender; pub type StdVerifReporterWithSender = VerificationReporterWithSender;
pub type SharedStdVerifReporterWithSender = Arc<Mutex<StdVerifReporterWithSender>>; pub type SharedStdVerifReporterWithSender = Arc<Mutex<StdVerifReporterWithSender>>;
//
// trait SendBackend: Send {
// type SendError: Debug;
//
// fn send(&self, addr: StoreAddr) -> Result<(), Self::SendError>;
// }
//
// #[derive(Clone)]
// struct StdSenderBase<S> {
// id: SenderId,
// name: &'static str,
// tm_store: SharedPool,
// tx: S,
// pub ignore_poison_error: bool,
// }
//
// impl<S: SendBackend> StdSenderBase<S> {
// pub fn new(id: SenderId, name: &'static str, tm_store: SharedPool, tx: S) -> Self {
// Self {
// id,
// name,
// tm_store,
// tx,
// ignore_poison_error: false,
// }
// }
// }
//
// unsafe impl<S: Sync> Sync for StdSenderBase<S> {}
// unsafe impl<S: Send> Send for StdSenderBase<S> {}
//
// impl SendBackend for mpsc::Sender<StoreAddr> {
// type SendError = mpsc::SendError<StoreAddr>;
//
// fn send(&self, addr: StoreAddr) -> Result<(), Self::SendError> {
// self.send(addr)
// }
// }
//
// #[derive(Clone)]
// pub struct MpscVerifSender {
// base: StdSenderBase<mpsc::Sender<StoreAddr>>,
// }
//
// /// Verification sender with a [mpsc::Sender] backend.
// /// It implements the [EcssTmSenderCore] trait to be used as PUS Verification TM sender.
// impl MpscVerifSender {
// pub fn new(
// id: SenderId,
// name: &'static str,
// tm_store: SharedPool,
// tx: mpsc::Sender<StoreAddr>,
// ) -> Self {
// Self {
// base: StdSenderBase::new(id, name, tm_store, tx),
// }
// }
// }
//
// //noinspection RsTraitImplementation
// impl EcssSender for MpscVerifSender {
// delegate!(
// to self.base {
// fn id(&self) -> SenderId;
// fn name(&self) -> &'static str;
// }
// );
// }
//
// //noinspection RsTraitImplementation
// impl EcssTmSenderCore for MpscVerifSender {
// type Error = MpscPusInStoreSendError;
//
// delegate!(
// to self.base {
// fn send_tm(&self, tm: PusTmWrapper) -> Result<(), Self::Error>;
// }
// );
// }
//
// impl SendBackend for crossbeam_channel::Sender<StoreAddr> {
// type SendError = crossbeam_channel::SendError<StoreAddr>;
//
// fn send(&self, addr: StoreAddr) -> Result<(), Self::SendError> {
// self.send(addr)
// }
// }
//
// /// Verification sender with a [crossbeam_channel::Sender] backend.
// /// It implements the [EcssTmSenderCore] trait to be used as PUS Verification TM sender
// #[cfg(feature = "crossbeam")]
// #[derive(Clone)]
// pub struct CrossbeamVerifSender {
// base: StdSenderBase<crossbeam_channel::Sender<StoreAddr>>,
// }
//
// #[cfg(feature = "crossbeam")]
// impl CrossbeamVerifSender {
// pub fn new(
// id: SenderId,
// name: &'static str,
// tm_store: SharedPool,
// tx: crossbeam_channel::Sender<StoreAddr>,
// ) -> Self {
// Self {
// base: StdSenderBase::new(id, name, tm_store, tx),
// }
// }
// }
//
// //noinspection RsTraitImplementation
// #[cfg(feature = "crossbeam")]
// impl EcssSender for CrossbeamVerifSender {
// delegate!(
// to self.base {
// fn id(&self) -> SenderId;
// fn name(&self) -> &'static str;
// }
// );
// }
//
// //noinspection RsTraitImplementation
// #[cfg(feature = "crossbeam")]
// impl EcssTmSenderCore for CrossbeamVerifSender {
// type Error = MpscPusInStoreSendError;
//
// delegate!(
// to self.base {
// fn send_tm(&mut self, tm: PusTm) -> Result<(), Self::Error>;
// }
// );
// }
//
// impl<S: SendBackend + Clone + 'static> EcssSender for StdSenderBase<S> {
// fn id(&self) -> SenderId {
// self.id
// }
// fn name(&self) -> &'static str {
// self.name
// }
// }
// impl<S: SendBackend + Clone + 'static> EcssTmSenderCore for StdSenderBase<S> {
// type Error = MpscPusInStoreSendError;
//
// fn send_tm(&self, tm: PusTmWrapper) -> Result<(), Self::Error> {
// match tm {
// PusTmWrapper::InStore(addr) => {
// self.tx.send(addr).unwrap();
// Ok(())
// }
// PusTmWrapper::Direct(tm) => {
// let operation = |mut mg: RwLockWriteGuard<ShareablePoolProvider>| {
// let (addr, buf) = mg.free_element(tm.len_packed())?;
// tm.write_to_bytes(buf)
// .map_err(MpscPusInStoreSendError::Pus)?;
// drop(mg);
// self.tx
// .send(addr)
// .map_err(|_| MpscPusInStoreSendError::RxDisconnected(addr))?;
// Ok(())
// };
// match self.tm_store.write() {
// Ok(lock) => operation(lock),
// Err(poison_error) => {
// if self.ignore_poison_error {
// operation(poison_error.into_inner())
// } else {
// Err(MpscPusInStoreSendError::StoreLock)
// }
// }
// }
// }
// }
// }
// }
} }
#[cfg(test)] #[cfg(test)]
@ -1506,9 +1326,9 @@ mod tests {
use crate::ChannelId; use crate::ChannelId;
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::format; use alloc::format;
use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader};
use spacepackets::ecss::tm::PusTmReader;
use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU8, PusError, PusPacket}; use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU8, PusError, PusPacket};
use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
use spacepackets::tm::PusTm;
use spacepackets::util::UnsignedEnum; use spacepackets::util::UnsignedEnum;
use spacepackets::{ByteConversionError, CcsdsPacket, SpHeader}; use spacepackets::{ByteConversionError, CcsdsPacket, SpHeader};
use std::cell::RefCell; use std::cell::RefCell;
@ -1554,10 +1374,10 @@ mod tests {
} }
PusTmWrapper::Direct(tm) => { PusTmWrapper::Direct(tm) => {
assert_eq!(PusPacket::service(&tm), 1); assert_eq!(PusPacket::service(&tm), 1);
assert!(tm.source_data().is_some()); assert!(!tm.source_data().is_empty());
let mut time_stamp = [0; 7]; let mut time_stamp = [0; 7];
time_stamp.clone_from_slice(&tm.timestamp().unwrap()[0..7]); time_stamp.clone_from_slice(&tm.timestamp()[0..7]);
let src_data = tm.source_data().unwrap(); let src_data = tm.source_data();
assert!(src_data.len() >= 4); assert!(src_data.len() >= 4);
let req_id = let req_id =
RequestId::from_bytes(&src_data[0..RequestId::SIZE_AS_BYTES]).unwrap(); RequestId::from_bytes(&src_data[0..RequestId::SIZE_AS_BYTES]).unwrap();
@ -1581,7 +1401,7 @@ mod tests {
struct TestBase<'a> { struct TestBase<'a> {
vr: VerificationReporter, vr: VerificationReporter,
#[allow(dead_code)] #[allow(dead_code)]
tc: PusTc<'a>, tc: PusTcCreator<'a>,
} }
impl<'a> TestBase<'a> { impl<'a> TestBase<'a> {
@ -1592,7 +1412,7 @@ mod tests {
struct TestBaseWithHelper<'a> { struct TestBaseWithHelper<'a> {
helper: VerificationReporterWithSender, helper: VerificationReporterWithSender,
#[allow(dead_code)] #[allow(dead_code)]
tc: PusTc<'a>, tc: PusTcCreator<'a>,
} }
impl<'a> TestBaseWithHelper<'a> { impl<'a> TestBaseWithHelper<'a> {
@ -1606,10 +1426,10 @@ mod tests {
VerificationReporter::new(&cfg) VerificationReporter::new(&cfg)
} }
fn base_tc_init(app_data: Option<&[u8]>) -> (PusTc, RequestId) { fn base_tc_init(app_data: Option<&[u8]>) -> (PusTcCreator, RequestId) {
let mut sph = SpHeader::tc_unseg(TEST_APID, 0x34, 0).unwrap(); let mut sph = SpHeader::tc_unseg(TEST_APID, 0x34, 0).unwrap();
let tc_header = PusTcSecondaryHeader::new_simple(17, 1); let tc_header = PusTcSecondaryHeader::new_simple(17, 1);
let pus_tc = PusTc::new(&mut sph, tc_header, app_data, true); let pus_tc = PusTcCreator::new(&mut sph, tc_header, app_data, true);
let req_id = RequestId::new(&pus_tc); let req_id = RequestId::new(&pus_tc);
(pus_tc, req_id) (pus_tc, req_id)
} }
@ -2333,7 +2153,7 @@ mod tests {
let mut sph = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let mut sph = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let tc_header = PusTcSecondaryHeader::new_simple(17, 1); let tc_header = PusTcSecondaryHeader::new_simple(17, 1);
let pus_tc_0 = PusTc::new(&mut sph, tc_header, None, true); let pus_tc_0 = PusTcCreator::new(&mut sph, tc_header, None, true);
let init_token = reporter.add_tc(&pus_tc_0); let init_token = reporter.add_tc(&pus_tc_0);
// Complete success sequence for a telecommand // Complete success sequence for a telecommand
@ -2361,7 +2181,7 @@ mod tests {
tm_buf[0..tm_len].copy_from_slice(slice); tm_buf[0..tm_len].copy_from_slice(slice);
} }
let (pus_tm, _) = let (pus_tm, _) =
PusTm::from_bytes(&tm_buf[0..tm_len], 7).expect("Error reading verification TM"); PusTmReader::new(&tm_buf[0..tm_len], 7).expect("Error reading verification TM");
if packet_idx == 0 { if packet_idx == 0 {
assert_eq!(pus_tm.subservice(), 1); assert_eq!(pus_tm.subservice(), 1);
assert_eq!(pus_tm.sp_header.seq_count(), 0); assert_eq!(pus_tm.sp_header.seq_count(), 0);

View File

@ -22,7 +22,7 @@
//! use satrs_core::tmtc::{ReceivesTc, ReceivesTcCore}; //! use satrs_core::tmtc::{ReceivesTc, ReceivesTcCore};
//! use spacepackets::{CcsdsPacket, SpHeader}; //! use spacepackets::{CcsdsPacket, SpHeader};
//! use spacepackets::ecss::SerializablePusPacket; //! use spacepackets::ecss::SerializablePusPacket;
//! use spacepackets::tc::PusTc; //! use spacepackets::ecss::tc::{PusTc, PusTcCreator};
//! //!
//! #[derive (Default)] //! #[derive (Default)]
//! struct ConcreteApidHandler { //! struct ConcreteApidHandler {
@ -56,7 +56,7 @@
//! //!
//! // Create and pass PUS telecommand with a valid APID //! // Create and pass PUS telecommand with a valid APID
//! let mut space_packet_header = SpHeader::tc_unseg(0x002, 0x34, 0).unwrap(); //! let mut space_packet_header = SpHeader::tc_unseg(0x002, 0x34, 0).unwrap();
//! let mut pus_tc = PusTc::new_simple(&mut space_packet_header, 17, 1, None, true); //! let mut pus_tc = PusTcCreator::new_simple(&mut space_packet_header, 17, 1, None, true);
//! let mut test_buf: [u8; 32] = [0; 32]; //! let mut test_buf: [u8; 32] = [0; 32];
//! let mut size = pus_tc //! let mut size = pus_tc
//! .write_to_bytes(test_buf.as_mut_slice()) //! .write_to_bytes(test_buf.as_mut_slice())
@ -225,8 +225,8 @@ impl<E: 'static> CcsdsDistributor<E> {
pub(crate) mod tests { pub(crate) mod tests {
use super::*; use super::*;
use crate::tmtc::ccsds_distrib::{CcsdsDistributor, CcsdsPacketHandler}; use crate::tmtc::ccsds_distrib::{CcsdsDistributor, CcsdsPacketHandler};
use spacepackets::ecss::tc::PusTcCreator;
use spacepackets::ecss::SerializablePusPacket; use spacepackets::ecss::SerializablePusPacket;
use spacepackets::tc::PusTc;
use spacepackets::CcsdsPacket; use spacepackets::CcsdsPacket;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -236,7 +236,7 @@ pub(crate) mod tests {
pub fn generate_ping_tc(buf: &mut [u8]) -> &[u8] { pub fn generate_ping_tc(buf: &mut [u8]) -> &[u8] {
let mut sph = SpHeader::tc_unseg(0x002, 0x34, 0).unwrap(); let mut sph = SpHeader::tc_unseg(0x002, 0x34, 0).unwrap();
let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true); let pus_tc = PusTcCreator::new_simple(&mut sph, 17, 1, None, true);
let size = pus_tc let size = pus_tc
.write_to_bytes(buf) .write_to_bytes(buf)
.expect("Error writing TC to buffer"); .expect("Error writing TC to buffer");
@ -350,7 +350,7 @@ pub(crate) mod tests {
}; };
let mut ccsds_distrib = CcsdsDistributor::new(Box::new(apid_handler)); let mut ccsds_distrib = CcsdsDistributor::new(Box::new(apid_handler));
let mut sph = SpHeader::tc_unseg(0x004, 0x34, 0).unwrap(); let mut sph = SpHeader::tc_unseg(0x004, 0x34, 0).unwrap();
let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true); let pus_tc = PusTcCreator::new_simple(&mut sph, 17, 1, None, true);
let mut test_buf: [u8; 32] = [0; 32]; let mut test_buf: [u8; 32] = [0; 32];
pus_tc pus_tc
.write_to_bytes(test_buf.as_mut_slice()) .write_to_bytes(test_buf.as_mut_slice())

View File

@ -21,7 +21,7 @@
//! use satrs_core::tmtc::pus_distrib::{PusDistributor, PusServiceProvider}; //! use satrs_core::tmtc::pus_distrib::{PusDistributor, PusServiceProvider};
//! use satrs_core::tmtc::{ReceivesTc, ReceivesTcCore}; //! use satrs_core::tmtc::{ReceivesTc, ReceivesTcCore};
//! use spacepackets::SpHeader; //! use spacepackets::SpHeader;
//! use spacepackets::tc::PusTc; //! use spacepackets::ecss::tc::{PusTcCreator, PusTcReader};
//! struct ConcretePusHandler { //! struct ConcretePusHandler {
//! handler_call_count: u32 //! handler_call_count: u32
//! } //! }
@ -30,7 +30,7 @@
//! // which is used to verify the handler was called //! // which is used to verify the handler was called
//! impl PusServiceProvider for ConcretePusHandler { //! impl PusServiceProvider for ConcretePusHandler {
//! type Error = (); //! type Error = ();
//! fn handle_pus_tc_packet(&mut self, service: u8, header: &SpHeader, pus_tc: &PusTc) -> Result<(), Self::Error> { //! fn handle_pus_tc_packet(&mut self, service: u8, header: &SpHeader, pus_tc: &PusTcReader) -> Result<(), Self::Error> {
//! assert_eq!(service, 17); //! assert_eq!(service, 17);
//! assert_eq!(pus_tc.len_packed(), 13); //! assert_eq!(pus_tc.len_packed(), 13);
//! self.handler_call_count += 1; //! self.handler_call_count += 1;
@ -45,7 +45,7 @@
//! //!
//! // Create and pass PUS ping telecommand with a valid APID //! // Create and pass PUS ping telecommand with a valid APID
//! let mut space_packet_header = SpHeader::tc_unseg(0x002, 0x34, 0).unwrap(); //! let mut space_packet_header = SpHeader::tc_unseg(0x002, 0x34, 0).unwrap();
//! let mut pus_tc = PusTc::new_simple(&mut space_packet_header, 17, 1, None, true); //! let mut pus_tc = PusTcCreator::new_simple(&mut space_packet_header, 17, 1, None, true);
//! let mut test_buf: [u8; 32] = [0; 32]; //! let mut test_buf: [u8; 32] = [0; 32];
//! let mut size = pus_tc //! let mut size = pus_tc
//! .write_to_bytes(test_buf.as_mut_slice()) //! .write_to_bytes(test_buf.as_mut_slice())
@ -66,8 +66,8 @@ use crate::tmtc::{ReceivesCcsdsTc, ReceivesTcCore};
use alloc::boxed::Box; use alloc::boxed::Box;
use core::fmt::{Display, Formatter}; use core::fmt::{Display, Formatter};
use downcast_rs::Downcast; use downcast_rs::Downcast;
use spacepackets::ecss::tc::PusTcReader;
use spacepackets::ecss::{PusError, PusPacket}; use spacepackets::ecss::{PusError, PusPacket};
use spacepackets::tc::PusTc;
use spacepackets::SpHeader; use spacepackets::SpHeader;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::error::Error; use std::error::Error;
@ -78,7 +78,7 @@ pub trait PusServiceProvider: Downcast {
&mut self, &mut self,
service: u8, service: u8,
header: &SpHeader, header: &SpHeader,
pus_tc: &PusTc, pus_tc: &PusTcReader,
) -> Result<(), Self::Error>; ) -> Result<(), Self::Error>;
} }
downcast_rs::impl_downcast!(PusServiceProvider assoc Error); downcast_rs::impl_downcast!(PusServiceProvider assoc Error);
@ -141,14 +141,14 @@ impl<E: 'static> ReceivesTcCore for PusDistributor<E> {
impl<E: 'static> ReceivesCcsdsTc for PusDistributor<E> { impl<E: 'static> ReceivesCcsdsTc for PusDistributor<E> {
type Error = PusDistribError<E>; type Error = PusDistribError<E>;
fn pass_ccsds(&mut self, header: &SpHeader, tm_raw: &[u8]) -> Result<(), Self::Error> { fn pass_ccsds(&mut self, header: &SpHeader, tm_raw: &[u8]) -> Result<(), Self::Error> {
let (tc, _) = PusTc::from_bytes(tm_raw).map_err(|e| PusDistribError::PusError(e))?; let (tc, _) = PusTcReader::new(tm_raw).map_err(|e| PusDistribError::PusError(e))?;
self.pass_pus_tc(header, &tc) self.pass_pus_tc(header, &tc)
} }
} }
impl<E: 'static> ReceivesEcssPusTc for PusDistributor<E> { impl<E: 'static> ReceivesEcssPusTc for PusDistributor<E> {
type Error = PusDistribError<E>; type Error = PusDistribError<E>;
fn pass_pus_tc(&mut self, header: &SpHeader, pus_tc: &PusTc) -> Result<(), Self::Error> { fn pass_pus_tc(&mut self, header: &SpHeader, pus_tc: &PusTcReader) -> Result<(), Self::Error> {
self.service_provider self.service_provider
.handle_pus_tc_packet(pus_tc.service(), header, pus_tc) .handle_pus_tc_packet(pus_tc.service(), header, pus_tc)
.map_err(|e| PusDistribError::CustomError(e)) .map_err(|e| PusDistribError::CustomError(e))
@ -176,7 +176,6 @@ mod tests {
use crate::tmtc::ccsds_distrib::{CcsdsDistributor, CcsdsPacketHandler}; use crate::tmtc::ccsds_distrib::{CcsdsDistributor, CcsdsPacketHandler};
use alloc::vec::Vec; use alloc::vec::Vec;
use spacepackets::ecss::PusError; use spacepackets::ecss::PusError;
use spacepackets::tc::PusTc;
use spacepackets::CcsdsPacket; use spacepackets::CcsdsPacket;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::collections::VecDeque; use std::collections::VecDeque;
@ -200,10 +199,10 @@ mod tests {
&mut self, &mut self,
service: u8, service: u8,
sp_header: &SpHeader, sp_header: &SpHeader,
pus_tc: &PusTc, pus_tc: &PusTcReader,
) -> Result<(), Self::Error> { ) -> Result<(), Self::Error> {
let mut vec: Vec<u8> = Vec::new(); let mut vec: Vec<u8> = Vec::new();
pus_tc.append_to_vec(&mut vec)?; vec.extend_from_slice(pus_tc.raw_data());
Ok(self Ok(self
.pus_queue .pus_queue
.lock() .lock()
@ -218,10 +217,10 @@ mod tests {
&mut self, &mut self,
service: u8, service: u8,
sp_header: &SpHeader, sp_header: &SpHeader,
pus_tc: &PusTc, pus_tc: &PusTcReader,
) -> Result<(), Self::Error> { ) -> Result<(), Self::Error> {
let mut vec: Vec<u8> = Vec::new(); let mut vec: Vec<u8> = Vec::new();
pus_tc.append_to_vec(&mut vec)?; vec.extend_from_slice(pus_tc.raw_data());
Ok(self.pus_queue.push_back((service, sp_header.apid(), vec))) Ok(self.pus_queue.push_back((service, sp_header.apid(), vec)))
} }
} }

View File

@ -1,6 +1,6 @@
use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
use spacepackets::time::cds::TimeProvider; use spacepackets::time::cds::TimeProvider;
use spacepackets::time::TimeWriter; use spacepackets::time::TimeWriter;
use spacepackets::tm::{PusTm, PusTmSecondaryHeader};
use spacepackets::SpHeader; use spacepackets::SpHeader;
#[cfg(feature = "std")] #[cfg(feature = "std")]
@ -10,8 +10,8 @@ pub use std_mod::*;
pub mod std_mod { pub mod std_mod {
use crate::pool::{ShareablePoolProvider, SharedPool, StoreAddr}; use crate::pool::{ShareablePoolProvider, SharedPool, StoreAddr};
use crate::pus::EcssTmtcError; use crate::pus::EcssTmtcError;
use spacepackets::ecss::tm::PusTmCreator;
use spacepackets::ecss::SerializablePusPacket; use spacepackets::ecss::SerializablePusPacket;
use spacepackets::tm::PusTm;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
#[derive(Clone)] #[derive(Clone)]
@ -30,7 +30,7 @@ pub mod std_mod {
self.pool.clone() self.pool.clone()
} }
pub fn add_pus_tm(&self, pus_tm: &PusTm) -> Result<StoreAddr, EcssTmtcError> { pub fn add_pus_tm(&self, pus_tm: &PusTmCreator) -> Result<StoreAddr, EcssTmtcError> {
let mut pg = self.pool.write().map_err(|_| EcssTmtcError::StoreLock)?; let mut pg = self.pool.write().map_err(|_| EcssTmtcError::StoreLock)?;
let (addr, buf) = pg.free_element(pus_tm.len_packed())?; let (addr, buf) = pg.free_element(pus_tm.len_packed())?;
pus_tm pus_tm
@ -61,7 +61,7 @@ impl PusTmWithCdsShortHelper {
subservice: u8, subservice: u8,
source_data: Option<&'a [u8]>, source_data: Option<&'a [u8]>,
seq_count: u16, seq_count: u16,
) -> PusTm { ) -> PusTmCreator {
let time_stamp = TimeProvider::from_now_with_u16_days().unwrap(); let time_stamp = TimeProvider::from_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)
@ -74,7 +74,7 @@ impl PusTmWithCdsShortHelper {
source_data: Option<&'a [u8]>, source_data: Option<&'a [u8]>,
stamper: &TimeProvider, stamper: &TimeProvider,
seq_count: u16, seq_count: u16,
) -> PusTm { ) -> PusTmCreator {
stamper.write_to_bytes(&mut self.cds_short_buf).unwrap(); stamper.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)
} }
@ -85,9 +85,9 @@ impl PusTmWithCdsShortHelper {
subservice: u8, subservice: u8,
source_data: Option<&'a [u8]>, source_data: Option<&'a [u8]>,
seq_count: u16, seq_count: u16,
) -> PusTm { ) -> PusTmCreator {
let mut reply_header = SpHeader::tm_unseg(self.apid, seq_count, 0).unwrap(); let mut reply_header = SpHeader::tm_unseg(self.apid, seq_count, 0).unwrap();
let tc_header = PusTmSecondaryHeader::new_simple(service, subservice, &self.cds_short_buf); let tc_header = PusTmSecondaryHeader::new_simple(service, subservice, &self.cds_short_buf);
PusTm::new(&mut reply_header, tc_header, source_data, true) PusTmCreator::new(&mut reply_header, tc_header, source_data, true)
} }
} }

View File

@ -8,8 +8,8 @@ use satrs_core::pus::event_man::{
DefaultPusMgmtBackendProvider, EventReporter, PusEventDispatcher, DefaultPusMgmtBackendProvider, EventReporter, PusEventDispatcher,
}; };
use satrs_core::pus::MpscTmAsVecSender; use satrs_core::pus::MpscTmAsVecSender;
use spacepackets::ecss::tm::PusTmReader;
use spacepackets::ecss::{PusError, PusPacket}; use spacepackets::ecss::{PusError, PusPacket};
use spacepackets::tm::PusTm;
use std::sync::mpsc::{channel, SendError, TryRecvError}; use std::sync::mpsc::{channel, SendError, TryRecvError};
use std::thread; use std::thread;
@ -103,12 +103,11 @@ fn test_threaded_usage() {
// Event TM received successfully // Event TM received successfully
Ok(event_tm) => { Ok(event_tm) => {
let tm = let tm =
PusTm::from_bytes(event_tm.as_slice(), 7).expect("Deserializing TM failed"); PusTmReader::new(event_tm.as_slice(), 7).expect("Deserializing TM failed");
assert_eq!(tm.0.service(), 5); assert_eq!(tm.0.service(), 5);
assert_eq!(tm.0.subservice(), 1); assert_eq!(tm.0.subservice(), 1);
let src_data = tm.0.source_data(); let src_data = tm.0.source_data();
assert!(src_data.is_some()); assert!(!src_data.is_empty());
let src_data = src_data.unwrap();
assert_eq!(src_data.len(), 4); assert_eq!(src_data.len(), 4);
let event = let event =
EventU32::from(u32::from_be_bytes(src_data[0..4].try_into().unwrap())); EventU32::from(u32::from_be_bytes(src_data[0..4].try_into().unwrap()));
@ -133,12 +132,11 @@ fn test_threaded_usage() {
// Event TM received successfully // Event TM received successfully
Ok(event_tm) => { Ok(event_tm) => {
let tm = let tm =
PusTm::from_bytes(event_tm.as_slice(), 7).expect("Deserializing TM failed"); PusTmReader::new(event_tm.as_slice(), 7).expect("Deserializing TM failed");
assert_eq!(tm.0.service(), 5); assert_eq!(tm.0.service(), 5);
assert_eq!(tm.0.subservice(), 2); assert_eq!(tm.0.subservice(), 2);
let src_data = tm.0.source_data(); let src_data = tm.0.source_data();
assert!(src_data.is_some()); assert!(!src_data.is_empty());
let src_data = src_data.unwrap();
assert_eq!(src_data.len(), 12); assert_eq!(src_data.len(), 12);
let event = let event =
EventU32::from(u32::from_be_bytes(src_data[0..4].try_into().unwrap())); EventU32::from(u32::from_be_bytes(src_data[0..4].try_into().unwrap()));

View File

@ -9,9 +9,9 @@ pub mod crossbeam_test {
}; };
use satrs_core::pus::MpscTmInStoreSender; use satrs_core::pus::MpscTmInStoreSender;
use satrs_core::tmtc::tm_helper::SharedTmStore; use satrs_core::tmtc::tm_helper::SharedTmStore;
use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader};
use spacepackets::ecss::tm::PusTmReader;
use spacepackets::ecss::{EcssEnumU16, EcssEnumU8, PusPacket, SerializablePusPacket}; use spacepackets::ecss::{EcssEnumU16, EcssEnumU8, PusPacket, SerializablePusPacket};
use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
use spacepackets::tm::PusTm;
use spacepackets::SpHeader; use spacepackets::SpHeader;
use std::sync::{mpsc, Arc, RwLock}; use std::sync::{mpsc, Arc, RwLock};
use std::thread; use std::thread;
@ -56,14 +56,14 @@ pub mod crossbeam_test {
let mut tc_guard = shared_tc_pool_0.write().unwrap(); let mut tc_guard = shared_tc_pool_0.write().unwrap();
let mut sph = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let mut sph = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let tc_header = PusTcSecondaryHeader::new_simple(17, 1); let tc_header = PusTcSecondaryHeader::new_simple(17, 1);
let pus_tc_0 = PusTc::new(&mut sph, tc_header, None, true); let pus_tc_0 = PusTcCreator::new(&mut sph, tc_header, None, true);
req_id_0 = RequestId::new(&pus_tc_0); req_id_0 = RequestId::new(&pus_tc_0);
let (addr, mut buf) = tc_guard.free_element(pus_tc_0.len_packed()).unwrap(); let (addr, mut buf) = tc_guard.free_element(pus_tc_0.len_packed()).unwrap();
pus_tc_0.write_to_bytes(&mut buf).unwrap(); pus_tc_0.write_to_bytes(&mut buf).unwrap();
tx_tc_0.send(addr).unwrap(); tx_tc_0.send(addr).unwrap();
let mut sph = SpHeader::tc_unseg(TEST_APID, 1, 0).unwrap(); let mut sph = SpHeader::tc_unseg(TEST_APID, 1, 0).unwrap();
let tc_header = PusTcSecondaryHeader::new_simple(5, 1); let tc_header = PusTcSecondaryHeader::new_simple(5, 1);
let pus_tc_1 = PusTc::new(&mut sph, tc_header, None, true); let pus_tc_1 = PusTcCreator::new(&mut sph, tc_header, None, true);
req_id_1 = RequestId::new(&pus_tc_1); req_id_1 = RequestId::new(&pus_tc_1);
let (addr, mut buf) = tc_guard.free_element(pus_tc_0.len_packed()).unwrap(); let (addr, mut buf) = tc_guard.free_element(pus_tc_0.len_packed()).unwrap();
pus_tc_1.write_to_bytes(&mut buf).unwrap(); pus_tc_1.write_to_bytes(&mut buf).unwrap();
@ -82,7 +82,7 @@ pub mod crossbeam_test {
tc_len = buf.len(); tc_len = buf.len();
tc_buf[0..tc_len].copy_from_slice(buf); tc_buf[0..tc_len].copy_from_slice(buf);
} }
let (_tc, _) = PusTc::from_bytes(&tc_buf[0..tc_len]).unwrap(); let (_tc, _) = PusTcReader::new(&tc_buf[0..tc_len]).unwrap();
let accepted_token; let accepted_token;
let token = reporter_with_sender_0.add_tc_with_req_id(req_id_0); let token = reporter_with_sender_0.add_tc_with_req_id(req_id_0);
@ -122,7 +122,7 @@ pub mod crossbeam_test {
tc_len = buf.len(); tc_len = buf.len();
tc_buf[0..tc_len].copy_from_slice(buf); tc_buf[0..tc_len].copy_from_slice(buf);
} }
let (tc, _) = PusTc::from_bytes(&tc_buf[0..tc_len]).unwrap(); let (tc, _) = PusTcReader::new(&tc_buf[0..tc_len]).unwrap();
let token = reporter_with_sender_1.add_tc(&tc); let token = reporter_with_sender_1.add_tc(&tc);
let accepted_token = reporter_with_sender_1 let accepted_token = reporter_with_sender_1
.acceptance_success(token, Some(&FIXED_STAMP)) .acceptance_success(token, Some(&FIXED_STAMP))
@ -154,13 +154,11 @@ pub mod crossbeam_test {
tm_len = slice.len(); tm_len = slice.len();
tm_buf[0..tm_len].copy_from_slice(slice); tm_buf[0..tm_len].copy_from_slice(slice);
} }
let (pus_tm, _) = PusTm::from_bytes(&tm_buf[0..tm_len], 7) let (pus_tm, _) =
.expect("Error reading verification TM"); PusTmReader::new(&tm_buf[0..tm_len], 7).expect("Error reading verification TM");
let req_id = RequestId::from_bytes( let req_id =
&pus_tm.source_data().expect("Invalid TM source data") RequestId::from_bytes(&pus_tm.source_data()[0..RequestId::SIZE_AS_BYTES])
[0..RequestId::SIZE_AS_BYTES], .expect("reading request ID from PUS TM source data failed");
)
.unwrap();
if !verif_map.contains_key(&req_id) { if !verif_map.contains_key(&req_id) {
let mut content = Vec::new(); let mut content = Vec::new();
content.push(pus_tm.subservice()); content.push(pus_tm.subservice());

View File

@ -1,8 +1,8 @@
use satrs_core::pus::verification::RequestId; use satrs_core::pus::verification::RequestId;
use satrs_core::spacepackets::ecss::tc::PusTcCreator;
use satrs_core::spacepackets::ecss::tm::PusTmReader;
use satrs_core::{ use satrs_core::{
spacepackets::ecss::{PusPacket, SerializablePusPacket}, spacepackets::ecss::{PusPacket, SerializablePusPacket},
spacepackets::tc::PusTc,
spacepackets::tm::PusTm,
spacepackets::SpHeader, spacepackets::SpHeader,
}; };
use satrs_example::{OBSW_SERVER_ADDR, SERVER_PORT}; use satrs_example::{OBSW_SERVER_ADDR, SERVER_PORT};
@ -13,7 +13,7 @@ fn main() {
let mut buf = [0; 32]; let mut buf = [0; 32];
let addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT); let addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
let mut sph = SpHeader::tc_unseg(0x02, 0, 0).unwrap(); let mut sph = SpHeader::tc_unseg(0x02, 0, 0).unwrap();
let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true); let pus_tc = PusTcCreator::new_simple(&mut sph, 17, 1, None, true);
let client = UdpSocket::bind("127.0.0.1:7302").expect("Connecting to UDP server failed"); let client = UdpSocket::bind("127.0.0.1:7302").expect("Connecting to UDP server failed");
let tc_req_id = RequestId::new(&pus_tc); let tc_req_id = RequestId::new(&pus_tc);
println!("Packing and sending PUS ping command TC[17,1] with request ID {tc_req_id}"); println!("Packing and sending PUS ping command TC[17,1] with request ID {tc_req_id}");
@ -30,14 +30,14 @@ fn main() {
let res = client.recv(&mut buf); let res = client.recv(&mut buf);
match res { match res {
Ok(_len) => { Ok(_len) => {
let (pus_tm, size) = PusTm::from_bytes(&buf, 7).expect("Parsing PUS TM failed"); let (pus_tm, size) = PusTmReader::new(&buf, 7).expect("Parsing PUS TM failed");
if pus_tm.service() == 17 && pus_tm.subservice() == 2 { if pus_tm.service() == 17 && pus_tm.subservice() == 2 {
println!("Received PUS Ping Reply TM[17,2]") println!("Received PUS Ping Reply TM[17,2]")
} else if pus_tm.service() == 1 { } else if pus_tm.service() == 1 {
if pus_tm.source_data().is_none() { if pus_tm.source_data().is_empty() {
println!("Invalid verification TM, no source data"); println!("Invalid verification TM, no source data");
} }
let src_data = pus_tm.source_data().unwrap(); let src_data = pus_tm.source_data();
if src_data.len() < 4 { if src_data.len() < 4 {
println!("Invalid verification TM source data, less than 4 bytes") println!("Invalid verification TM source data, less than 4 bytes")
} }

View File

@ -1,6 +1,7 @@
use crate::tmtc::{MpscStoreAndSendError, PusTcSource, PUS_APID}; use crate::tmtc::{MpscStoreAndSendError, PusTcSource};
use satrs_core::spacepackets::{CcsdsPacket, SpHeader}; use satrs_core::spacepackets::{CcsdsPacket, SpHeader};
use satrs_core::tmtc::{CcsdsPacketHandler, ReceivesCcsdsTc}; use satrs_core::tmtc::{CcsdsPacketHandler, ReceivesCcsdsTc};
use satrs_example::PUS_APID;
pub struct CcsdsReceiver { pub struct CcsdsReceiver {
pub tc_source: PusTcSource, pub tc_source: PusTcSource,

View File

@ -6,6 +6,8 @@ use std::net::Ipv4Addr;
use satrs_mib::res_code::{ResultU16, ResultU16Info}; use satrs_mib::res_code::{ResultU16, ResultU16Info};
use satrs_mib::resultcode; use satrs_mib::resultcode;
pub const PUS_APID: u16 = 0x02;
#[derive(Copy, Clone, PartialEq, Eq, Debug, TryFromPrimitive, IntoPrimitive)] #[derive(Copy, Clone, PartialEq, Eq, Debug, TryFromPrimitive, IntoPrimitive)]
#[repr(u8)] #[repr(u8)]
pub enum CustomPusServiceId { pub enum CustomPusServiceId {

View File

@ -16,7 +16,7 @@ use crate::pus::scheduler::Pus11Wrapper;
use crate::pus::test::Service17CustomWrapper; use crate::pus::test::Service17CustomWrapper;
use crate::pus::PusTcMpscRouter; use crate::pus::PusTcMpscRouter;
use crate::requests::{Request, RequestWithToken}; use crate::requests::{Request, RequestWithToken};
use crate::tmtc::{core_tmtc_task, PusTcSource, TcArgs, TcStore, TmArgs, TmFunnel, PUS_APID}; use crate::tmtc::{core_tmtc_task, PusTcSource, TcArgs, TcStore, TmArgs, TmFunnel};
use satrs_core::event_man::{ use satrs_core::event_man::{
EventManagerWithMpscQueue, MpscEventReceiver, MpscEventU32SendProvider, SendEventProvider, EventManagerWithMpscQueue, MpscEventReceiver, MpscEventU32SendProvider, SendEventProvider,
}; };
@ -37,17 +37,17 @@ use satrs_core::pus::verification::{
}; };
use satrs_core::pus::{MpscTcInStoreReceiver, MpscTmInStoreSender}; use satrs_core::pus::{MpscTcInStoreReceiver, MpscTmInStoreSender};
use satrs_core::seq_count::{CcsdsSimpleSeqCountProvider, SequenceCountProviderCore}; use satrs_core::seq_count::{CcsdsSimpleSeqCountProvider, SequenceCountProviderCore};
use satrs_core::spacepackets::tm::PusTmZeroCopyWriter; use satrs_core::spacepackets::ecss::tm::{PusTmCreator, PusTmZeroCopyWriter};
use satrs_core::spacepackets::{ use satrs_core::spacepackets::{
time::cds::TimeProvider, ecss::tm::PusTmSecondaryHeader, time::cds::TimeProvider, time::TimeWriter, SequenceFlags,
time::TimeWriter, SpHeader,
tm::{PusTm, PusTmSecondaryHeader},
SequenceFlags, SpHeader,
}; };
use satrs_core::tmtc::tm_helper::SharedTmStore; use satrs_core::tmtc::tm_helper::SharedTmStore;
use satrs_core::tmtc::{AddressableId, TargetId}; use satrs_core::tmtc::{AddressableId, TargetId};
use satrs_core::ChannelId; use satrs_core::ChannelId;
use satrs_example::{RequestTargetId, TcReceiverId, TmSenderId, OBSW_SERVER_ADDR, SERVER_PORT}; use satrs_example::{
RequestTargetId, TcReceiverId, TmSenderId, OBSW_SERVER_ADDR, PUS_APID, SERVER_PORT,
};
use std::collections::HashMap; use std::collections::HashMap;
use std::net::{IpAddr, SocketAddr}; use std::net::{IpAddr, SocketAddr};
use std::sync::mpsc::{channel, TryRecvError}; use std::sync::mpsc::{channel, TryRecvError};
@ -415,7 +415,7 @@ fn main() {
unique_id, unique_id,
}; };
addressable_id.write_to_be_bytes(&mut buf).unwrap(); addressable_id.write_to_be_bytes(&mut buf).unwrap();
let pus_tm = PusTm::new( let pus_tm = PusTmCreator::new(
&mut sp_header, &mut sp_header,
sec_header, sec_header,
Some(&buf), Some(&buf),

View File

@ -8,8 +8,8 @@ use satrs_core::pus::{
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase, EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase,
PusServiceHandler, PusServiceHandler,
}; };
use satrs_core::spacepackets::ecss::tc::PusTcReader;
use satrs_core::spacepackets::ecss::PusPacket; use satrs_core::spacepackets::ecss::PusPacket;
use satrs_core::spacepackets::tc::PusTc;
use satrs_core::tmtc::TargetId; use satrs_core::tmtc::TargetId;
use satrs_example::tmtc_err; use satrs_example::tmtc_err;
use std::collections::HashMap; use std::collections::HashMap;
@ -46,11 +46,11 @@ impl PusService8ActionHandler {
fn handle_action_request_with_id( fn handle_action_request_with_id(
&self, &self,
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
tc: &PusTc, tc: &PusTcReader,
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<(), PusPacketHandlingError> { ) -> Result<(), PusPacketHandlingError> {
let user_data = tc.user_data(); let user_data = tc.user_data();
if user_data.is_none() || user_data.unwrap().len() < 8 { if user_data.len() < 8 {
self.psb() self.psb()
.verification_handler .verification_handler
.borrow_mut() .borrow_mut()
@ -63,7 +63,6 @@ impl PusService8ActionHandler {
"Expected at least 4 bytes".into(), "Expected at least 4 bytes".into(),
)); ));
} }
let user_data = user_data.unwrap();
let target_id = u32::from_be_bytes(user_data[0..4].try_into().unwrap()); let target_id = u32::from_be_bytes(user_data[0..4].try_into().unwrap());
let action_id = u32::from_be_bytes(user_data[4..8].try_into().unwrap()); let action_id = u32::from_be_bytes(user_data[4..8].try_into().unwrap());
if let Some(sender) = self.request_handlers.get(&target_id) { if let Some(sender) = self.request_handlers.get(&target_id) {
@ -114,7 +113,7 @@ impl PusServiceHandler for PusService8ActionHandler {
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> { ) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
self.copy_tc_to_buf(addr)?; self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTc::from_bytes(&self.psb().pus_buf).unwrap(); let (tc, _) = PusTcReader::new(&self.psb().pus_buf).unwrap();
let subservice = tc.subservice(); let subservice = tc.subservice();
let mut partial_error = None; let mut partial_error = None;
let time_stamp = self.psb().get_current_timestamp(&mut partial_error); let time_stamp = self.psb().get_current_timestamp(&mut partial_error);

View File

@ -9,8 +9,8 @@ use satrs_core::pus::{
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase, EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase,
PusServiceHandler, PusServiceHandler,
}; };
use satrs_core::spacepackets::ecss::tc::PusTcReader;
use satrs_core::spacepackets::ecss::{hk, PusPacket}; use satrs_core::spacepackets::ecss::{hk, PusPacket};
use satrs_core::spacepackets::tc::PusTc;
use satrs_core::tmtc::{AddressableId, TargetId}; use satrs_core::tmtc::{AddressableId, TargetId};
use satrs_example::{hk_err, tmtc_err}; use satrs_example::{hk_err, tmtc_err};
use std::collections::HashMap; use std::collections::HashMap;
@ -57,12 +57,12 @@ impl PusServiceHandler for PusService3HkHandler {
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> { ) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
self.copy_tc_to_buf(addr)?; self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTc::from_bytes(&self.psb().pus_buf).unwrap(); let (tc, _) = PusTcReader::new(&self.psb().pus_buf).unwrap();
let subservice = tc.subservice(); let subservice = tc.subservice();
let mut partial_error = None; let mut partial_error = None;
let time_stamp = self.psb().get_current_timestamp(&mut partial_error); let time_stamp = self.psb().get_current_timestamp(&mut partial_error);
let user_data = tc.user_data().unwrap(); let user_data = tc.user_data();
if tc.user_data().is_none() { if user_data.is_empty() {
self.psb self.psb
.verification_handler .verification_handler
.borrow_mut() .borrow_mut()

View File

@ -3,8 +3,8 @@ use log::warn;
use satrs_core::pool::StoreAddr; use satrs_core::pool::StoreAddr;
use satrs_core::pus::verification::{FailParams, StdVerifReporterWithSender}; use satrs_core::pus::verification::{FailParams, StdVerifReporterWithSender};
use satrs_core::pus::{PusPacketHandlerResult, TcAddrWithToken}; use satrs_core::pus::{PusPacketHandlerResult, TcAddrWithToken};
use satrs_core::spacepackets::ecss::tc::PusTcReader;
use satrs_core::spacepackets::ecss::PusServiceId; use satrs_core::spacepackets::ecss::PusServiceId;
use satrs_core::spacepackets::tc::PusTc;
use satrs_core::spacepackets::time::cds::TimeProvider; use satrs_core::spacepackets::time::cds::TimeProvider;
use satrs_core::spacepackets::time::TimeWriter; use satrs_core::spacepackets::time::TimeWriter;
use satrs_example::{tmtc_err, CustomPusServiceId}; use satrs_example::{tmtc_err, CustomPusServiceId};
@ -72,7 +72,7 @@ impl PusReceiver {
&mut self, &mut self,
store_addr: StoreAddr, store_addr: StoreAddr,
service: u8, service: u8,
pus_tc: &PusTc, pus_tc: &PusTcReader,
) -> Result<PusPacketHandlerResult, MpscStoreAndSendError> { ) -> Result<PusPacketHandlerResult, MpscStoreAndSendError> {
let init_token = self.verif_reporter.add_tc(pus_tc); let init_token = self.verif_reporter.add_tc(pus_tc);
self.stamp_helper.update_from_now(); self.stamp_helper.update_from_now();
@ -118,6 +118,7 @@ impl PusReceiver {
if let Ok(custom_service) = CustomPusServiceId::try_from(e.number) { if let Ok(custom_service) = CustomPusServiceId::try_from(e.number) {
match custom_service { match custom_service {
CustomPusServiceId::Mode => { CustomPusServiceId::Mode => {
// TODO: Fix mode service.
//self.handle_mode_service(pus_tc, accepted_token) //self.handle_mode_service(pus_tc, accepted_token)
} }
CustomPusServiceId::Health => {} CustomPusServiceId::Health => {}

View File

@ -4,8 +4,8 @@ use satrs_core::params::Params;
use satrs_core::pus::test::PusService17TestHandler; use satrs_core::pus::test::PusService17TestHandler;
use satrs_core::pus::verification::FailParams; use satrs_core::pus::verification::FailParams;
use satrs_core::pus::{PusPacketHandlerResult, PusServiceHandler}; use satrs_core::pus::{PusPacketHandlerResult, PusServiceHandler};
use satrs_core::spacepackets::ecss::tc::PusTcReader;
use satrs_core::spacepackets::ecss::PusPacket; use satrs_core::spacepackets::ecss::PusPacket;
use satrs_core::spacepackets::tc::PusTc;
use satrs_core::spacepackets::time::cds::TimeProvider; use satrs_core::spacepackets::time::cds::TimeProvider;
use satrs_core::spacepackets::time::TimeWriter; use satrs_core::spacepackets::time::TimeWriter;
use satrs_example::{tmtc_err, TEST_EVENT}; use satrs_example::{tmtc_err, TEST_EVENT};
@ -40,7 +40,7 @@ impl Service17CustomWrapper {
PusPacketHandlerResult::CustomSubservice(subservice, token) => { PusPacketHandlerResult::CustomSubservice(subservice, token) => {
let psb_mut = self.pus17_handler.psb_mut(); let psb_mut = self.pus17_handler.psb_mut();
let buf = psb_mut.pus_buf; let buf = psb_mut.pus_buf;
let (tc, _) = PusTc::from_bytes(&buf).unwrap(); let (tc, _) = PusTcReader::new(&buf).unwrap();
let time_stamper = TimeProvider::from_now_with_u16_days().unwrap(); let time_stamper = TimeProvider::from_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();

View File

@ -11,14 +11,12 @@ use crate::pus::{PusReceiver, PusTcMpscRouter};
use satrs_core::pool::{SharedPool, StoreAddr, StoreError}; use satrs_core::pool::{SharedPool, StoreAddr, StoreError};
use satrs_core::pus::verification::StdVerifReporterWithSender; use satrs_core::pus::verification::StdVerifReporterWithSender;
use satrs_core::pus::{ReceivesEcssPusTc, TcAddrWithToken}; use satrs_core::pus::{ReceivesEcssPusTc, TcAddrWithToken};
use satrs_core::spacepackets::ecss::{PusPacket, SerializablePusPacket}; use satrs_core::spacepackets::ecss::tc::PusTcReader;
use satrs_core::spacepackets::tc::PusTc; use satrs_core::spacepackets::ecss::PusPacket;
use satrs_core::spacepackets::SpHeader; use satrs_core::spacepackets::SpHeader;
use satrs_core::tmtc::tm_helper::SharedTmStore; use satrs_core::tmtc::tm_helper::SharedTmStore;
use satrs_core::tmtc::{CcsdsDistributor, CcsdsError, ReceivesCcsdsTc}; use satrs_core::tmtc::{CcsdsDistributor, CcsdsError, ReceivesCcsdsTc};
pub const PUS_APID: u16 = 0x02;
pub struct TmArgs { pub struct TmArgs {
pub tm_store: SharedTmStore, pub tm_store: SharedTmStore,
pub tm_sink_sender: Sender<StoreAddr>, pub tm_sink_sender: Sender<StoreAddr>,
@ -53,12 +51,10 @@ pub struct TcStore {
} }
impl TcStore { impl TcStore {
pub fn add_pus_tc(&mut self, pus_tc: &PusTc) -> Result<StoreAddr, StoreError> { pub fn add_pus_tc(&mut self, pus_tc: &PusTcReader) -> Result<StoreAddr, StoreError> {
let mut pg = self.pool.write().expect("error locking TC store"); let mut pg = self.pool.write().expect("error locking TC store");
let (addr, buf) = pg.free_element(pus_tc.len_packed())?; let (addr, buf) = pg.free_element(pus_tc.len_packed())?;
pus_tc buf[0..pus_tc.len_packed()].copy_from_slice(pus_tc.raw_data());
.write_to_bytes(buf)
.expect("writing PUS TC to store failed");
Ok(addr) Ok(addr)
} }
} }
@ -83,7 +79,7 @@ pub struct PusTcSource {
impl ReceivesEcssPusTc for PusTcSource { impl ReceivesEcssPusTc for PusTcSource {
type Error = MpscStoreAndSendError; type Error = MpscStoreAndSendError;
fn pass_pus_tc(&mut self, _: &SpHeader, pus_tc: &PusTc) -> Result<(), Self::Error> { fn pass_pus_tc(&mut self, _: &SpHeader, pus_tc: &PusTcReader) -> Result<(), Self::Error> {
let addr = self.tc_store.add_pus_tc(pus_tc)?; let addr = self.tc_store.add_pus_tc(pus_tc)?;
self.tc_source.send(addr)?; self.tc_source.send(addr)?;
Ok(()) Ok(())
@ -156,7 +152,7 @@ fn core_tmtc_loop(
let data = pool.read(&addr).expect("reading pool failed"); let data = pool.read(&addr).expect("reading pool failed");
tc_buf[0..data.len()].copy_from_slice(data); tc_buf[0..data.len()].copy_from_slice(data);
drop(pool); drop(pool);
match PusTc::from_bytes(tc_buf) { match PusTcReader::new(tc_buf) {
Ok((pus_tc, _)) => { Ok((pus_tc, _)) => {
pus_receiver pus_receiver
.handle_tc_packet(addr, pus_tc.service(), &pus_tc) .handle_tc_packet(addr, pus_tc.service(), &pus_tc)