1
#[cfg(feature = "alloc")]
2
use spacepackets::cfdp::tlv::WritableTlv;
3
use spacepackets::{
4
    cfdp::{
5
        pdu::{
6
            file_data::SegmentMetadata,
7
            finished::{DeliveryCode, FileStatus},
8
        },
9
        tlv::msg_to_user::MsgToUserTlv,
10
        ConditionCode,
11
    },
12
    util::UnsignedByteField,
13
};
14

            
15
use super::TransactionId;
16

            
17
#[derive(Debug, Copy, Clone)]
18
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
19
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20
pub struct TransactionFinishedParams {
21
    pub id: TransactionId,
22
    pub condition_code: ConditionCode,
23
    pub delivery_code: DeliveryCode,
24
    pub file_status: FileStatus,
25
}
26

            
27
#[derive(Debug)]
28
pub struct MetadataReceivedParams<'src_file, 'dest_file, 'msgs_to_user> {
29
    pub id: TransactionId,
30
    pub source_id: UnsignedByteField,
31
    pub file_size: u64,
32
    pub src_file_name: &'src_file str,
33
    pub dest_file_name: &'dest_file str,
34
    pub msgs_to_user: &'msgs_to_user [MsgToUserTlv<'msgs_to_user>],
35
}
36

            
37
#[cfg(feature = "alloc")]
38
#[derive(Debug)]
39
pub struct OwnedMetadataRecvdParams {
40
    pub id: TransactionId,
41
    pub source_id: UnsignedByteField,
42
    pub file_size: u64,
43
    pub src_file_name: alloc::string::String,
44
    pub dest_file_name: alloc::string::String,
45
    pub msgs_to_user: alloc::vec::Vec<alloc::vec::Vec<u8>>,
46
}
47

            
48
#[cfg(feature = "alloc")]
49
impl From<MetadataReceivedParams<'_, '_, '_>> for OwnedMetadataRecvdParams {
50
    fn from(value: MetadataReceivedParams) -> Self {
51
        Self::from(&value)
52
    }
53
}
54

            
55
#[cfg(feature = "alloc")]
56
impl From<&MetadataReceivedParams<'_, '_, '_>> for OwnedMetadataRecvdParams {
57
34
    fn from(value: &MetadataReceivedParams) -> Self {
58
34
        Self {
59
34
            id: value.id,
60
34
            source_id: value.source_id,
61
34
            file_size: value.file_size,
62
34
            src_file_name: value.src_file_name.into(),
63
34
            dest_file_name: value.dest_file_name.into(),
64
34
            msgs_to_user: value.msgs_to_user.iter().map(|tlv| tlv.to_vec()).collect(),
65
34
        }
66
34
    }
67
}
68

            
69
#[derive(Debug)]
70
pub struct FileSegmentRecvdParams<'seg_meta> {
71
    pub id: TransactionId,
72
    pub offset: u64,
73
    pub length: usize,
74
    pub segment_metadata: Option<&'seg_meta SegmentMetadata<'seg_meta>>,
75
}
76

            
77
pub trait CfdpUser {
78
    fn transaction_indication(&mut self, id: &TransactionId);
79
    fn eof_sent_indication(&mut self, id: &TransactionId);
80
    fn transaction_finished_indication(&mut self, finished_params: &TransactionFinishedParams);
81
    fn metadata_recvd_indication(&mut self, md_recvd_params: &MetadataReceivedParams);
82
    fn file_segment_recvd_indication(&mut self, segment_recvd_params: &FileSegmentRecvdParams);
83
    // TODO: The standard does not strictly specify how the report information looks..
84
    fn report_indication(&mut self, id: &TransactionId);
85
    fn suspended_indication(&mut self, id: &TransactionId, condition_code: ConditionCode);
86
    fn resumed_indication(&mut self, id: &TransactionId, progress: u64);
87
    fn fault_indication(
88
        &mut self,
89
        id: &TransactionId,
90
        condition_code: ConditionCode,
91
        progress: u64,
92
    );
93
    fn abandoned_indication(
94
        &mut self,
95
        id: &TransactionId,
96
        condition_code: ConditionCode,
97
        progress: u64,
98
    );
99
    fn eof_recvd_indication(&mut self, id: &TransactionId);
100
}