this should get the job done
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
Robin Müller 2023-08-16 19:28:28 +02:00
parent a415cd8f6c
commit eb85741684
Signed by: muellerr
GPG Key ID: A649FB78196E3849
3 changed files with 46 additions and 8 deletions

View File

@ -17,6 +17,9 @@ delegate = ">=0.8, <0.11"
paste = "1" paste = "1"
embed-doc-image = "0.1" embed-doc-image = "0.1"
[dependencies.smallvec]
version = "1"
[dependencies.num_enum] [dependencies.num_enum]
version = "0.6" version = "0.6"
default-features = false default-features = false
@ -67,8 +70,9 @@ optional = true
[dependencies.spacepackets] [dependencies.spacepackets]
version = "0.7.0-beta.0" version = "0.7.0-beta.0"
# path = "../../spacepackets" # path = "../../spacepackets"
# git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git" git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git"
# rev = "041959e546e6e72b24eb50986c425a924015e3f4" # rev = ""
branch = "update-lv-tlv"
default-features = false default-features = false
[dev-dependencies] [dev-dependencies]

View File

@ -9,6 +9,7 @@ use super::{
user::{CfdpUser, MetadataReceivedParams}, user::{CfdpUser, MetadataReceivedParams},
State, TransactionId, TransactionStep, CRC_32, State, TransactionId, TransactionStep, CRC_32,
}; };
use smallvec::SmallVec;
use spacepackets::{ use spacepackets::{
cfdp::{ cfdp::{
pdu::{ pdu::{
@ -18,7 +19,7 @@ use spacepackets::{
metadata::{MetadataGenericParams, MetadataPdu}, metadata::{MetadataGenericParams, MetadataPdu},
CommonPduConfig, FileDirectiveType, PduError, PduHeader, CommonPduConfig, FileDirectiveType, PduError, PduHeader,
}, },
tlv::EntityIdTlv, tlv::{msg_to_user::MsgToUserTlv, EntityIdTlv, TlvType},
ConditionCode, PduType, ConditionCode, PduType,
}, },
util::UnsignedByteField, util::UnsignedByteField,
@ -58,7 +59,10 @@ struct TransactionParams {
condition_code: ConditionCode, condition_code: ConditionCode,
delivery_code: DeliveryCode, delivery_code: DeliveryCode,
file_status: FileStatus, file_status: FileStatus,
//msgs_to_user: Vec<MsgToUserTlv<'static>>,
cksum_buf: [u8; 1024], cksum_buf: [u8; 1024],
msgs_to_user_size: usize,
msgs_to_user_buf: [u8; 1024],
} }
impl Default for FileProperties { impl Default for FileProperties {
@ -84,6 +88,8 @@ impl Default for TransactionParams {
delivery_code: DeliveryCode::Incomplete, delivery_code: DeliveryCode::Incomplete,
file_status: FileStatus::Unreported, file_status: FileStatus::Unreported,
cksum_buf: [0; 1024], cksum_buf: [0; 1024],
msgs_to_user_size: 0,
msgs_to_user_buf: [0; 1024],
} }
} }
} }
@ -242,16 +248,29 @@ impl DestinationHandler {
return Err(DestError::EmptySrcFileField); return Err(DestError::EmptySrcFileField);
} }
self.transaction_params.file_properties.src_file_name[..src_name.len_value()] self.transaction_params.file_properties.src_file_name[..src_name.len_value()]
.copy_from_slice(src_name.value().unwrap()); .copy_from_slice(src_name.value());
self.transaction_params.file_properties.src_file_name_len = src_name.len_value(); self.transaction_params.file_properties.src_file_name_len = src_name.len_value();
let dest_name = metadata_pdu.dest_file_name(); let dest_name = metadata_pdu.dest_file_name();
if dest_name.is_empty() { if dest_name.is_empty() {
return Err(DestError::EmptyDestFileField); return Err(DestError::EmptyDestFileField);
} }
self.transaction_params.file_properties.dest_file_name[..dest_name.len_value()] self.transaction_params.file_properties.dest_file_name[..dest_name.len_value()]
.copy_from_slice(dest_name.value().unwrap()); .copy_from_slice(dest_name.value());
self.transaction_params.file_properties.dest_file_name_len = dest_name.len_value(); self.transaction_params.file_properties.dest_file_name_len = dest_name.len_value();
self.transaction_params.pdu_conf = *metadata_pdu.pdu_header().common_pdu_conf(); self.transaction_params.pdu_conf = *metadata_pdu.pdu_header().common_pdu_conf();
self.transaction_params.msgs_to_user_size = 0;
if metadata_pdu.options().is_some() {
for option_tlv in metadata_pdu.options_iter().unwrap() {
if option_tlv.is_standard_tlv()
&& option_tlv.tlv_type().unwrap() == TlvType::MsgToUser
{
self.transaction_params
.msgs_to_user_buf
.copy_from_slice(option_tlv.raw_data().unwrap());
self.transaction_params.msgs_to_user_size += option_tlv.len_full();
}
}
}
Ok(()) Ok(())
} }
@ -360,13 +379,27 @@ impl DestinationHandler {
&self.transaction_params.file_properties.src_file_name &self.transaction_params.file_properties.src_file_name
[0..self.transaction_params.file_properties.src_file_name_len], [0..self.transaction_params.file_properties.src_file_name_len],
)?; )?;
let mut msgs_to_user = SmallVec::<[MsgToUserTlv<'_>; 16]>::new();
let mut num_msgs_to_user = 0;
if self.transaction_params.msgs_to_user_size > 0 {
let mut index = 0;
while index < self.transaction_params.msgs_to_user_size {
// This should never panic as the validity of the options was checked beforehand.
let msgs_to_user_tlv =
MsgToUserTlv::from_bytes(&self.transaction_params.msgs_to_user_buf[index..])
.expect("message to user creation failed unexpectedly");
msgs_to_user.push(msgs_to_user_tlv);
index += msgs_to_user_tlv.len_full();
num_msgs_to_user += 1;
}
}
let metadata_recvd_params = MetadataReceivedParams { let metadata_recvd_params = MetadataReceivedParams {
id, id,
source_id, source_id,
file_size: self.transaction_params.metadata_params.file_size, file_size: self.transaction_params.metadata_params.file_size,
src_file_name: src_name, src_file_name: src_name,
dest_file_name: dest_name, dest_file_name: dest_name,
msgs_to_user: &[], msgs_to_user: &msgs_to_user[..num_msgs_to_user],
}; };
self.transaction_params.transaction_id = Some(id); self.transaction_params.transaction_id = Some(id);
cfdp_user.metadata_recvd_indication(&metadata_recvd_params); cfdp_user.metadata_recvd_indication(&metadata_recvd_params);
@ -516,6 +549,7 @@ mod tests {
let test_user = TestCfdpUser::default(); let test_user = TestCfdpUser::default();
let mut dest_handler = DestinationHandler::new(LOCAL_ID); let mut dest_handler = DestinationHandler::new(LOCAL_ID);
init_check(&dest_handler); init_check(&dest_handler);
// TODO: Create Metadata PDU and EOF PDU for empty file transfer. // TODO: Create Metadata PDU and EOF PDU for empty file transfer.
//dest_handler.insert_packet(pdu_type, pdu_directive, raw_packet) //dest_handler.insert_packet(pdu_type, pdu_directive, raw_packet)
} }

View File

@ -4,6 +4,7 @@ use spacepackets::{
file_data::RecordContinuationState, file_data::RecordContinuationState,
finished::{DeliveryCode, FileStatus}, finished::{DeliveryCode, FileStatus},
}, },
tlv::msg_to_user::MsgToUserTlv,
ConditionCode, ConditionCode,
}, },
util::UnsignedByteField, util::UnsignedByteField,
@ -26,8 +27,7 @@ pub struct MetadataReceivedParams<'src_file, 'dest_file, 'msgs_to_user> {
pub file_size: u64, pub file_size: u64,
pub src_file_name: &'src_file str, pub src_file_name: &'src_file str,
pub dest_file_name: &'dest_file str, pub dest_file_name: &'dest_file str,
// TODO: This is pretty low-level. Is there a better way to do this? pub msgs_to_user: &'msgs_to_user [MsgToUserTlv<'msgs_to_user>],
pub msgs_to_user: &'msgs_to_user [u8],
} }
#[derive(Debug)] #[derive(Debug)]