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 headerpsc- Packet Sequence Control, occupies the third and fourth byte of the raw headerdata_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: u16Implementations§
Source§impl SpHeader
impl SpHeader
pub const fn new( packet_id: PacketId, psc: PacketSequenceCtrl, data_len: u16, ) -> Self
Sourcepub const fn new_from_apid(apid: u16) -> Self
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.
Sourcepub fn new_from_apid_checked(apid: u16) -> Option<Self>
pub fn new_from_apid_checked(apid: u16) -> Option<Self>
Checked variant of Self::new_from_apid.
Sourcepub const fn new_from_fields(
ptype: PacketType,
sec_header: bool,
apid: u16,
seq_flags: SequenceFlags,
seq_count: u16,
data_len: u16,
) -> Self
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.
Sourcepub fn new_from_fields_checked(
ptype: PacketType,
sec_header: bool,
apid: u16,
seq_flags: SequenceFlags,
seq_count: u16,
data_len: u16,
) -> Option<Self>
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.
Sourcepub fn new_for_tm_checked(
apid: u16,
seq_flags: SequenceFlags,
seq_count: u16,
data_len: u16,
) -> Option<Self>
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.
Sourcepub fn new_for_tc_checked(
apid: u16,
seq_flags: SequenceFlags,
seq_count: u16,
data_len: u16,
) -> Option<Self>
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.
Sourcepub const fn new_for_tm(
apid: u16,
seq_flags: SequenceFlags,
seq_count: u16,
data_len: u16,
) -> Self
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.
Sourcepub const fn new_for_tc(
apid: u16,
seq_flags: SequenceFlags,
seq_count: u16,
data_len: u16,
) -> Self
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.
Sourcepub fn new_for_unseg_tm_checked(
apid: u16,
seq_count: u16,
data_len: u16,
) -> Option<Self>
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
Sourcepub fn new_for_unseg_tc_checked(
apid: u16,
seq_count: u16,
data_len: u16,
) -> Option<Self>
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
Sourcepub const fn new_for_unseg_tc(apid: u16, seq_count: u16, data_len: u16) -> Self
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.
Sourcepub const fn new_for_unseg_tm(apid: u16, seq_count: u16, data_len: u16) -> Self
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.
Sourcepub fn set_seq_count(&mut self, seq_count: u16) -> bool
pub fn set_seq_count(&mut self, seq_count: u16) -> bool
Returns false and fails if the sequence count exceeds MAX_SEQ_COUNT
pub fn set_seq_flags(&mut self, seq_flags: SequenceFlags)
pub fn set_sec_header_flag(&mut self)
pub fn clear_sec_header_flag(&mut self)
pub fn set_packet_type(&mut self, packet_type: PacketType)
Sourcepub fn from_be_bytes(buf: &[u8]) -> Result<(Self, &[u8]), ByteConversionError>
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.
Sourcepub fn write_to_be_bytes<'a>(
&self,
buf: &'a mut [u8],
) -> Result<&'a mut [u8], ByteConversionError>
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.
Trait Implementations§
Source§impl CcsdsPacket for SpHeader
impl CcsdsPacket for SpHeader
fn ccsds_version(&self) -> u8
fn packet_id(&self) -> PacketId
fn psc(&self) -> PacketSequenceCtrl
Source§fn packet_id_raw(&self) -> u16
fn packet_id_raw(&self) -> u16
Source§fn ptype(&self) -> PacketType
fn ptype(&self) -> PacketType
fn is_tm(&self) -> bool
fn is_tc(&self) -> bool
Source§fn sec_header_flag(&self) -> bool
fn sec_header_flag(&self) -> bool
fn seq_count(&self) -> u16
fn sequence_flags(&self) -> SequenceFlags
Source§impl CcsdsPrimaryHeader for SpHeader
impl CcsdsPrimaryHeader for SpHeader
fn from_composite_fields( packet_id: PacketId, psc: PacketSequenceCtrl, data_len: u16, version: Option<u8>, ) -> Self
Source§impl Default for SpHeader
impl Default for SpHeader
Source§fn default() -> Self
fn default() -> Self
The default function sets the sequence flag field to SequenceFlags::Unsegmented and the data length to 0.