prepare next patch version

This commit is contained in:
Robin Müller 2024-04-20 10:42:36 +02:00
parent 619b22e58f
commit 8b1ccb0cd0
Signed by: muellerr
GPG Key ID: A649FB78196E3849
3 changed files with 42 additions and 9 deletions

View File

@ -8,6 +8,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased] # [unreleased]
# [v0.11.1] 2024-04-20
## Fixed
- The default data length for for `SpHeader` constructors where the data field length is not
specified is now 0.
- The `SpHeader::new_from_fields` is public now.
## Added
- `SpHeader::to_vec` method.
# [v0.11.0] 2024-04-16 # [v0.11.0] 2024-04-16
## Changed ## Changed

View File

@ -1,6 +1,6 @@
[package] [package]
name = "spacepackets" name = "spacepackets"
version = "0.11.0" version = "0.11.1"
edition = "2021" edition = "2021"
rust-version = "1.65" rust-version = "1.65"
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"] authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]

View File

@ -505,8 +505,8 @@ pub struct SpHeader {
pub type SpacePacketHeader = SpHeader; pub type SpacePacketHeader = SpHeader;
impl Default for SpHeader { impl Default for SpHeader {
/// The default function sets the sequence flag field to [SequenceFlags::Unsegmented]. The data /// The default function sets the sequence flag field to [SequenceFlags::Unsegmented] and the
/// length field is set to 1, which denotes an empty space packets. /// data length to 0.
#[inline] #[inline]
fn default() -> Self { fn default() -> Self {
SpHeader { SpHeader {
@ -516,7 +516,7 @@ impl Default for SpHeader {
seq_flags: SequenceFlags::Unsegmented, seq_flags: SequenceFlags::Unsegmented,
seq_count: 0, seq_count: 0,
}, },
data_len: 1, data_len: 0,
} }
} }
} }
@ -532,8 +532,8 @@ impl SpHeader {
} }
} }
/// This constructor sets the sequence flag field to [SequenceFlags::Unsegmented]. The data /// This constructor sets the sequence flag field to [SequenceFlags::Unsegmented] and the data
/// length field is set to 1, which denotes an empty space packets. /// length to 0.
/// ///
/// This constructor will panic if the APID exceeds [MAX_APID]. /// This constructor will panic if the APID exceeds [MAX_APID].
#[inline] #[inline]
@ -545,7 +545,7 @@ impl SpHeader {
seq_flags: SequenceFlags::Unsegmented, seq_flags: SequenceFlags::Unsegmented,
seq_count: 0, seq_count: 0,
}, },
data_len: 1, data_len: 0,
} }
} }
@ -559,7 +559,7 @@ impl SpHeader {
seq_flags: SequenceFlags::Unsegmented, seq_flags: SequenceFlags::Unsegmented,
seq_count: 0, seq_count: 0,
}, },
data_len: 1, data_len: 0,
}) })
} }
@ -568,7 +568,7 @@ impl SpHeader {
/// ///
/// The checked constructor variants can be used to avoid panics. /// The checked constructor variants can be used to avoid panics.
#[inline] #[inline]
const fn new_from_fields( pub const fn new_from_fields(
ptype: PacketType, ptype: PacketType,
sec_header: bool, sec_header: bool,
apid: u16, apid: u16,
@ -755,6 +755,15 @@ impl SpHeader {
.ok_or(ByteConversionError::ZeroCopyToError)?; .ok_or(ByteConversionError::ZeroCopyToError)?;
Ok(&mut buf[CCSDS_HEADER_LEN..]) Ok(&mut buf[CCSDS_HEADER_LEN..])
} }
/// Create a vector containing the CCSDS header.
#[cfg(feature = "alloc")]
pub fn to_vec(&self) -> alloc::vec::Vec<u8> {
let mut vec = alloc::vec![0; CCSDS_HEADER_LEN];
// This can not fail.
self.write_to_be_bytes(&mut vec[..]).unwrap();
vec
}
} }
impl CcsdsPacket for SpHeader { impl CcsdsPacket for SpHeader {
@ -1260,12 +1269,14 @@ pub(crate) mod tests {
fn sp_header_from_apid() { fn sp_header_from_apid() {
let sp_header = SpHeader::new_from_apid(0x03); let sp_header = SpHeader::new_from_apid(0x03);
assert_eq!(sp_header.apid(), 0x03); assert_eq!(sp_header.apid(), 0x03);
assert_eq!(sp_header.data_len(), 0);
} }
#[test] #[test]
fn sp_header_from_apid_checked() { fn sp_header_from_apid_checked() {
let sp_header = SpHeader::new_from_apid_checked(0x03).unwrap(); let sp_header = SpHeader::new_from_apid_checked(0x03).unwrap();
assert_eq!(sp_header.apid(), 0x03); assert_eq!(sp_header.apid(), 0x03);
assert_eq!(sp_header.data_len(), 0);
} }
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
@ -1279,4 +1290,14 @@ pub(crate) mod tests {
expected: 2, expected: 2,
}); });
} }
#[test]
fn test_sp_header_as_vec() {
let sp_header = SpHeader::new_for_unseg_tc(0x42, 25, 1);
let sp_header_as_vec = sp_header.to_vec();
let sp_header_read_back = SpHeader::from_be_bytes(&sp_header_as_vec)
.expect("Error reading back SP header")
.0;
assert_eq!(sp_header, sp_header_read_back);
}
} }