From 02098977a51ca8ac6a359fb8e8b8b9e06666576d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Aug 2023 19:55:42 +0200 Subject: [PATCH 1/3] added pdu conf src and dest id setter --- src/cfdp/pdu/mod.rs | 64 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/src/cfdp/pdu/mod.rs b/src/cfdp/pdu/mod.rs index adaa6c4..cb81c0f 100644 --- a/src/cfdp/pdu/mod.rs +++ b/src/cfdp/pdu/mod.rs @@ -168,22 +168,8 @@ impl CommonPduConfig { crc_flag: CrcFlag, direction: Direction, ) -> Result { - let source_id = source_id.into(); - let dest_id = dest_id.into(); + let (source_id, dest_id) = Self::source_dest_id_check(source_id, dest_id)?; let transaction_seq_num = transaction_seq_num.into(); - if source_id.size() != dest_id.size() { - return Err(PduError::SourceDestIdLenMissmatch(( - source_id.size(), - dest_id.size(), - ))); - } - if source_id.size() != 1 - && source_id.size() != 2 - && source_id.size() != 4 - && source_id.size() != 8 - { - return Err(PduError::InvalidEntityLen(source_id.size() as u8)); - } if transaction_seq_num.size() != 1 && transaction_seq_num.size() != 2 && transaction_seq_num.size() != 4 @@ -224,6 +210,39 @@ impl CommonPduConfig { self.source_entity_id } + fn source_dest_id_check( + source_id: impl Into, + dest_id: impl Into, + ) -> Result<(UnsignedByteField, UnsignedByteField), PduError> { + let source_id = source_id.into(); + let dest_id = dest_id.into(); + if source_id.size() != dest_id.size() { + return Err(PduError::SourceDestIdLenMissmatch(( + source_id.size(), + dest_id.size(), + ))); + } + if source_id.size() != 1 + && source_id.size() != 2 + && source_id.size() != 4 + && source_id.size() != 8 + { + return Err(PduError::InvalidEntityLen(source_id.size() as u8)); + } + Ok((source_id, dest_id)) + } + + pub fn set_source_and_dest_id( + &mut self, + source_id: impl Into, + dest_id: impl Into, + ) -> Result<(), PduError> { + let (source_id, dest_id) = Self::source_dest_id_check(source_id, dest_id)?; + self.source_entity_id = source_id; + self.dest_entity_id = dest_id; + Ok(()) + } + pub fn dest_id(&self) -> UnsignedByteField { self.dest_entity_id } @@ -666,6 +685,21 @@ mod tests { assert_eq!(pdu_header.header_len(), 7); } + #[test] + fn test_pdu_header_setter() { + let src_id = UnsignedByteFieldU8::new(1); + let dest_id = UnsignedByteFieldU8::new(2); + let transaction_id = UnsignedByteFieldU8::new(3); + let mut common_pdu_cfg = CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_id) + .expect("common config creation failed"); + let other_src_id = UnsignedByteFieldU16::new(5); + let other_dest_id = UnsignedByteFieldU16::new(6); + let set_result = common_pdu_cfg.set_source_and_dest_id(other_src_id, other_dest_id); + assert!(set_result.is_ok()); + assert_eq!(common_pdu_cfg.source_id(), other_src_id.into()); + assert_eq!(common_pdu_cfg.dest_id(), other_dest_id.into()); + } + #[test] fn test_serialization_1() { let src_id = UnsignedByteFieldU8::new(1); -- 2.43.0 From 837b412ef055d3b86a1c116b86edb81271511db0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Aug 2023 20:01:13 +0200 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 646a7db..d407a96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). call `user_data` but are also in line with the PUS packet standard names for those fields. - Added new marker trait `IsPusTelemetry` implemented by `PusTmCreator` and `PusTmReader`. - Added new marker trait `IsPusTelecommand` implemented by `PusTcCreator` and `PusTcReader`. +- New setter method `set_source_and_dest_id` for `CommonPduConfig`. # [v0.6.0] 2023-07-06 -- 2.43.0 From 17296ade19f0bf8b170741277870b36e0f4e3a60 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Aug 2023 20:04:50 +0200 Subject: [PATCH 3/3] fmt --- src/cfdp/pdu/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cfdp/pdu/mod.rs b/src/cfdp/pdu/mod.rs index cb81c0f..e1498cd 100644 --- a/src/cfdp/pdu/mod.rs +++ b/src/cfdp/pdu/mod.rs @@ -690,8 +690,9 @@ mod tests { let src_id = UnsignedByteFieldU8::new(1); let dest_id = UnsignedByteFieldU8::new(2); let transaction_id = UnsignedByteFieldU8::new(3); - let mut common_pdu_cfg = CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_id) - .expect("common config creation failed"); + let mut common_pdu_cfg = + CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_id) + .expect("common config creation failed"); let other_src_id = UnsignedByteFieldU16::new(5); let other_dest_id = UnsignedByteFieldU16::new(6); let set_result = common_pdu_cfg.set_source_and_dest_id(other_src_id, other_dest_id); -- 2.43.0