improve docs

This commit is contained in:
Robin Mueller
2025-09-09 15:12:04 +02:00
parent 76450320e8
commit 895a57ca89
3 changed files with 18 additions and 21 deletions

View File

@@ -436,7 +436,9 @@ pub trait WritablePusPacket {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct CreatorConfig { pub struct CreatorConfig {
/// Set the CCSDS data length field on construction.
pub set_ccsds_len: bool, pub set_ccsds_len: bool,
/// CRC-16-CCITT Checksum is present.
pub has_checksum: bool, pub has_checksum: bool,
} }

View File

@@ -247,17 +247,13 @@ impl<'app_data> PusTcCreator<'app_data> {
/// * `sec_header` - Information contained in the data field header, including the service /// * `sec_header` - Information contained in the data field header, including the service
/// and subservice type /// and subservice type
/// * `app_data` - Custom application data /// * `app_data` - Custom application data
/// * `set_ccsds_len` - Can be used to automatically update the CCSDS space packet data length /// * `packet_config` - Common configuration options for TC packet creation
/// field. If this is not set to true, [Self::update_ccsds_data_len] can be called to set
/// the correct value to this field manually
/// * `has_checksum` - A CRC16 checksum will be generated and appended to the end of the
/// packet.
#[inline] #[inline]
pub fn new( pub fn new(
mut sp_header: SpHeader, mut sp_header: SpHeader,
sec_header: PusTcSecondaryHeader, sec_header: PusTcSecondaryHeader,
app_data: &'app_data [u8], app_data: &'app_data [u8],
creator_config: CreatorConfig, packet_config: CreatorConfig,
) -> 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();
@@ -265,9 +261,9 @@ impl<'app_data> PusTcCreator<'app_data> {
sp_header, sp_header,
app_data, app_data,
sec_header, sec_header,
has_checksum: creator_config.has_checksum, has_checksum: packet_config.has_checksum,
}; };
if creator_config.set_ccsds_len { if packet_config.set_ccsds_len {
pus_tc.update_ccsds_data_len(); pus_tc.update_ccsds_data_len();
} }
pus_tc pus_tc
@@ -281,13 +277,13 @@ impl<'app_data> PusTcCreator<'app_data> {
service: u8, service: u8,
subservice: u8, subservice: u8,
app_data: &'app_data [u8], app_data: &'app_data [u8],
creator_config: CreatorConfig, packet_config: CreatorConfig,
) -> Self { ) -> Self {
Self::new( Self::new(
sph, sph,
PusTcSecondaryHeader::new(service, subservice, ACK_ALL, 0), PusTcSecondaryHeader::new(service, subservice, ACK_ALL, 0),
app_data, app_data,
creator_config, packet_config,
) )
} }
@@ -295,9 +291,9 @@ impl<'app_data> PusTcCreator<'app_data> {
pub fn new_no_app_data( pub fn new_no_app_data(
sp_header: SpHeader, sp_header: SpHeader,
sec_header: PusTcSecondaryHeader, sec_header: PusTcSecondaryHeader,
creator_config: CreatorConfig, packet_config: CreatorConfig,
) -> Self { ) -> Self {
Self::new(sp_header, sec_header, &[], creator_config) Self::new(sp_header, sec_header, &[], packet_config)
} }
#[inline] #[inline]

View File

@@ -288,9 +288,7 @@ impl<'time, 'src_data> PusTmCreator<'time, 'src_data> {
/// * `sec_header` - Information contained in the secondary header, including the service /// * `sec_header` - Information contained in the secondary header, including the service
/// and subservice type /// and subservice type
/// * `source_data` - Custom application data /// * `source_data` - Custom application data
/// * `set_ccsds_len` - Can be used to automatically update the CCSDS space packet data length /// * `packet_config` - Common configuration options for TM packet creation
/// field. If this is not set to true, [Self::update_ccsds_data_len] can be called to set
/// the correct value to this field manually
#[inline] #[inline]
pub fn new( pub fn new(
mut sp_header: SpHeader, mut sp_header: SpHeader,
@@ -726,7 +724,8 @@ pub struct PusTmReader<'raw_data> {
#[cfg_attr(feature = "serde", serde(skip))] #[cfg_attr(feature = "serde", serde(skip))]
raw_data: &'raw_data [u8], raw_data: &'raw_data [u8],
source_data: &'raw_data [u8], source_data: &'raw_data [u8],
checksum_crc16: Option<u16>, // CRC-16-CCITT checksum.
checksum: Option<u16>,
} }
impl<'raw_data> PusTmReader<'raw_data> { impl<'raw_data> PusTmReader<'raw_data> {
@@ -734,7 +733,7 @@ impl<'raw_data> PusTmReader<'raw_data> {
/// the instance and the found byte length of the packet. The timestamp length needs to be /// the instance and the found byte length of the packet. The timestamp length needs to be
/// known beforehand. /// known beforehand.
/// ///
/// This function will check the CRC-16 of the PUS packet and will return an appropriate /// This function will verify the CRC-16-CCITT of the PUS packet and will return an appropriate
/// [PusError] if the check fails. /// [PusError] if the check fails.
pub fn new(slice: &'raw_data [u8], timestamp_len: usize) -> Result<Self, PusError> { pub fn new(slice: &'raw_data [u8], timestamp_len: usize) -> Result<Self, PusError> {
let tc = Self::new_no_checksum_verification( let tc = Self::new_no_checksum_verification(
@@ -822,7 +821,7 @@ impl<'raw_data> PusTmReader<'raw_data> {
slice, slice,
reader_config.has_checksum, reader_config.has_checksum,
)?, )?,
checksum_crc16: crc16, checksum: crc16,
}) })
} }
@@ -843,7 +842,7 @@ impl<'raw_data> PusTmReader<'raw_data> {
#[inline] #[inline]
pub fn checksum(&self) -> Option<u16> { pub fn checksum(&self) -> Option<u16> {
self.checksum_crc16 self.checksum
} }
/// This function will return the slice [Self] was constructed from. /// This function will return the slice [Self] was constructed from.
@@ -858,7 +857,7 @@ impl PartialEq for PusTmReader<'_> {
self.sec_header == other.sec_header self.sec_header == other.sec_header
&& self.source_data == other.source_data && self.source_data == other.source_data
&& self.sp_header == other.sp_header && self.sp_header == other.sp_header
&& self.checksum_crc16 == other.checksum_crc16 && self.checksum == other.checksum
} }
} }
@@ -878,7 +877,7 @@ impl PusPacket for PusTmReader<'_> {
#[inline] #[inline]
fn has_checksum(&self) -> bool { fn has_checksum(&self) -> bool {
self.checksum_crc16.is_some() self.checksum.is_some()
} }
#[inline] #[inline]