From 6c87ae0b67b6c9471682f9226226824255121324 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 25 Jul 2023 00:43:45 +0200 Subject: [PATCH] continue dest handler --- satrs-core/src/cfdp/dest.rs | 41 +++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/satrs-core/src/cfdp/dest.rs b/satrs-core/src/cfdp/dest.rs index 026ed95..a58a2e3 100644 --- a/satrs-core/src/cfdp/dest.rs +++ b/satrs-core/src/cfdp/dest.rs @@ -1,12 +1,24 @@ use super::{State, TransactionStep}; -use spacepackets::cfdp::{pdu::FileDirectiveType, PduType}; +use spacepackets::cfdp::{ + pdu::{CommonPduConfig, FileDirectiveType}, + PduType, +}; pub struct DestinationHandler { step: TransactionStep, state: State, + //pdu_conf: CommonPduConfig, } impl DestinationHandler { + pub fn new() -> Self { + Self { + step: TransactionStep::Idle, + state: State::Idle, + //pdu_conf: CommonPduConfig::new_with_defaults(), + } + } + pub fn insert_packet( &mut self, pdu_type: PduType, @@ -27,6 +39,7 @@ impl DestinationHandler { pub fn handle_file_data(&mut self, raw_packet: &[u8]) -> Result<(), ()> { Ok(()) } + pub fn handle_file_directive( &mut self, pdu_directive: FileDirectiveType, @@ -38,8 +51,32 @@ impl DestinationHandler { pub fn state_machine(&mut self) { match self.state { State::Idle => todo!(), - State::BusyClass1Nacked => todo!(), + State::BusyClass1Nacked => self.fsm_nacked(), State::BusyClass2Acked => todo!(), } } + + fn fsm_nacked(&self) { + match self.step { + TransactionStep::Idle => { + // TODO: Should not happen. Determine what to do later + } + TransactionStep::TransactionStart => {} + TransactionStep::ReceivingFileDataPdus => todo!(), + TransactionStep::SendingAckPdu => todo!(), + TransactionStep::TransferCompletion => todo!(), + TransactionStep::SendingFinishedPdu => todo!(), + } + } + + /// Get the step, which denotes the exact step of a pending CFDP transaction when applicable. + pub fn step(&self) -> TransactionStep { + self.step + } + + /// Get the step, which denotes whether the CFDP handler is active, and which CFDP class + /// is used if it is active. + pub fn state(&self) -> State { + self.state + } }