Skip to content

Commit

Permalink
set direction field correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Oct 6, 2023
1 parent 5ebf0a5 commit 6c20120
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/cfdp/pdu/eof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::cfdp::pdu::{
FileDirectiveType, PduError, PduHeader,
};
use crate::cfdp::tlv::EntityIdTlv;
use crate::cfdp::{ConditionCode, CrcFlag, LargeFileFlag};
use crate::cfdp::{ConditionCode, CrcFlag, Direction, LargeFileFlag};
use crate::ByteConversionError;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand All @@ -22,7 +22,9 @@ pub struct 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 {
pdu_header,
condition_code: ConditionCode::NoError,
Expand Down
14 changes: 12 additions & 2 deletions src/cfdp/pdu/finished.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::cfdp::pdu::{
add_pdu_crc, generic_length_checks_pdu_deserialization, FileDirectiveType, PduError, PduHeader,
};
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 num_enum::{IntoPrimitive, TryFromPrimitive};
#[cfg(feature = "serde")]
Expand Down Expand Up @@ -83,6 +83,8 @@ impl<'fs_responses> FinishedPdu<'fs_responses> {
fault_location: Option<EntityIdTlv>,
) -> Self {
pdu_header.pdu_type = PduType::FileDirective;
// Enforce correct direction bit.
pdu_header.pdu_conf.direction = Direction::TowardsSender;
let mut finished_pdu = Self {
pdu_header,
condition_code,
Expand Down Expand Up @@ -249,7 +251,7 @@ mod tests {
use crate::cfdp::pdu::finished::{DeliveryCode, FileStatus, FinishedPdu};
use crate::cfdp::pdu::tests::{common_pdu_conf, verify_raw_header};
use crate::cfdp::pdu::{FileDirectiveType, PduHeader};
use crate::cfdp::{ConditionCode, CrcFlag, LargeFileFlag};
use crate::cfdp::{ConditionCode, CrcFlag, Direction, LargeFileFlag};

fn generic_finished_pdu(
crc_flag: CrcFlag,
Expand All @@ -270,6 +272,10 @@ mod tests {
FileStatus::Retained,
);
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.file_status(), FileStatus::Retained);
assert_eq!(finished_pdu.filestore_responses(), None);
Expand All @@ -290,6 +296,10 @@ mod tests {
let written = written.unwrap();
assert_eq!(written, finished_pdu.written_len());
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);
let mut current_idx = finished_pdu.pdu_header().header_len();
assert_eq!(buf[current_idx], FileDirectiveType::FinishedPdu as u8);
Expand Down
3 changes: 2 additions & 1 deletion src/cfdp/pdu/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::cfdp::pdu::{
FileDirectiveType, PduError, PduHeader,
};
use crate::cfdp::tlv::Tlv;
use crate::cfdp::{ChecksumType, CrcFlag, LargeFileFlag, PduType};
use crate::cfdp::{ChecksumType, CrcFlag, Direction, LargeFileFlag, PduType};
use crate::ByteConversionError;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
Expand Down Expand Up @@ -134,6 +134,7 @@ impl<'src_name, 'dest_name, 'opts> MetadataPdu<'src_name, 'dest_name, 'opts> {
options: Option<&'opts [u8]>,
) -> Self {
pdu_header.pdu_type = PduType::FileDirective;
pdu_header.pdu_conf.direction = Direction::TowardsReceiver;
let mut pdu = Self {
pdu_header,
metadata_params,
Expand Down
3 changes: 1 addition & 2 deletions src/cfdp/pdu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ mod tests {
assert_eq!((buf[0] >> 5) & 0b111, CFDP_VERSION_2);
// File directive
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);
// Acknowledged
assert_eq!((buf[0] >> 2) & 1, pdu_conf.pdu_conf.trans_mode as u8);
Expand Down Expand Up @@ -678,7 +677,7 @@ mod tests {
.try_into()
.unwrap()
),
ubf.value() as u64
ubf.value()
),
_ => panic!("invalid entity ID length"),
}
Expand Down

0 comments on commit 6c20120

Please sign in to comment.