Clean up ECSS API #52

Merged
muellerr merged 2 commits from clean-up-ecss-api into main 2023-12-07 13:54:00 +01:00
2 changed files with 25 additions and 22 deletions

View File

@ -11,7 +11,7 @@
//! // Create a ping telecommand with no user application data //! // Create a ping telecommand with no user application data
//! let mut sph = SpHeader::tc_unseg(0x02, 0x34, 0).unwrap(); //! let mut sph = SpHeader::tc_unseg(0x02, 0x34, 0).unwrap();
//! let tc_header = PusTcSecondaryHeader::new_simple(17, 1); //! let tc_header = PusTcSecondaryHeader::new_simple(17, 1);
//! let pus_tc = PusTcCreator::new(&mut sph, tc_header, None, true); //! let pus_tc = PusTcCreator::new_no_app_data(&mut sph, tc_header, true);
//! println!("{:?}", pus_tc); //! println!("{:?}", pus_tc);
//! assert_eq!(pus_tc.service(), 17); //! assert_eq!(pus_tc.service(), 17);
//! assert_eq!(pus_tc.subservice(), 1); //! assert_eq!(pus_tc.subservice(), 1);
@ -571,14 +571,14 @@ impl<'raw_data> PusTcCreator<'raw_data> {
pub fn new( pub fn new(
sp_header: &mut SpHeader, sp_header: &mut SpHeader,
sec_header: PusTcSecondaryHeader, sec_header: PusTcSecondaryHeader,
app_data: Option<&'raw_data [u8]>, app_data: &'raw_data [u8],
set_ccsds_len: bool, set_ccsds_len: bool,
) -> Self { ) -> Self {
sp_header.set_packet_type(PacketType::Tc); sp_header.set_packet_type(PacketType::Tc);
sp_header.set_sec_header_flag(); sp_header.set_sec_header_flag();
let mut pus_tc = Self { let mut pus_tc = Self {
sp_header: *sp_header, sp_header: *sp_header,
app_data: app_data.unwrap_or(&[]), app_data,
sec_header, sec_header,
}; };
if set_ccsds_len { if set_ccsds_len {
@ -599,11 +599,19 @@ impl<'raw_data> PusTcCreator<'raw_data> {
Self::new( Self::new(
sph, sph,
PusTcSecondaryHeader::new(service, subservice, ACK_ALL, 0), PusTcSecondaryHeader::new(service, subservice, ACK_ALL, 0),
app_data, app_data.unwrap_or(&[]),
set_ccsds_len, set_ccsds_len,
) )
} }
pub fn new_no_app_data(
sp_header: &mut SpHeader,
sec_header: PusTcSecondaryHeader,
set_ccsds_len: bool,
) -> Self {
Self::new(sp_header, sec_header, &[], set_ccsds_len)
}
pub fn sp_header(&self) -> &SpHeader { pub fn sp_header(&self) -> &SpHeader {
&self.sp_header &self.sp_header
} }
@ -888,7 +896,7 @@ mod tests {
fn base_ping_tc_full_ctor() -> PusTcCreator<'static> { fn base_ping_tc_full_ctor() -> PusTcCreator<'static> {
let mut sph = SpHeader::tc_unseg(0x02, 0x34, 0).unwrap(); let mut sph = SpHeader::tc_unseg(0x02, 0x34, 0).unwrap();
let tc_header = PusTcSecondaryHeader::new_simple(17, 1); let tc_header = PusTcSecondaryHeader::new_simple(17, 1);
PusTcCreator::new(&mut sph, tc_header, None, true) PusTcCreator::new_no_app_data(&mut sph, tc_header, true)
} }
fn base_ping_tc_simple_ctor() -> PusTcCreator<'static> { fn base_ping_tc_simple_ctor() -> PusTcCreator<'static> {

View File

@ -586,13 +586,18 @@ impl<'raw_data> PusTmCreator<'raw_data> {
subservice: u8, subservice: u8,
time_provider: &impl TimeWriter, time_provider: &impl TimeWriter,
stamp_buf: &'raw_data mut [u8], stamp_buf: &'raw_data mut [u8],
source_data: &'raw_data [u8], source_data: Option<&'raw_data [u8]>,
set_ccsds_len: bool, set_ccsds_len: bool,
) -> Result<Self, TimestampError> { ) -> Result<Self, TimestampError> {
let stamp_size = time_provider.write_to_bytes(stamp_buf)?; let stamp_size = time_provider.write_to_bytes(stamp_buf)?;
let sec_header = let sec_header =
PusTmSecondaryHeader::new_simple(service, subservice, &stamp_buf[0..stamp_size]); PusTmSecondaryHeader::new_simple(service, subservice, &stamp_buf[0..stamp_size]);
Ok(Self::new(sp_header, sec_header, source_data, set_ccsds_len)) Ok(Self::new(
sp_header,
sec_header,
source_data.unwrap_or(&[]),
set_ccsds_len,
))
} }
pub fn new_no_source_data( pub fn new_no_source_data(
@ -600,19 +605,9 @@ impl<'raw_data> PusTmCreator<'raw_data> {
sec_header: PusTmSecondaryHeader<'raw_data>, sec_header: PusTmSecondaryHeader<'raw_data>,
set_ccsds_len: bool, set_ccsds_len: bool,
) -> Self { ) -> Self {
sp_header.set_packet_type(PacketType::Tm); Self::new(sp_header, sec_header, &[], set_ccsds_len)
sp_header.set_sec_header_flag();
let mut pus_tm = Self {
sp_header: *sp_header,
source_data: &[],
sec_header,
calc_crc_on_serialization: true,
};
if set_ccsds_len {
pus_tm.update_ccsds_data_len();
}
pus_tm
} }
pub fn timestamp(&self) -> &[u8] { pub fn timestamp(&self) -> &[u8] {
self.sec_header.timestamp self.sec_header.timestamp
} }
@ -1034,7 +1029,7 @@ mod tests {
let time_provider = TimeProvider::new_with_u16_days(0, 0); let time_provider = TimeProvider::new_with_u16_days(0, 0);
let mut stamp_buf: [u8; 8] = [0; 8]; let mut stamp_buf: [u8; 8] = [0; 8];
let pus_tm = let pus_tm =
PusTmCreator::new_simple(&mut sph, 17, 2, &time_provider, &mut stamp_buf, &[], true) PusTmCreator::new_simple(&mut sph, 17, 2, &time_provider, &mut stamp_buf, None, true)
.unwrap(); .unwrap();
verify_ping_reply(&pus_tm, false, 22, &[64, 0, 0, 0, 0, 0, 0]); verify_ping_reply(&pus_tm, false, 22, &[64, 0, 0, 0, 0, 0, 0]);
} }
@ -1387,7 +1382,7 @@ mod tests {
let time_provider = TimeProvider::new_with_u16_days(0, 0); let time_provider = TimeProvider::new_with_u16_days(0, 0);
let mut stamp_buf: [u8; 8] = [0; 8]; let mut stamp_buf: [u8; 8] = [0; 8];
let pus_tm = let pus_tm =
PusTmCreator::new_simple(&mut sph, 17, 2, &time_provider, &mut stamp_buf, &[], true) PusTmCreator::new_simple(&mut sph, 17, 2, &time_provider, &mut stamp_buf, None, true)
.unwrap(); .unwrap();
let output = to_allocvec(&pus_tm).unwrap(); let output = to_allocvec(&pus_tm).unwrap();
@ -1402,7 +1397,7 @@ mod tests {
let time_provider = TimeProvider::new_with_u16_days(0, 0); let time_provider = TimeProvider::new_with_u16_days(0, 0);
let mut stamp_buf: [u8; 8] = [0; 8]; let mut stamp_buf: [u8; 8] = [0; 8];
let pus_tm = let pus_tm =
PusTmCreator::new_simple(&mut sph, 17, 2, &time_provider, &mut stamp_buf, &[], true) PusTmCreator::new_simple(&mut sph, 17, 2, &time_provider, &mut stamp_buf, None, true)
.unwrap(); .unwrap();
let pus_tm_vec = pus_tm.to_vec().unwrap(); let pus_tm_vec = pus_tm.to_vec().unwrap();
let (tm_reader, _) = PusTmReader::new(&pus_tm_vec, time_provider.len_as_bytes()).unwrap(); let (tm_reader, _) = PusTmReader::new(&pus_tm_vec, time_provider.len_as_bytes()).unwrap();