Skip to main content

CrcSpacePacket

Struct CrcSpacePacket 

Source
pub struct CrcSpacePacket<'a, 'b> { /* private fields */ }
Expand description

A wrapper around a SpacePacket that automatically manages a trailing CRC-16 checksum.

Implementations§

Source§

impl<'a, 'b> CrcSpacePacket<'a, 'b>

Source

pub fn new( buffer: &'a mut [u8], apid: Apid, packet_type: PacketType, sequence_count: SequenceCount, secondary_header_flag: SecondaryHeaderFlag, sequence_flag: SequenceFlag, data_field_len: u16, crc_alg: &'b Crc<u16>, ) -> Result<CrcSpacePacket<'a, 'b>, CrcError>

Creates a new CRC-protected Space Packet in the provided buffer.

Source

pub fn set_data<T: SpacePacketData>( &mut self, data: &T, ) -> Result<(), DataFieldError>

Writes data to the packet’s data field and automatically updates the CRC.

This is the safe, CRC-aware way to set the packet’s payload.

Source

pub fn data_as<T: SpacePacketData>(&self) -> Result<&T, CrcError>

Validates the CRC and returns a typed, zero-copy view of the data field.

Source

pub fn data(&self) -> Result<&[u8], CrcError>

Validates the CRC and returns an immutable slice of the data field.

Source

pub fn validate(&self) -> Result<(), CrcError>

Validates the current CRC against the packet’s contents.

Source

pub fn update_crc(&mut self)

Forces a recalculation and update of the CRC value. This is called automatically by set_data_field.

Methods from Deref<Target = SpacePacket>§

Source

pub fn set_data_field<T: SpacePacketData>( &mut self, data: &T, ) -> Result<(), DataFieldError>

Copies a user-defined data structure into the packet’s data field.

The size of T must exactly match the length of the data field.

Source

pub fn data_as<T: SpacePacketData>(&self) -> Result<&T, DataFieldError>

Returns a zero-copy, typed view of the packet’s data field.

This is the primary method for interpreting the packet’s payload as a specific data structure. It will fail if the size of T does not match the data field’s length.

Source

pub fn data_field(&self) -> &[u8]

Returns an immutable slice of the packet’s data field.

Source

pub fn data_field_mut(&mut self) -> &mut [u8]

Returns a mutable slice of the packet’s data field.

Warning: Modifying the data field directly will invalidate any CRC checksum. If using a CrcSpacePacket, prefer the safe set_data() method instead.

Methods from Deref<Target = PrimaryHeader>§

Source

pub fn version(&self) -> PacketVersion

Returns the 3-bit packet version number.

Source

pub fn set_version(&mut self, version: PacketVersion)

Sets the 3-bit packet version number.

Source

pub fn packet_type(&self) -> PacketType

Returns the PacketType (Telemetry or Telecommand).

Source

pub fn set_packet_type(&mut self, packet_type: PacketType)

Sets the PacketType (Telemetry or Telecommand).

Source

pub fn secondary_header_flag(&self) -> SecondaryHeaderFlag

Returns the SecondaryHeader flag (Present or Absent).

Source

pub fn set_secondary_header_flag(&mut self, flag: SecondaryHeaderFlag)

Sets the SecondaryHeader flag (Present or Absent).

Source

pub fn apid(&self) -> Apid

Returns the 11-bit Application Process Identifier (Apid).

Source

pub fn set_apid(&mut self, apid: Apid)

Sets the 11-bit Application Process Identifier (Apid).

Source

pub fn sequence_flag(&self) -> SequenceFlag

Returns the 2-bit SequenceFlag.

Source

pub fn set_sequence_flag(&mut self, flag: SequenceFlag)

Sets the 2-bit SequenceFlag.

Source

pub fn sequence_count(&self) -> SequenceCount

Returns the 14-bit packet sequence count.

Source

pub fn set_sequence_count(&mut self, count: SequenceCount)

Sets the 14-bit SequenceCount.

Source

pub fn data_field_len(&self) -> usize

Returns the length of the data field in bytes as specified by the header.

Source

pub fn set_data_field_len(&mut self, len: u16)

Sets the length of the data field in bytes. The value written to the header will be len - 1 as per the CCSDS standard.

Source

pub fn packet_len(&self) -> usize

Returns the total length of the packet (header + data field) in bytes.

Source

pub fn cfe_msg_id(&self) -> u16

Reconstructs the CFE-style Message ID (MsgId) from the primary header fields.

This is a crucial convenience function for systems that interact with the cFE Software Bus (SB). The SB uses a single integer MsgId for routing, which is a composite value created from several fields in the CCSDS header.

A cFE MsgId is 16-bit integer with the following structure:

+-----------------+------+-----------------------------------------+
| Field           | Size | Description                             |
+-----------------+------+-----------------------------------------+
| APID            | 11   | The 11-bit Application Process ID.      |
| SB Flag         | 1    | 1 indicates a Software Bus message.     |
| Type            | 1    | 0 for Telemetry, 1 for Telecommand.     |
| Reserved        | 3    | Unused, should be zero.                 |
+-----------------+------+-----------------------------------------+

Trait Implementations§

Source§

impl<'a, 'b> Deref for CrcSpacePacket<'a, 'b>

Source§

type Target = SpacePacket

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a, 'b> DerefMut for CrcSpacePacket<'a, 'b>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'a, 'b> Freeze for CrcSpacePacket<'a, 'b>

§

impl<'a, 'b> RefUnwindSafe for CrcSpacePacket<'a, 'b>

§

impl<'a, 'b> Send for CrcSpacePacket<'a, 'b>

§

impl<'a, 'b> Sync for CrcSpacePacket<'a, 'b>

§

impl<'a, 'b> Unpin for CrcSpacePacket<'a, 'b>

§

impl<'a, 'b> UnsafeUnpin for CrcSpacePacket<'a, 'b>

§

impl<'a, 'b> !UnwindSafe for CrcSpacePacket<'a, 'b>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.