Struct SpHeader

Source
pub struct SpHeader {
    pub version: u8,
    pub packet_id: PacketId,
    pub psc: PacketSequenceCtrl,
    pub data_len: u16,
}
Expand description

Space Packet Primary Header according to CCSDS 133.0-B-2.

§Arguments

  • version - CCSDS version field, occupies the first 3 bits of the raw header. Will generally be set to 0b000 in all constructors provided by this crate.
  • packet_id - Packet Identifier, which can also be used as a start marker. Occupies the last 13 bits of the first two bytes of the raw header
  • psc - Packet Sequence Control, occupies the third and fourth byte of the raw header
  • data_len - Data length field occupies the fifth and the sixth byte of the raw header

Fields§

§version: u8§packet_id: PacketId§psc: PacketSequenceCtrl§data_len: u16

Implementations§

Source§

impl SpHeader

Source

pub const fn new( packet_id: PacketId, psc: PacketSequenceCtrl, data_len: u16, ) -> Self

Source

pub const fn new_from_apid(apid: u16) -> Self

This constructor sets the sequence flag field to SequenceFlags::Unsegmented and the data length to 0.

This constructor will panic if the APID exceeds MAX_APID.

Source

pub fn new_from_apid_checked(apid: u16) -> Option<Self>

Checked variant of Self::new_from_apid.

Source

pub const fn new_from_fields( ptype: PacketType, sec_header: bool, apid: u16, seq_flags: SequenceFlags, seq_count: u16, data_len: u16, ) -> Self

This constructor panics if the passed APID exceeds MAX_APID or the passed packet sequence count exceeds MAX_SEQ_COUNT.

The checked constructor variants can be used to avoid panics.

Source

pub fn new_from_fields_checked( ptype: PacketType, sec_header: bool, apid: u16, seq_flags: SequenceFlags, seq_count: u16, data_len: u16, ) -> Option<Self>

Create a new Space Packet Header instance which can be used to create generic Space Packets.

This will return None if the APID or sequence count argument exceed MAX_APID or MAX_SEQ_COUNT respectively. The version field is set to 0b000.

Source

pub fn new_for_tm_checked( apid: u16, seq_flags: SequenceFlags, seq_count: u16, data_len: u16, ) -> Option<Self>

Helper function for telemetry space packet headers. The packet type field will be set accordingly. The secondary header flag field is set to false.

Source

pub fn new_for_tc_checked( apid: u16, seq_flags: SequenceFlags, seq_count: u16, data_len: u16, ) -> Option<Self>

Helper function for telemetry space packet headers. The packet type field will be set accordingly. The secondary header flag field is set to false.

Source

pub const fn new_for_tm( apid: u16, seq_flags: SequenceFlags, seq_count: u16, data_len: u16, ) -> Self

This is an unchecked constructor which can panic on invalid input.

Source

pub const fn new_for_tc( apid: u16, seq_flags: SequenceFlags, seq_count: u16, data_len: u16, ) -> Self

This is an unchecked constructor which can panic on invalid input.

Source

pub fn new_for_unseg_tm_checked( apid: u16, seq_count: u16, data_len: u16, ) -> Option<Self>

Variant of SpHeader::new_for_tm_checked which sets the sequence flag field to SequenceFlags::Unsegmented

Source

pub fn new_for_unseg_tc_checked( apid: u16, seq_count: u16, data_len: u16, ) -> Option<Self>

Variant of SpHeader::new_for_tc_checked which sets the sequence flag field to SequenceFlags::Unsegmented

Source

pub const fn new_for_unseg_tc(apid: u16, seq_count: u16, data_len: u16) -> Self

Variant of SpHeader::new_for_tc which sets the sequence flag field to SequenceFlags::Unsegmented.

This is an unchecked constructor which can panic on invalid input.

Source

pub const fn new_for_unseg_tm(apid: u16, seq_count: u16, data_len: u16) -> Self

Variant of SpHeader::new_for_tm which sets the sequence flag field to SequenceFlags::Unsegmented.

This is an unchecked constructor which can panic on invalid input.

Source

pub fn set_apid(&mut self, apid: u16) -> bool

Returns false and fails if the APID exceeds MAX_APID

Source

pub fn set_seq_count(&mut self, seq_count: u16) -> bool

Returns false and fails if the sequence count exceeds MAX_SEQ_COUNT

Source

pub fn set_seq_flags(&mut self, seq_flags: SequenceFlags)

Source

pub fn set_sec_header_flag(&mut self)

Source

pub fn clear_sec_header_flag(&mut self)

Source

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

Source

pub fn from_be_bytes(buf: &[u8]) -> Result<(Self, &[u8]), ByteConversionError>

Create a struct from a raw slice where the fields have network endianness (big). This function also returns the remaining part of the passed slice starting past the read CCSDS header.

Source

pub fn write_to_be_bytes<'a>( &self, buf: &'a mut [u8], ) -> Result<&'a mut [u8], ByteConversionError>

Write the header to a raw buffer using big endian format. This function returns the remaining part of the passed slice starting past the written CCSDS header.

Source

pub fn to_vec(&self) -> Vec<u8>

Available on crate feature alloc only.

Create a vector containing the CCSDS header.

Trait Implementations§

Source§

impl CcsdsPacket for SpHeader

Source§

fn ccsds_version(&self) -> u8

Source§

fn packet_id(&self) -> PacketId

Source§

fn psc(&self) -> PacketSequenceCtrl

Source§

fn data_len(&self) -> u16

Retrieve data length field
Source§

fn total_len(&self) -> usize

Retrieve the total packet size based on the data length field
Source§

fn packet_id_raw(&self) -> u16

Retrieve 13 bit Packet Identification field. Can usually be retrieved with a bitwise AND of the first 2 bytes with 0x1FFF.
Source§

fn psc_raw(&self) -> u16

Retrieve Packet Sequence Count
Source§

fn ptype(&self) -> PacketType

Retrieve Packet Type (TM: 0, TC: 1).
Source§

fn is_tm(&self) -> bool

Source§

fn is_tc(&self) -> bool

Source§

fn sec_header_flag(&self) -> bool

Retrieve the secondary header flag. Returns true if a secondary header is present and false if it is not.
Source§

fn apid(&self) -> u16

Retrieve Application Process ID.
Source§

fn seq_count(&self) -> u16

Source§

fn sequence_flags(&self) -> SequenceFlags

Source§

impl CcsdsPrimaryHeader for SpHeader

Source§

fn from_composite_fields( packet_id: PacketId, psc: PacketSequenceCtrl, data_len: u16, version: Option<u8>, ) -> Self

Source§

impl Clone for SpHeader

Source§

fn clone(&self) -> SpHeader

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SpHeader

Source§

fn default() -> Self

The default function sets the sequence flag field to SequenceFlags::Unsegmented and the data length to 0.

Source§

impl<'de> Deserialize<'de> for SpHeader

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Format for SpHeader

Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
Source§

impl From<SpHeader> for SpHeader

Source§

fn from(other: SpHeader) -> Self

Converts to this type from the input type.
Source§

impl From<SpHeader> for SpHeader

Source§

fn from(other: SpHeader) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for SpHeader

Source§

fn eq(&self, other: &SpHeader) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for SpHeader

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for SpHeader

Source§

impl Eq for SpHeader

Source§

impl StructuralPartialEq for SpHeader

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,