From beb80b2188fa191afe29769457f7560eac963695 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 11 Aug 2023 12:44:24 +0200 Subject: [PATCH] start adding CFDP user --- satrs-core/src/cfdp/mod.rs | 22 +++++++++++++++++ satrs-core/src/cfdp/user.rs | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 satrs-core/src/cfdp/user.rs diff --git a/satrs-core/src/cfdp/mod.rs b/satrs-core/src/cfdp/mod.rs index 2fba15e..527ca05 100644 --- a/satrs-core/src/cfdp/mod.rs +++ b/satrs-core/src/cfdp/mod.rs @@ -1,6 +1,28 @@ use crc::{Crc, CRC_32_CKSUM}; +use spacepackets::util::UnsignedByteField; pub mod dest; +pub mod user; + +#[derive(Debug, PartialEq, Eq, Copy, Clone)] +pub struct TransactionId { + source_id: UnsignedByteField, + seq_num: UnsignedByteField, +} + +impl TransactionId { + pub fn new(source_id: UnsignedByteField, seq_num: UnsignedByteField) -> Self { + Self { source_id, seq_num } + } + + pub fn source_id(&self) -> &UnsignedByteField { + &self.source_id + } + + pub fn seq_num(&self) -> &UnsignedByteField { + &self.seq_num + } +} #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum TransactionStep { diff --git a/satrs-core/src/cfdp/user.rs b/satrs-core/src/cfdp/user.rs new file mode 100644 index 0000000..354a95a --- /dev/null +++ b/satrs-core/src/cfdp/user.rs @@ -0,0 +1,48 @@ +use spacepackets::{ + cfdp::{ + pdu::{ + file_data::RecordContinuationState, + finished::{DeliveryCode, FileStatus}, + }, + ConditionCode, + }, + util::UnsignedByteField, +}; + +use super::TransactionId; + +#[derive(Debug, Copy, Clone)] +pub struct TransactionFinishedParams { + pub id: TransactionId, + pub condition_code: ConditionCode, + pub delivery_code: DeliveryCode, + pub file_status: FileStatus, +} + +#[derive(Debug)] +pub struct MetadataReceivedParams<'src_file, 'dest_file, 'msgs_to_user> { + pub id: TransactionId, + pub source_id: UnsignedByteField, + pub file_size: u64, + pub src_file_name: &'src_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 [u8], +} + +#[derive(Debug)] +pub struct FileSegmentRecvdParams<'seg_meta> { + pub id: TransactionId, + pub offset: u64, + pub length: usize, + pub rec_cont_state: Option, + pub segment_metadata: Option<&'seg_meta [u8]>, +} + +pub trait CfdpUser { + fn transaction_indication(&mut self, id: &TransactionId); + fn eof_sent_indication(&mut self, id: &TransactionId); + fn transaction_finished_indication(&mut self, finished_params: &TransactionFinishedParams); + fn metadata_recvd_indication(&mut self, md_recvd_params: &MetadataReceivedParams); + fn file_segment_recvd_indication(&mut self, segment_recvd_params: &FileSegmentRecvdParams); +}