leodos_protocols/transport/cfdp/pdu/file_directive/
mod.rs1use zerocopy::FromBytes;
2use zerocopy::Immutable;
3use zerocopy::IntoBytes;
4use zerocopy::KnownLayout;
5use zerocopy::Unaligned;
6
7use crate::transport::cfdp::CfdpError;
8
9pub mod ack;
11pub mod eof;
13pub mod finished;
15pub mod keepalive;
17pub mod metadata;
19pub mod nak;
21pub mod prompt;
23
24#[repr(C)]
37#[derive(FromBytes, IntoBytes, Unaligned, KnownLayout, Immutable)]
38pub struct FileDirectivePdu {
39 directive_code: u8,
41 rest: [u8],
43}
44
45#[repr(u8)]
47#[derive(Debug, PartialEq, Eq, Clone, Copy)]
48pub enum DirectiveCode {
49 Eof = 0x04,
51 Finished = 0x05,
53 Ack = 0x06,
55 Metadata = 0x07,
57 Nak = 0x08,
59 Prompt = 0x09,
61 KeepAlive = 0x0C,
63}
64
65impl DirectiveCode {
66 pub fn size() -> usize {
68 1
69 }
70}
71
72impl TryFrom<u8> for DirectiveCode {
73 type Error = CfdpError;
74 fn try_from(val: u8) -> Result<Self, Self::Error> {
75 let val = match val {
76 0x04 => DirectiveCode::Eof,
77 0x05 => DirectiveCode::Finished,
78 0x06 => DirectiveCode::Ack,
79 0x07 => DirectiveCode::Metadata,
80 0x08 => DirectiveCode::Nak,
81 0x09 => DirectiveCode::Prompt,
82 0x0C => DirectiveCode::KeepAlive,
83 _ => return Err(CfdpError::Custom("Invalid DirectiveCode value")),
84 };
85 Ok(val)
86 }
87}
88
89impl FileDirectivePdu {
90 pub fn directive_code(&self) -> Result<DirectiveCode, CfdpError> {
92 self.directive_code.try_into()
93 }
94
95 pub fn set_directive_code(&mut self, code: DirectiveCode) {
97 self.directive_code = code as u8;
98 }
99
100 pub fn rest(&self) -> &[u8] {
102 &self.rest
103 }
104}
105
106#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
108#[repr(u8)]
109pub enum ConditionCode {
110 #[default]
112 NoError = 0,
113 AckLimitReached = 1,
115 KeepAliveLimitReached = 2,
117 InvalidTransmissionMode = 3,
119 FilestoreRejection = 4,
121 FileChecksumFailure = 5,
123 FileSizeError = 6,
125 NakLimitReached = 7,
127 InactivityDetected = 8,
129 InvalidFileStructure = 9,
131 CheckLimitReached = 10,
133 UnsupportedChecksumType = 11,
135 SuspendReceived = 14,
137 CancelReceived = 15,
139}
140
141impl TryFrom<u8> for ConditionCode {
142 type Error = CfdpError;
143 fn try_from(val: u8) -> Result<Self, Self::Error> {
144 let val = match val {
145 0 => ConditionCode::NoError,
146 1 => ConditionCode::AckLimitReached,
147 2 => ConditionCode::KeepAliveLimitReached,
148 3 => ConditionCode::InvalidTransmissionMode,
149 4 => ConditionCode::FilestoreRejection,
150 5 => ConditionCode::FileChecksumFailure,
151 6 => ConditionCode::FileSizeError,
152 7 => ConditionCode::NakLimitReached,
153 8 => ConditionCode::InactivityDetected,
154 9 => ConditionCode::InvalidFileStructure,
155 10 => ConditionCode::CheckLimitReached,
156 11 => ConditionCode::UnsupportedChecksumType,
157 14 => ConditionCode::SuspendReceived,
158 15 => ConditionCode::CancelReceived,
159 _ => return Err(CfdpError::Custom("Invalid ConditionCode value")),
160 };
161 Ok(val)
162 }
163}