|
|
|
@ -52,7 +52,7 @@
|
|
|
|
|
//!
|
|
|
|
|
//! ```rust
|
|
|
|
|
//! use spacepackets::SpHeader;
|
|
|
|
|
//! let sp_header = SpHeader::tc_unseg(0x42, 12, 1).expect("Error creating CCSDS TC header");
|
|
|
|
|
//! let sp_header = SpHeader::new_for_unseg_tc_checked(0x42, 12, 1).expect("error creating CCSDS TC header");
|
|
|
|
|
//! println!("{:?}", sp_header);
|
|
|
|
|
//! let mut ccsds_buf: [u8; 32] = [0; 32];
|
|
|
|
|
//! sp_header.write_to_be_bytes(&mut ccsds_buf).expect("Writing CCSDS TC header failed");
|
|
|
|
@ -581,26 +581,63 @@ impl SpHeader {
|
|
|
|
|
Self::new_from_fields_checked(PacketType::Tc, false, apid, seq_flags, seq_count, data_len)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// This is an unchecked constructor which can panic on invalid input.
|
|
|
|
|
pub const fn new_for_tm(
|
|
|
|
|
apid: u16,
|
|
|
|
|
seq_flags: SequenceFlags,
|
|
|
|
|
seq_count: u16,
|
|
|
|
|
data_len: u16,
|
|
|
|
|
) -> Self {
|
|
|
|
|
Self::new_from_fields(PacketType::Tm, false, apid, seq_flags, seq_count, data_len)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// This is an unchecked constructor which can panic on invalid input.
|
|
|
|
|
pub const fn new_for_tc(
|
|
|
|
|
apid: u16,
|
|
|
|
|
seq_flags: SequenceFlags,
|
|
|
|
|
seq_count: u16,
|
|
|
|
|
data_len: u16,
|
|
|
|
|
) -> Self {
|
|
|
|
|
Self::new_from_fields(PacketType::Tc, false, apid, seq_flags, seq_count, data_len)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Variant of [SpHeader::new_for_tm_checked] which sets the sequence flag field to [SequenceFlags::Unsegmented]
|
|
|
|
|
pub fn new_for_unseg_tm_checked(apid: u16, seq_count: u16, data_len: u16) -> Option<Self> {
|
|
|
|
|
Self::new_for_tm_checked(apid, SequenceFlags::Unsegmented, seq_count, data_len)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Variant of [SpHeader::new_for_tc] which sets the sequence flag field to [SequenceFlags::Unsegmented]
|
|
|
|
|
/// Variant of [SpHeader::new_for_tc_checked] which sets the sequence flag field to [SequenceFlags::Unsegmented]
|
|
|
|
|
pub fn new_for_unseg_tc_checked(apid: u16, seq_count: u16, data_len: u16) -> Option<Self> {
|
|
|
|
|
Self::new_for_tc_checked(apid, SequenceFlags::Unsegmented, seq_count, data_len)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//noinspection RsTraitImplementation
|
|
|
|
|
delegate!(to self.packet_id {
|
|
|
|
|
/// Returns [false] and fails if the APID exceeds [MAX_APID]
|
|
|
|
|
pub fn set_apid(&mut self, apid: u16) -> bool;
|
|
|
|
|
});
|
|
|
|
|
/// 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.
|
|
|
|
|
pub const fn new_for_unseg_tc(apid: u16, seq_count: u16, data_len: u16) -> Self {
|
|
|
|
|
Self::new_for_tc(apid, SequenceFlags::Unsegmented, seq_count, data_len)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delegate!(to self.psc {
|
|
|
|
|
/// Returns [false] and fails if the sequence count exceeds [MAX_SEQ_COUNT]
|
|
|
|
|
pub fn set_seq_count(&mut self, seq_count: u16) -> bool;
|
|
|
|
|
});
|
|
|
|
|
/// 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.
|
|
|
|
|
pub const fn new_for_unseg_tm(apid: u16, seq_count: u16, data_len: u16) -> Self {
|
|
|
|
|
Self::new_for_tm(apid, SequenceFlags::Unsegmented, seq_count, data_len)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delegate! {
|
|
|
|
|
to self.packet_id {
|
|
|
|
|
/// Returns [false] and fails if the APID exceeds [MAX_APID]
|
|
|
|
|
pub fn set_apid(&mut self, apid: u16) -> bool;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delegate! {
|
|
|
|
|
to self.psc {
|
|
|
|
|
/// Returns [false] and fails if the sequence count exceeds [MAX_SEQ_COUNT]
|
|
|
|
|
pub fn set_seq_count(&mut self, seq_count: u16) -> bool;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_seq_flags(&mut self, seq_flags: SequenceFlags) {
|
|
|
|
|
self.psc.seq_flags = seq_flags;
|
|
|
|
@ -949,7 +986,8 @@ pub(crate) mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
#[cfg(feature = "serde")]
|
|
|
|
|
fn test_serde_sph() {
|
|
|
|
|
let sp_header = SpHeader::tc_unseg(0x42, 12, 0).expect("Error creating SP header");
|
|
|
|
|
let sp_header =
|
|
|
|
|
SpHeader::new_for_unseg_tc_checked(0x42, 12, 0).expect("Error creating SP header");
|
|
|
|
|
assert_eq!(sp_header.ccsds_version(), 0b000);
|
|
|
|
|
assert!(sp_header.is_tc());
|
|
|
|
|
assert!(!sp_header.sec_header_flag());
|
|
|
|
@ -971,7 +1009,8 @@ pub(crate) mod tests {
|
|
|
|
|
assert_eq!(sp_header.ccsds_version(), 0b000);
|
|
|
|
|
assert_eq!(sp_header.data_len, 0);
|
|
|
|
|
|
|
|
|
|
let sp_header = SpHeader::tm_unseg(0x7, 22, 36).expect("Error creating SP header");
|
|
|
|
|
let sp_header =
|
|
|
|
|
SpHeader::new_for_unseg_tm_checked(0x7, 22, 36).expect("Error creating SP header");
|
|
|
|
|
assert_eq!(sp_header.ccsds_version(), 0b000);
|
|
|
|
|
assert!(sp_header.is_tm());
|
|
|
|
|
assert!(!sp_header.sec_header_flag());
|
|
|
|
@ -985,8 +1024,8 @@ pub(crate) mod tests {
|
|
|
|
|
assert_eq!(sp_header.ccsds_version(), 0b000);
|
|
|
|
|
|
|
|
|
|
let from_comp_fields = SpHeader::from_composite_fields(
|
|
|
|
|
PacketId::new(PacketType::Tc, true, 0x42).unwrap(),
|
|
|
|
|
PacketSequenceCtrl::new(SequenceFlags::Unsegmented, 0x7).unwrap(),
|
|
|
|
|
PacketId::new(PacketType::Tc, true, 0x42),
|
|
|
|
|
PacketSequenceCtrl::new(SequenceFlags::Unsegmented, 0x7),
|
|
|
|
|
0,
|
|
|
|
|
None,
|
|
|
|
|
);
|
|
|
|
@ -1035,6 +1074,12 @@ pub(crate) mod tests {
|
|
|
|
|
verify_sp_fields(PacketType::Tc, &sp_header);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_tc_ctor_unseg_const() {
|
|
|
|
|
let sp_header = SpHeader::new_for_unseg_tc(0x42, 25, 0);
|
|
|
|
|
verify_sp_fields(PacketType::Tc, &sp_header);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_tm_ctor() {
|
|
|
|
|
let sp_header = SpHeader::new_for_tm_checked(0x42, SequenceFlags::Unsegmented, 25, 0);
|
|
|
|
@ -1043,6 +1088,12 @@ pub(crate) mod tests {
|
|
|
|
|
verify_sp_fields(PacketType::Tm, &sp_header);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_tm_ctor_const() {
|
|
|
|
|
let sp_header = SpHeader::new_for_tm(0x42, SequenceFlags::Unsegmented, 25, 0);
|
|
|
|
|
verify_sp_fields(PacketType::Tm, &sp_header);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_tm_ctor_unseg() {
|
|
|
|
|
let sp_header = SpHeader::new_for_unseg_tm_checked(0x42, 25, 0);
|
|
|
|
|