set direction field correctly
All checks were successful
Rust/spacepackets/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2023-10-06 14:54:11 +02:00
parent 5ebf0a5f4c
commit 6c201206cc
Signed by: muellerr
GPG Key ID: FCE0B2BD2195142F
4 changed files with 19 additions and 7 deletions

View File

@ -3,7 +3,7 @@ use crate::cfdp::pdu::{
FileDirectiveType, PduError, PduHeader, FileDirectiveType, PduError, PduHeader,
}; };
use crate::cfdp::tlv::EntityIdTlv; use crate::cfdp::tlv::EntityIdTlv;
use crate::cfdp::{ConditionCode, CrcFlag, LargeFileFlag}; use crate::cfdp::{ConditionCode, CrcFlag, Direction, LargeFileFlag};
use crate::ByteConversionError; use crate::ByteConversionError;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -22,7 +22,9 @@ pub struct EofPdu {
} }
impl EofPdu { impl EofPdu {
pub fn new_no_error(pdu_header: PduHeader, file_checksum: u32, file_size: u64) -> Self { pub fn new_no_error(mut pdu_header: PduHeader, file_checksum: u32, file_size: u64) -> Self {
// Force correct direction flag.
pdu_header.pdu_conf.direction = Direction::TowardsReceiver;
let mut eof_pdu = Self { let mut eof_pdu = Self {
pdu_header, pdu_header,
condition_code: ConditionCode::NoError, condition_code: ConditionCode::NoError,

View File

@ -2,7 +2,7 @@ use crate::cfdp::pdu::{
add_pdu_crc, generic_length_checks_pdu_deserialization, FileDirectiveType, PduError, PduHeader, add_pdu_crc, generic_length_checks_pdu_deserialization, FileDirectiveType, PduError, PduHeader,
}; };
use crate::cfdp::tlv::{EntityIdTlv, Tlv, TlvType, TlvTypeField}; use crate::cfdp::tlv::{EntityIdTlv, Tlv, TlvType, TlvTypeField};
use crate::cfdp::{ConditionCode, CrcFlag, PduType, TlvLvError}; use crate::cfdp::{ConditionCode, CrcFlag, Direction, PduType, TlvLvError};
use crate::ByteConversionError; use crate::ByteConversionError;
use num_enum::{IntoPrimitive, TryFromPrimitive}; use num_enum::{IntoPrimitive, TryFromPrimitive};
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
@ -83,6 +83,8 @@ impl<'fs_responses> FinishedPdu<'fs_responses> {
fault_location: Option<EntityIdTlv>, fault_location: Option<EntityIdTlv>,
) -> Self { ) -> Self {
pdu_header.pdu_type = PduType::FileDirective; pdu_header.pdu_type = PduType::FileDirective;
// Enforce correct direction bit.
pdu_header.pdu_conf.direction = Direction::TowardsSender;
let mut finished_pdu = Self { let mut finished_pdu = Self {
pdu_header, pdu_header,
condition_code, condition_code,
@ -249,7 +251,7 @@ mod tests {
use crate::cfdp::pdu::finished::{DeliveryCode, FileStatus, FinishedPdu}; use crate::cfdp::pdu::finished::{DeliveryCode, FileStatus, FinishedPdu};
use crate::cfdp::pdu::tests::{common_pdu_conf, verify_raw_header}; use crate::cfdp::pdu::tests::{common_pdu_conf, verify_raw_header};
use crate::cfdp::pdu::{FileDirectiveType, PduHeader}; use crate::cfdp::pdu::{FileDirectiveType, PduHeader};
use crate::cfdp::{ConditionCode, CrcFlag, LargeFileFlag}; use crate::cfdp::{ConditionCode, CrcFlag, Direction, LargeFileFlag};
fn generic_finished_pdu( fn generic_finished_pdu(
crc_flag: CrcFlag, crc_flag: CrcFlag,
@ -270,6 +272,10 @@ mod tests {
FileStatus::Retained, FileStatus::Retained,
); );
assert_eq!(finished_pdu.condition_code(), ConditionCode::NoError); assert_eq!(finished_pdu.condition_code(), ConditionCode::NoError);
assert_eq!(
finished_pdu.pdu_header().pdu_conf.direction,
Direction::TowardsSender
);
assert_eq!(finished_pdu.delivery_code(), DeliveryCode::Complete); assert_eq!(finished_pdu.delivery_code(), DeliveryCode::Complete);
assert_eq!(finished_pdu.file_status(), FileStatus::Retained); assert_eq!(finished_pdu.file_status(), FileStatus::Retained);
assert_eq!(finished_pdu.filestore_responses(), None); assert_eq!(finished_pdu.filestore_responses(), None);
@ -290,6 +296,10 @@ mod tests {
let written = written.unwrap(); let written = written.unwrap();
assert_eq!(written, finished_pdu.written_len()); assert_eq!(written, finished_pdu.written_len());
assert_eq!(written, finished_pdu.pdu_header().header_len() + 2); assert_eq!(written, finished_pdu.pdu_header().header_len() + 2);
assert_eq!(
finished_pdu.pdu_header().pdu_conf.direction,
Direction::TowardsSender
);
verify_raw_header(finished_pdu.pdu_header(), &buf); verify_raw_header(finished_pdu.pdu_header(), &buf);
let mut current_idx = finished_pdu.pdu_header().header_len(); let mut current_idx = finished_pdu.pdu_header().header_len();
assert_eq!(buf[current_idx], FileDirectiveType::FinishedPdu as u8); assert_eq!(buf[current_idx], FileDirectiveType::FinishedPdu as u8);

View File

@ -4,7 +4,7 @@ use crate::cfdp::pdu::{
FileDirectiveType, PduError, PduHeader, FileDirectiveType, PduError, PduHeader,
}; };
use crate::cfdp::tlv::Tlv; use crate::cfdp::tlv::Tlv;
use crate::cfdp::{ChecksumType, CrcFlag, LargeFileFlag, PduType}; use crate::cfdp::{ChecksumType, CrcFlag, Direction, LargeFileFlag, PduType};
use crate::ByteConversionError; use crate::ByteConversionError;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use alloc::vec::Vec; use alloc::vec::Vec;
@ -134,6 +134,7 @@ impl<'src_name, 'dest_name, 'opts> MetadataPdu<'src_name, 'dest_name, 'opts> {
options: Option<&'opts [u8]>, options: Option<&'opts [u8]>,
) -> Self { ) -> Self {
pdu_header.pdu_type = PduType::FileDirective; pdu_header.pdu_type = PduType::FileDirective;
pdu_header.pdu_conf.direction = Direction::TowardsReceiver;
let mut pdu = Self { let mut pdu = Self {
pdu_header, pdu_header,
metadata_params, metadata_params,

View File

@ -632,7 +632,6 @@ mod tests {
assert_eq!((buf[0] >> 5) & 0b111, CFDP_VERSION_2); assert_eq!((buf[0] >> 5) & 0b111, CFDP_VERSION_2);
// File directive // File directive
assert_eq!((buf[0] >> 4) & 1, pdu_conf.pdu_type as u8); assert_eq!((buf[0] >> 4) & 1, pdu_conf.pdu_type as u8);
// Towards receiver
assert_eq!((buf[0] >> 3) & 1, pdu_conf.pdu_conf.direction as u8); assert_eq!((buf[0] >> 3) & 1, pdu_conf.pdu_conf.direction as u8);
// Acknowledged // Acknowledged
assert_eq!((buf[0] >> 2) & 1, pdu_conf.pdu_conf.trans_mode as u8); assert_eq!((buf[0] >> 2) & 1, pdu_conf.pdu_conf.trans_mode as u8);
@ -678,7 +677,7 @@ mod tests {
.try_into() .try_into()
.unwrap() .unwrap()
), ),
ubf.value() as u64 ubf.value()
), ),
_ => panic!("invalid entity ID length"), _ => panic!("invalid entity ID length"),
} }