continue dest handler

This commit is contained in:
Robin Müller 2023-07-26 22:27:02 +02:00
parent 6c87ae0b67
commit 9bbd2cdad1
Signed by: muellerr
GPG Key ID: A649FB78196E3849
3 changed files with 60 additions and 10 deletions

View File

@ -64,7 +64,7 @@ optional = true
# version = "0.6" # version = "0.6"
# 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 = "62df510147b" rev = "041959e546e6e72b24eb50986c425a924015e3f4"
default-features = false default-features = false
[dev-dependencies] [dev-dependencies]

View File

@ -1,13 +1,29 @@
use super::{State, TransactionStep}; use super::{State, TransactionStep};
use spacepackets::cfdp::{ use spacepackets::cfdp::{
pdu::{CommonPduConfig, FileDirectiveType}, pdu::{metadata::MetadataPdu, CommonPduConfig, FileDirectiveType, PduError},
PduType, PduType,
}; };
pub struct DestinationHandler { pub struct DestinationHandler {
step: TransactionStep, step: TransactionStep,
state: State, state: State,
//pdu_conf: CommonPduConfig, pdu_conf: CommonPduConfig,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum DestError {
/// File directive expected, but none specified
DirectiveExpected,
CantProcessPacketType(FileDirectiveType),
// Received new metadata PDU while being already being busy with a file transfer.
RecvdMetadataButIsBusy,
Pdu(PduError),
}
impl From<PduError> for DestError {
fn from(value: PduError) -> Self {
Self::Pdu(value)
}
} }
impl DestinationHandler { impl DestinationHandler {
@ -15,7 +31,7 @@ impl DestinationHandler {
Self { Self {
step: TransactionStep::Idle, step: TransactionStep::Idle,
state: State::Idle, state: State::Idle,
//pdu_conf: CommonPduConfig::new_with_defaults(), pdu_conf: CommonPduConfig::new_with_defaults(),
} }
} }
@ -24,11 +40,11 @@ impl DestinationHandler {
pdu_type: PduType, pdu_type: PduType,
pdu_directive: Option<FileDirectiveType>, pdu_directive: Option<FileDirectiveType>,
raw_packet: &[u8], raw_packet: &[u8],
) -> Result<(), ()> { ) -> Result<(), DestError> {
match pdu_type { match pdu_type {
PduType::FileDirective => { PduType::FileDirective => {
if pdu_directive.is_none() { if pdu_directive.is_none() {
return Err(()); return Err(DestError::DirectiveExpected);
} }
self.handle_file_directive(pdu_directive.unwrap(), raw_packet) self.handle_file_directive(pdu_directive.unwrap(), raw_packet)
} }
@ -36,7 +52,7 @@ impl DestinationHandler {
} }
} }
pub fn handle_file_data(&mut self, raw_packet: &[u8]) -> Result<(), ()> { pub fn handle_file_data(&mut self, raw_packet: &[u8]) -> Result<(), DestError> {
Ok(()) Ok(())
} }
@ -44,7 +60,16 @@ impl DestinationHandler {
&mut self, &mut self,
pdu_directive: FileDirectiveType, pdu_directive: FileDirectiveType,
raw_packet: &[u8], raw_packet: &[u8],
) -> Result<(), ()> { ) -> Result<(), DestError> {
match pdu_directive {
FileDirectiveType::EofPdu => todo!(),
FileDirectiveType::FinishedPdu => todo!(),
FileDirectiveType::AckPdu => todo!(),
FileDirectiveType::MetadataPdu => self.handle_metadata_pdu(raw_packet),
FileDirectiveType::NakPdu => todo!(),
FileDirectiveType::PromptPdu => todo!(),
FileDirectiveType::KeepAlivePdu => todo!(),
};
Ok(()) Ok(())
} }
@ -56,6 +81,19 @@ impl DestinationHandler {
} }
} }
pub fn handle_metadata_pdu(&mut self, raw_packet: &[u8]) -> Result<(), DestError> {
if self.state != State::Idle {
return Err(DestError::RecvdMetadataButIsBusy);
}
let metadata_pdu = MetadataPdu::from_bytes(raw_packet)?;
Ok(())
}
pub fn handle_eof_pdu(&mut self, raw_packet: &[u8]) -> Result<(), DestError> {
Ok(())
}
fn fsm_nacked(&self) { fn fsm_nacked(&self) {
match self.step { match self.step {
TransactionStep::Idle => { TransactionStep::Idle => {
@ -80,3 +118,15 @@ impl DestinationHandler {
self.state self.state
} }
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_basic() {
let dest_handler = DestinationHandler::new();
assert_eq!(dest_handler.state(), State::Idle);
assert_eq!(dest_handler.step(), TransactionStep::Idle);
}
}

View File

@ -1,6 +1,6 @@
pub mod dest; pub mod dest;
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum TransactionStep { pub enum TransactionStep {
Idle = 0, Idle = 0,
TransactionStart = 1, TransactionStart = 1,
@ -10,7 +10,7 @@ pub enum TransactionStep {
SendingFinishedPdu = 5, SendingFinishedPdu = 5,
} }
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum State { pub enum State {
Idle = 0, Idle = 0,
BusyClass1Nacked = 2, BusyClass1Nacked = 2,