pub struct PrimaryHeader {
pub version: u8,
pub packet_type: PacketType,
pub secondary_header: bool,
pub apid: u16,
pub sequence_flag: SequenceFlag,
pub sequence_number: u16,
}Expand description
Primary Header used in the Space Packet Protocol.
This data structure encapsulates the packet version number, packet identification, and sequence control field of the primary header of a SpacePacket. It is possible, although not neccessary to work with the PrimaryHeader struct directly.
Typical usage involves creating a SpacePacket, which internally constructs the PrimaryHeader using the arguments passed.
use ccsds_rs::spp::{SpacePacket, PacketType, SequenceFlag};
// generates new SpacePacket, internally constructing the PrimaryHeader.
let my_space_packet = SpacePacket::new(
PacketType::Telecommand,
false,
17,
SequenceFlag::Unsegmented,
0,
"Cool Space Data".as_bytes().to_vec()
);Note that the user data length field is not included as a field within PrimaryHeader, The data length field is generated at encoding time of the SpacePacket.
Fields§
§version: u8Hardcoded to 0b000, but here incase standard changes in the future (3 bits)
packet_type: PacketTypePacket type defined by PacketType enum (1 bit)
secondary_header: boolIndicates if secondary header is used (1 bit)
apid: u16Application process ID of the packet (11 bits)
sequence_flag: SequenceFlagSequence flag defined by SequenceFlag (2 bits)
sequence_number: u16Sequence number (14 bits)
Implementations§
Source§impl PrimaryHeader
impl PrimaryHeader
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
Encodes the PrimaryHeader into a vector of big endian bytes as described by CCSDS 133.0-B-2.
Sourcepub fn decode(buf: &[u8]) -> Result<Self, Error>
pub fn decode(buf: &[u8]) -> Result<Self, Error>
Decodes the PrimaryHeader from a slice of bytes. Returns the result of the operation, on success giving the decoded PrimaryHeader.
Decoding can fail for the following reasons:
- Unsupported Space Packet Protocol version if the version number found in the primary header is something other then version 0.
- Incomplete header if the byte slice supplied as an argument is less than 4 bytes in length.
Trait Implementations§
Source§impl Clone for PrimaryHeader
impl Clone for PrimaryHeader
Source§fn clone(&self) -> PrimaryHeader
fn clone(&self) -> PrimaryHeader
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more