Skip to content

Commit

Permalink
some more API improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Aug 22, 2024
1 parent 6aae8cb commit 563e1a4
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 100 deletions.
45 changes: 26 additions & 19 deletions src/dest.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{user::TransactionFinishedParams, GenericSendError};
use crate::{user::TransactionFinishedParams, DummyPduProvider, GenericSendError, PduProvider};
use core::str::{from_utf8, Utf8Error};
use std::path::{Path, PathBuf};

use super::{
filestore::{FilestoreError, NativeFilestore, VirtualFilestore},
user::{CfdpUser, FileSegmentRecvdParams, MetadataReceivedParams},
CheckTimerProviderCreator, CountdownProvider, EntityType, LocalEntityConfig, PacketInfo,
PacketTarget, PduSendProvider, RemoteEntityConfig, RemoteEntityConfigProvider, State,
StdCheckTimer, StdCheckTimerCreator, StdRemoteEntityConfigProvider, TimerContext,
TransactionId, UserFaultHookProvider,
CheckTimerProviderCreator, CountdownProvider, EntityType, LocalEntityConfig, PacketTarget,
PduSendProvider, RemoteEntityConfig, RemoteEntityConfigProvider, State, StdCheckTimer,
StdCheckTimerCreator, StdRemoteEntityConfigProvider, TimerContext, TransactionId,
UserFaultHookProvider,
};
use smallvec::SmallVec;
use spacepackets::{
Expand Down Expand Up @@ -290,6 +290,13 @@ impl<
}
}

pub fn state_machine_no_packet(
&mut self,
cfdp_user: &mut impl CfdpUser,
) -> Result<u32, DestError> {
self.state_machine(cfdp_user, None::<&DummyPduProvider>)
}

/// This is the core function to drive the destination handler. It is also used to insert
/// packets into the destination handler.
///
Expand All @@ -301,7 +308,7 @@ impl<
pub fn state_machine(
&mut self,
cfdp_user: &mut impl CfdpUser,
packet_to_insert: Option<&PacketInfo>,
packet_to_insert: Option<&impl PduProvider>,
) -> Result<u32, DestError> {
if let Some(packet) = packet_to_insert {
self.insert_packet(cfdp_user, packet)?;
Expand Down Expand Up @@ -335,28 +342,28 @@ impl<
fn insert_packet(
&mut self,
cfdp_user: &mut impl CfdpUser,
packet_info: &PacketInfo,
packet_to_insert: &impl PduProvider,
) -> Result<(), DestError> {
if packet_info.target() != PacketTarget::DestEntity {
if packet_to_insert.packet_target()? != PacketTarget::DestEntity {
// Unwrap is okay here, a PacketInfo for a file data PDU should always have the
// destination as the target.
return Err(DestError::CantProcessPacketType {
pdu_type: packet_info.pdu_type(),
directive_type: packet_info.pdu_directive(),
pdu_type: packet_to_insert.pdu_type(),
directive_type: packet_to_insert.file_directive_type(),
});
}
match packet_info.pdu_type {
match packet_to_insert.pdu_type() {
PduType::FileDirective => {
if packet_info.pdu_directive.is_none() {
if packet_to_insert.file_directive_type().is_none() {
return Err(DestError::DirectiveFieldEmpty);
}
self.handle_file_directive(
cfdp_user,
packet_info.pdu_directive.unwrap(),
packet_info.raw_packet,
packet_to_insert.file_directive_type().unwrap(),
packet_to_insert.pdu(),
)
}
PduType::FileData => self.handle_file_data(cfdp_user, packet_info.raw_packet),
PduType::FileData => self.handle_file_data(cfdp_user, packet_to_insert.pdu()),
}
}

Expand Down Expand Up @@ -863,7 +870,7 @@ mod tests {
basic_remote_cfg_table, SentPdu, TestCfdpSender, TestCfdpUser, TestFaultHandler,
LOCAL_ID,
},
CheckTimerProviderCreator, CountdownProvider, FaultHandler, IndicationConfig,
CheckTimerProviderCreator, CountdownProvider, FaultHandler, IndicationConfig, PacketInfo,
StdRemoteEntityConfigProvider, CRC_32,
};

Expand Down Expand Up @@ -1297,7 +1304,7 @@ mod tests {
testbench.set_check_timer_expired();
testbench
.handler
.state_machine(&mut test_user, None)
.state_machine_no_packet(&mut test_user)
.expect("fsm failure");
let fault_handler = testbench.handler.local_cfg.fault_handler.user_hook.borrow();

Expand Down Expand Up @@ -1339,7 +1346,7 @@ mod tests {
testbench.set_check_timer_expired();
testbench
.handler
.state_machine(&mut test_user, None)
.state_machine_no_packet(&mut test_user)
.expect("fsm error");
testbench.state_check(
State::Busy,
Expand All @@ -1348,7 +1355,7 @@ mod tests {
testbench.set_check_timer_expired();
testbench
.handler
.state_machine(&mut test_user, None)
.state_machine_no_packet(&mut test_user)
.expect("fsm error");
testbench.state_check(State::Idle, TransactionStep::Idle);

Expand Down
Loading

0 comments on commit 563e1a4

Please sign in to comment.