Skip to main content

Telecommand

Struct Telecommand 

Source
#[repr(C)]
pub struct Telecommand { pub primary: PrimaryHeader, pub secondary: TelecommandSecondaryHeader, pub payload: [u8], }
Expand description

A zero-copy view over a complete CFE command packet (headers + payload). This is the primary struct you will use to represent a command.

+------------------------------------+---------+
| Field Name                         | Size    |
+------------------------------------+---------+
+ -- Primary Header (6 bytes) ------ | ------- |
|                                    |         |
| - Packet Type is always Telecommand|         |
| - Sec. Hdr. Flag is always Present |         |
|                                    |         |
+ -- cFE Secondary Header (2 bytes)  | ------- |
|                                    |         |
| Function Code                      | 1 byte  |
| Checksum                           | 1 byte  |
|                                    |         |
+ -- User Data Field (Variable) ---- | ------- |
|                                    |         |
| Payload                            | 1-65534 |
|                                    | bytes   |
+------------------------------------+---------+

Fields§

§primary: PrimaryHeader

CCSDS SPP primary header.

§secondary: TelecommandSecondaryHeader

CFE command secondary header containing function code and checksum.

§payload: [u8]

Variable-length command payload.

Implementations§

Source§

impl Telecommand

Source

pub const fn size_minimum() -> usize

Minimum size of a telecommand packet (primary + secondary headers).

Source

pub fn function_code(&self) -> u8

Returns the function code from the secondary header.

Source

pub fn set_function_code(&mut self, function_code: u8)

Sets the function code in the secondary header.

Source

pub fn set_cfe_checksum(&mut self)

Calculates and sets the 8-bit cFE checksum for this command packet.

The algorithm is a byte-wise XOR sum of the entire packet, with the checksum field itself treated as zero during calculation.

Source

pub fn validate_cfe_checksum(&self) -> bool

Validates the 8-bit cFE checksum.

Returns true if the checksum is valid, false otherwise.

Source

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

Returns the command payload bytes.

Source

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

Returns a mutable reference to the command payload bytes.

Source

pub fn parse<'a>(bytes: &'a [u8]) -> Result<&'a Telecommand, TelecommandError>

Parses a byte slice as a CFE telecommand packet.

Source

pub fn as_spacepacket(&self) -> &SpacePacket

Returns a reference to the underlying SpacePacket.

Source

pub fn builder<'a>() -> TelecommandBuilder<'a>

Creates a new telecommand packet in the provided buffer.

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 Deref for Telecommand

Source§

type Target = SpacePacket

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl DerefMut for Telecommand

Source§

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

Mutably dereferences the value.
Source§

impl FromBytes for Telecommand
where PrimaryHeader: FromBytes, TelecommandSecondaryHeader: FromBytes, [u8]: FromBytes,

§

fn ref_from_bytes( source: &[u8], ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
where Self: KnownLayout + Immutable,

Interprets the given source as a &Self. Read more
§

fn ref_from_prefix( source: &[u8], ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
where Self: KnownLayout + Immutable,

Interprets the prefix of the given source as a &Self without copying. Read more
§

fn ref_from_suffix( source: &[u8], ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
where Self: Immutable + KnownLayout,

Interprets the suffix of the given bytes as a &Self. Read more
§

fn mut_from_bytes( source: &mut [u8], ) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
where Self: IntoBytes + KnownLayout,

Interprets the given source as a &mut Self. Read more
§

fn mut_from_prefix( source: &mut [u8], ) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
where Self: IntoBytes + KnownLayout,

Interprets the prefix of the given source as a &mut Self without copying. Read more
§

fn mut_from_suffix( source: &mut [u8], ) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
where Self: IntoBytes + KnownLayout,

Interprets the suffix of the given source as a &mut Self without copying. Read more
§

fn ref_from_bytes_with_elems( source: &[u8], count: usize, ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
where Self: KnownLayout<PointerMetadata = usize> + Immutable,

Interprets the given source as a &Self with a DST length equal to count. Read more
§

fn ref_from_prefix_with_elems( source: &[u8], count: usize, ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
where Self: KnownLayout<PointerMetadata = usize> + Immutable,

Interprets the prefix of the given source as a DST &Self with length equal to count. Read more
§

fn ref_from_suffix_with_elems( source: &[u8], count: usize, ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>
where Self: KnownLayout<PointerMetadata = usize> + Immutable,

Interprets the suffix of the given source as a DST &Self with length equal to count. Read more
§

fn mut_from_bytes_with_elems( source: &mut [u8], count: usize, ) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
where Self: IntoBytes + KnownLayout<PointerMetadata = usize> + Immutable,

Interprets the given source as a &mut Self with a DST length equal to count. Read more
§

fn mut_from_prefix_with_elems( source: &mut [u8], count: usize, ) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
where Self: IntoBytes + KnownLayout<PointerMetadata = usize>,

Interprets the prefix of the given source as a &mut Self with DST length equal to count. Read more
§

fn mut_from_suffix_with_elems( source: &mut [u8], count: usize, ) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>
where Self: IntoBytes + KnownLayout<PointerMetadata = usize>,

Interprets the suffix of the given source as a &mut Self with DST length equal to count. Read more
Source§

impl FromZeros for Telecommand
where PrimaryHeader: FromZeros, TelecommandSecondaryHeader: FromZeros, [u8]: FromZeros,

§

fn zero(&mut self)

Overwrites self with zeros. Read more
Source§

impl IntoBytes for Telecommand
where PrimaryHeader: IntoBytes, TelecommandSecondaryHeader: IntoBytes, [u8]: IntoBytes, (): DynamicPaddingFree<Self, { _ }>,

§

fn as_bytes(&self) -> &[u8]
where Self: Immutable,

Gets the bytes of this value. Read more
§

fn as_mut_bytes(&mut self) -> &mut [u8]
where Self: FromBytes,

Gets the bytes of this value mutably. Read more
§

fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to dst. Read more
§

fn write_to_prefix( &self, dst: &mut [u8], ) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to the prefix of dst. Read more
§

fn write_to_suffix( &self, dst: &mut [u8], ) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to the suffix of dst. Read more
Source§

impl KnownLayout for Telecommand
where [u8]: KnownLayout,

Source§

type PointerMetadata = <[u8] as KnownLayout>::PointerMetadata

The type of metadata stored in a pointer to Self. Read more
§

fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>

Computes the size of an object of type Self with the given pointer metadata. Read more
Source§

impl<'a> TryFrom<&'a SpacePacket> for &'a Telecommand

Source§

type Error = TelecommandError

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

fn try_from(sp: &'a SpacePacket) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFromBytes for Telecommand
where PrimaryHeader: TryFromBytes, TelecommandSecondaryHeader: TryFromBytes, [u8]: TryFromBytes,

§

fn try_ref_from_bytes( source: &[u8], ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the given source as a &Self. Read more
§

fn try_ref_from_prefix( source: &[u8], ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the prefix of the given source as a &Self. Read more
§

fn try_ref_from_suffix( source: &[u8], ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the suffix of the given source as a &Self. Read more
§

fn try_mut_from_bytes( bytes: &mut [u8], ) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the given source as a &mut Self without copying. Read more
§

fn try_mut_from_prefix( source: &mut [u8], ) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the prefix of the given source as a &mut Self. Read more
§

fn try_mut_from_suffix( source: &mut [u8], ) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the suffix of the given source as a &mut Self. Read more
§

fn try_ref_from_bytes_with_elems( source: &[u8], count: usize, ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout<PointerMetadata = usize> + Immutable,

Attempts to interpret the given source as a &Self with a DST length equal to count. Read more
§

fn try_ref_from_prefix_with_elems( source: &[u8], count: usize, ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout<PointerMetadata = usize> + Immutable,

Attempts to interpret the prefix of the given source as a &Self with a DST length equal to count. Read more
§

fn try_ref_from_suffix_with_elems( source: &[u8], count: usize, ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout<PointerMetadata = usize> + Immutable,

Attempts to interpret the suffix of the given source as a &Self with a DST length equal to count. Read more
§

fn try_mut_from_bytes_with_elems( source: &mut [u8], count: usize, ) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout<PointerMetadata = usize> + IntoBytes,

Attempts to interpret the given source as a &mut Self with a DST length equal to count. Read more
§

fn try_mut_from_prefix_with_elems( source: &mut [u8], count: usize, ) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout<PointerMetadata = usize> + IntoBytes,

Attempts to interpret the prefix of the given source as a &mut Self with a DST length equal to count. Read more
§

fn try_mut_from_suffix_with_elems( source: &mut [u8], count: usize, ) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout<PointerMetadata = usize> + IntoBytes,

Attempts to interpret the suffix of the given source as a &mut Self with a DST length equal to count. Read more
Source§

impl Immutable for Telecommand
where PrimaryHeader: Immutable, TelecommandSecondaryHeader: Immutable, [u8]: Immutable,

Source§

impl Unaligned for Telecommand
where PrimaryHeader: Unaligned, TelecommandSecondaryHeader: Unaligned, [u8]: Unaligned,

Auto Trait Implementations§

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<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.