PDU config tweak #17
@ -22,6 +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`.
|
||||
|
||||
## Added
|
||||
|
||||
@ -29,6 +30,13 @@ 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`.
|
||||
- `metadata_param` getter method for the `MetadataPdu` object.
|
||||
- `Default` impl for CFDP `ChecksumType`
|
||||
- `Default` impl for CFDP `CommonPduConfig`
|
||||
|
||||
## Fixed
|
||||
|
||||
- All `MetadataGenericParam` fields are now public.
|
||||
- New setter method `set_source_and_dest_id` for `CommonPduConfig`.
|
||||
|
||||
# [v0.6.0] 2023-07-06
|
||||
|
@ -134,6 +134,12 @@ pub enum ChecksumType {
|
||||
NullChecksum = 15,
|
||||
}
|
||||
|
||||
impl Default for ChecksumType {
|
||||
fn default() -> Self {
|
||||
Self::NullChecksum
|
||||
}
|
||||
}
|
||||
|
||||
pub const NULL_CHECKSUM_U32: [u8; 4] = [0; 4];
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
|
@ -235,7 +235,7 @@ mod tests {
|
||||
let dest_id = UbfU8::new(2);
|
||||
let transaction_seq_num = UbfU8::new(3);
|
||||
let common_conf =
|
||||
CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_seq_num).unwrap();
|
||||
CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_seq_num).unwrap();
|
||||
let pdu_header = PduHeader::new_for_file_data_default(common_conf, 0);
|
||||
let file_data: [u8; 4] = [1, 2, 3, 4];
|
||||
let fd_pdu = FileDataPdu::new_no_seg_metadata(pdu_header, 10, &file_data);
|
||||
@ -254,7 +254,7 @@ mod tests {
|
||||
let dest_id = UbfU8::new(2);
|
||||
let transaction_seq_num = UbfU8::new(3);
|
||||
let common_conf =
|
||||
CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_seq_num).unwrap();
|
||||
CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_seq_num).unwrap();
|
||||
let pdu_header = PduHeader::new_for_file_data_default(common_conf, 0);
|
||||
let file_data: [u8; 4] = [1, 2, 3, 4];
|
||||
let fd_pdu = FileDataPdu::new_no_seg_metadata(pdu_header, 10, &file_data);
|
||||
@ -289,7 +289,7 @@ mod tests {
|
||||
let dest_id = UbfU8::new(2);
|
||||
let transaction_seq_num = UbfU8::new(3);
|
||||
let common_conf =
|
||||
CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_seq_num).unwrap();
|
||||
CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_seq_num).unwrap();
|
||||
let pdu_header = PduHeader::new_for_file_data_default(common_conf, 0);
|
||||
let file_data: [u8; 4] = [1, 2, 3, 4];
|
||||
let fd_pdu = FileDataPdu::new_no_seg_metadata(pdu_header, 10, &file_data);
|
||||
@ -307,7 +307,7 @@ mod tests {
|
||||
let dest_id = UbfU8::new(2);
|
||||
let transaction_seq_num = UbfU8::new(3);
|
||||
let common_conf =
|
||||
CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_seq_num).unwrap();
|
||||
CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_seq_num).unwrap();
|
||||
let pdu_header = PduHeader::new_for_file_data(
|
||||
common_conf,
|
||||
0,
|
||||
@ -372,7 +372,7 @@ mod tests {
|
||||
let dest_id = UbfU8::new(2);
|
||||
let transaction_seq_num = UbfU8::new(3);
|
||||
let common_conf =
|
||||
CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_seq_num).unwrap();
|
||||
CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_seq_num).unwrap();
|
||||
let pdu_header = PduHeader::new_for_file_data(
|
||||
common_conf,
|
||||
0,
|
||||
|
@ -11,12 +11,12 @@ use alloc::vec::Vec;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct MetadataGenericParams {
|
||||
closure_requested: bool,
|
||||
checksum_type: ChecksumType,
|
||||
file_size: u64,
|
||||
pub closure_requested: bool,
|
||||
pub checksum_type: ChecksumType,
|
||||
pub file_size: u64,
|
||||
}
|
||||
|
||||
impl MetadataGenericParams {
|
||||
@ -145,6 +145,10 @@ impl<'src_name, 'dest_name, 'opts> MetadataPdu<'src_name, 'dest_name, 'opts> {
|
||||
pdu
|
||||
}
|
||||
|
||||
pub fn metadata_params(&self) -> &MetadataGenericParams {
|
||||
&self.metadata_params
|
||||
}
|
||||
|
||||
pub fn src_file_name(&self) -> Lv<'src_name> {
|
||||
self.src_file_name
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! CFDP Packet Data Unit (PDU) support.
|
||||
use crate::cfdp::*;
|
||||
use crate::util::{UnsignedByteField, UnsignedEnum};
|
||||
use crate::util::{UnsignedByteField, UnsignedByteFieldU8, UnsignedEnum};
|
||||
use crate::CRC_CCITT_FALSE;
|
||||
use crate::{ByteConversionError, SizeMissmatch};
|
||||
use core::fmt::{Display, Formatter};
|
||||
@ -190,7 +190,7 @@ impl CommonPduConfig {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_with_defaults(
|
||||
pub fn new_with_byte_fields(
|
||||
source_id: impl Into<UnsignedByteField>,
|
||||
dest_id: impl Into<UnsignedByteField>,
|
||||
transaction_seq_num: impl Into<UnsignedByteField>,
|
||||
@ -248,6 +248,24 @@ impl CommonPduConfig {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
fn default() -> Self {
|
||||
// The new function can not fail for these input parameters.
|
||||
Self::new(
|
||||
UnsignedByteFieldU8::new(0),
|
||||
UnsignedByteFieldU8::new(0),
|
||||
UnsignedByteFieldU8::new(0),
|
||||
TransmissionMode::Acknowledged,
|
||||
LargeFileFlag::Normal,
|
||||
CrcFlag::NoCrc,
|
||||
Direction::TowardsReceiver,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub const FIXED_HEADER_LEN: usize = 4;
|
||||
|
||||
/// Abstraction for the PDU header common to all CFDP PDUs.
|
||||
@ -593,8 +611,9 @@ mod tests {
|
||||
let src_id = UbfU8::new(5);
|
||||
let dest_id = UbfU8::new(10);
|
||||
let transaction_seq_num = UbfU8::new(20);
|
||||
let mut pdu_conf = CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_seq_num)
|
||||
.expect("Generating common PDU config");
|
||||
let mut pdu_conf =
|
||||
CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_seq_num)
|
||||
.expect("Generating common PDU config");
|
||||
pdu_conf.crc_flag = crc_flag;
|
||||
pdu_conf.file_flag = fss;
|
||||
pdu_conf
|
||||
@ -666,7 +685,7 @@ mod tests {
|
||||
let src_id = UnsignedByteFieldU8::new(1);
|
||||
let dest_id = UnsignedByteFieldU8::new(2);
|
||||
let transaction_id = UnsignedByteFieldU8::new(3);
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_id)
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_id)
|
||||
.expect("common config creation failed");
|
||||
let pdu_header = PduHeader::new_no_file_data(common_pdu_cfg, 5);
|
||||
assert_eq!(pdu_header.pdu_type(), PduType::FileDirective);
|
||||
@ -686,12 +705,25 @@ mod tests {
|
||||
}
|
||||
|
||||
#[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);
|
||||
}
|
||||
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)
|
||||
CommonPduConfig::new_with_byte_fields(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);
|
||||
@ -706,7 +738,7 @@ mod tests {
|
||||
let src_id = UnsignedByteFieldU8::new(1);
|
||||
let dest_id = UnsignedByteFieldU8::new(2);
|
||||
let transaction_id = UnsignedByteFieldU8::new(3);
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_id)
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_id)
|
||||
.expect("common config creation failed");
|
||||
let pdu_header = PduHeader::new_no_file_data(common_pdu_cfg, 5);
|
||||
let mut buf: [u8; 7] = [0; 7];
|
||||
@ -722,7 +754,7 @@ mod tests {
|
||||
let src_id = UnsignedByteFieldU8::new(1);
|
||||
let dest_id = UnsignedByteFieldU8::new(2);
|
||||
let transaction_id = UnsignedByteFieldU8::new(3);
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_id)
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_id)
|
||||
.expect("common config creation failed");
|
||||
let pdu_header = PduHeader::new_no_file_data(common_pdu_cfg, 5);
|
||||
let mut buf: [u8; 7] = [0; 7];
|
||||
@ -741,7 +773,7 @@ mod tests {
|
||||
let dest_id = UnsignedByteFieldU16::new(0x0203);
|
||||
let transaction_id = UnsignedByteFieldU16::new(0x0405);
|
||||
let mut common_pdu_cfg =
|
||||
CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_id)
|
||||
CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_id)
|
||||
.expect("common config creation failed");
|
||||
common_pdu_cfg.crc_flag = CrcFlag::WithCrc;
|
||||
common_pdu_cfg.direction = Direction::TowardsSender;
|
||||
@ -768,7 +800,7 @@ mod tests {
|
||||
let dest_id = UnsignedByteFieldU16::new(0x0203);
|
||||
let transaction_id = UnsignedByteFieldU16::new(0x0405);
|
||||
let mut common_pdu_cfg =
|
||||
CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_id)
|
||||
CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_id)
|
||||
.expect("common config creation failed");
|
||||
common_pdu_cfg.crc_flag = CrcFlag::WithCrc;
|
||||
common_pdu_cfg.direction = Direction::TowardsSender;
|
||||
@ -795,7 +827,7 @@ mod tests {
|
||||
let src_id = UnsignedByteFieldU8::new(1);
|
||||
let dest_id = UnsignedByteFieldU8::new(2);
|
||||
let transaction_id = UnsignedByteFieldU8::new(3);
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_id)
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_id)
|
||||
.expect("common config creation failed");
|
||||
let pdu_header = PduHeader::new_no_file_data(common_pdu_cfg, 5);
|
||||
let mut buf: [u8; 7] = [0; 7];
|
||||
@ -834,7 +866,7 @@ mod tests {
|
||||
let src_id = UnsignedByteFieldU8::new(1);
|
||||
let dest_id = UnsignedByteFieldU8::new(2);
|
||||
let transaction_id = UnsignedByteFieldU8::new(3);
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_id)
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_id)
|
||||
.expect("common config creation failed");
|
||||
let pdu_header = PduHeader::new_no_file_data(common_pdu_cfg, 5);
|
||||
let mut buf: [u8; 7] = [0; 7];
|
||||
@ -857,7 +889,8 @@ mod tests {
|
||||
let dest_id = UbfU8::new(2);
|
||||
let transaction_seq_id = UbfU8::new(3);
|
||||
let invalid_byte_field = UnsignedByteField::new(3, 5);
|
||||
let pdu_conf_res = CommonPduConfig::new_with_defaults(src_id, dest_id, invalid_byte_field);
|
||||
let pdu_conf_res =
|
||||
CommonPduConfig::new_with_byte_fields(src_id, dest_id, invalid_byte_field);
|
||||
assert!(pdu_conf_res.is_err());
|
||||
let error = pdu_conf_res.unwrap_err();
|
||||
if let PduError::InvalidTransactionSeqNumLen(len) = error {
|
||||
@ -865,7 +898,7 @@ mod tests {
|
||||
} else {
|
||||
panic!("Invalid exception: {}", error)
|
||||
}
|
||||
let pdu_conf_res = CommonPduConfig::new_with_defaults(
|
||||
let pdu_conf_res = CommonPduConfig::new_with_byte_fields(
|
||||
invalid_byte_field,
|
||||
invalid_byte_field,
|
||||
transaction_seq_id,
|
||||
@ -883,7 +916,8 @@ mod tests {
|
||||
let src_id = UnsignedByteField::new(1, 5);
|
||||
let dest_id = UnsignedByteField::new(2, 5);
|
||||
let transaction_seq_id = UbfU8::new(3);
|
||||
let pdu_conf_res = CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_seq_id);
|
||||
let pdu_conf_res =
|
||||
CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_seq_id);
|
||||
assert!(pdu_conf_res.is_err());
|
||||
let error = pdu_conf_res.unwrap_err();
|
||||
if let PduError::SourceDestIdLenMissmatch((src_len, dest_len)) = error {
|
||||
@ -897,7 +931,7 @@ mod tests {
|
||||
let src_id = UnsignedByteFieldU8::new(1);
|
||||
let dest_id = UnsignedByteFieldU8::new(2);
|
||||
let transaction_id = UnsignedByteFieldU8::new(3);
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_id)
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_id)
|
||||
.expect("common config creation failed");
|
||||
let pdu_header = PduHeader::new_no_file_data(common_pdu_cfg, 5);
|
||||
let mut buf: [u8; 7] = [0; 7];
|
||||
@ -921,7 +955,7 @@ mod tests {
|
||||
let src_id = UnsignedByteFieldU8::new(1);
|
||||
let dest_id = UnsignedByteFieldU8::new(2);
|
||||
let transaction_id = UnsignedByteFieldU8::new(3);
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_defaults(src_id, dest_id, transaction_id)
|
||||
let common_pdu_cfg = CommonPduConfig::new_with_byte_fields(src_id, dest_id, transaction_id)
|
||||
.expect("common config creation failed");
|
||||
let pdu_header = PduHeader::new_no_file_data(common_pdu_cfg, 5);
|
||||
let mut buf: [u8; 7] = [0; 7];
|
||||
|
Loading…
Reference in New Issue
Block a user