PDU config tweak #17
@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
## Fixed
|
## Fixed
|
||||||
|
|
||||||
- All `MetadataGenericParam` fields are now public.
|
- All `MetadataGenericParam` fields are now public.
|
||||||
|
- New setter method `set_source_and_dest_id` for `CommonPduConfig`.
|
||||||
|
|
||||||
# [v0.6.0] 2023-07-06
|
# [v0.6.0] 2023-07-06
|
||||||
|
|
||||||
|
@ -168,22 +168,8 @@ impl CommonPduConfig {
|
|||||||
crc_flag: CrcFlag,
|
crc_flag: CrcFlag,
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
) -> Result<Self, PduError> {
|
) -> Result<Self, PduError> {
|
||||||
let source_id = source_id.into();
|
let (source_id, dest_id) = Self::source_dest_id_check(source_id, dest_id)?;
|
||||||
let dest_id = dest_id.into();
|
|
||||||
let transaction_seq_num = transaction_seq_num.into();
|
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
|
if transaction_seq_num.size() != 1
|
||||||
&& transaction_seq_num.size() != 2
|
&& transaction_seq_num.size() != 2
|
||||||
&& transaction_seq_num.size() != 4
|
&& transaction_seq_num.size() != 4
|
||||||
@ -224,6 +210,39 @@ impl CommonPduConfig {
|
|||||||
self.source_entity_id
|
self.source_entity_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn source_dest_id_check(
|
||||||
|
source_id: impl Into<UnsignedByteField>,
|
||||||
|
dest_id: impl Into<UnsignedByteField>,
|
||||||
|
) -> 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<UnsignedByteField>,
|
||||||
|
dest_id: impl Into<UnsignedByteField>,
|
||||||
|
) -> 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 {
|
pub fn dest_id(&self) -> UnsignedByteField {
|
||||||
self.dest_entity_id
|
self.dest_entity_id
|
||||||
}
|
}
|
||||||
@ -690,12 +709,29 @@ mod tests {
|
|||||||
let default_conf = CommonPduConfig::default();
|
let default_conf = CommonPduConfig::default();
|
||||||
assert_eq!(default_conf.source_id(), UnsignedByteFieldU8::new(0).into());
|
assert_eq!(default_conf.source_id(), UnsignedByteFieldU8::new(0).into());
|
||||||
assert_eq!(default_conf.dest_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.transaction_seq_num,
|
||||||
|
UnsignedByteFieldU8::new(0).into()
|
||||||
|
);
|
||||||
assert_eq!(default_conf.trans_mode, TransmissionMode::Acknowledged);
|
assert_eq!(default_conf.trans_mode, TransmissionMode::Acknowledged);
|
||||||
assert_eq!(default_conf.direction, Direction::TowardsReceiver);
|
assert_eq!(default_conf.direction, Direction::TowardsReceiver);
|
||||||
assert_eq!(default_conf.crc_flag, CrcFlag::NoCrc);
|
assert_eq!(default_conf.crc_flag, CrcFlag::NoCrc);
|
||||||
assert_eq!(default_conf.file_flag, LargeFileFlag::Normal);
|
assert_eq!(default_conf.file_flag, LargeFileFlag::Normal);
|
||||||
}
|
}
|
||||||
|
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]
|
#[test]
|
||||||
fn test_serialization_1() {
|
fn test_serialization_1() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user