also added a unittest
Rust/spacepackets/pipeline/head There was a failure building this commit Details
Rust/spacepackets/pipeline/pr-main There was a failure building this commit Details

This commit is contained in:
Robin Müller 2023-08-10 20:22:07 +02:00
parent fd893fbf89
commit a3da71668f
Signed by: muellerr
GPG Key ID: 407F9B00F858F270
2 changed files with 26 additions and 12 deletions

View File

@ -22,8 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
classes. The old `PusTm` class is deprecated now.
- Implement `Display` and `Error` for `StdTimestampError` properly.
- Remove some redundant `Error` suffixes for enum error variants.
- `CommonPduConfig`: `new_with_defaults` replaced by `new_with_byte_fields`
and `new_with_defaults` has now empty argument list.
- `CommonPduConfig`: `new_with_defaults` replaced by `new_with_byte_fields`.
## Added
@ -33,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added new marker trait `IsPusTelecommand` implemented by `PusTcCreator` and `PusTcReader`.
- `metadata_param` getter method for the `MetadataPdu` object.
- `Default` impl for CFDP `ChecksumType`
- `Default` impl for CFDP `CommonPduConfig`
## Fixed

View File

@ -220,10 +220,20 @@ impl CommonPduConfig {
)
}
pub fn source_id(&self) -> UnsignedByteField {
self.source_entity_id
}
pub fn dest_id(&self) -> UnsignedByteField {
self.dest_entity_id
}
}
impl Default for CommonPduConfig {
/// The defaults for the source ID, destination ID and the transaction sequence number is the
/// [UnsignedByteFieldU8] with an intitial value of 0
pub fn new_with_defaults() -> Self {
// new can not fail for these input parameters
fn default() -> Self {
// The new function can not fail for these input parameters.
Self::new(
UnsignedByteFieldU8::new(0),
UnsignedByteFieldU8::new(0),
@ -235,14 +245,6 @@ impl CommonPduConfig {
)
.unwrap()
}
pub fn source_id(&self) -> UnsignedByteField {
self.source_entity_id
}
pub fn dest_id(&self) -> UnsignedByteField {
self.dest_entity_id
}
}
pub const FIXED_HEADER_LEN: usize = 4;
@ -683,6 +685,18 @@ mod tests {
assert_eq!(pdu_header.header_len(), 7);
}
#[test]
fn test_basic_state_default() {
let default_conf = CommonPduConfig::default();
assert_eq!(default_conf.source_id(), UnsignedByteFieldU8::new(0).into());
assert_eq!(default_conf.dest_id(), UnsignedByteFieldU8::new(0).into());
assert_eq!(default_conf.transaction_seq_num, UnsignedByteFieldU8::new(0).into());
assert_eq!(default_conf.trans_mode, TransmissionMode::Acknowledged);
assert_eq!(default_conf.direction, Direction::TowardsReceiver);
assert_eq!(default_conf.crc_flag, CrcFlag::NoCrc);
assert_eq!(default_conf.file_flag, LargeFileFlag::Normal);
}
#[test]
fn test_serialization_1() {
let src_id = UnsignedByteFieldU8::new(1);