From 0bbada90ef100a2c540f21c595da4ad8225722a2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Apr 2024 12:57:32 +0200 Subject: [PATCH] improve example structure --- satrs-example/src/interface/mod.rs | 3 ++ satrs-example/src/{ => interface}/tcp.rs | 2 +- satrs-example/src/{ => interface}/udp.rs | 0 satrs-example/src/main.rs | 15 +++----- satrs-example/src/queue.rs | 45 ---------------------- satrs-example/src/{ => tmtc}/ccsds.rs | 0 satrs-example/src/{tmtc.rs => tmtc/mod.rs} | 3 ++ satrs-example/src/{ => tmtc}/tm_funnel.rs | 2 +- 8 files changed, 14 insertions(+), 56 deletions(-) create mode 100644 satrs-example/src/interface/mod.rs rename satrs-example/src/{ => interface}/tcp.rs (99%) rename satrs-example/src/{ => interface}/udp.rs (100%) delete mode 100644 satrs-example/src/queue.rs rename satrs-example/src/{ => tmtc}/ccsds.rs (100%) rename satrs-example/src/{tmtc.rs => tmtc/mod.rs} (99%) rename satrs-example/src/{ => tmtc}/tm_funnel.rs (99%) diff --git a/satrs-example/src/interface/mod.rs b/satrs-example/src/interface/mod.rs new file mode 100644 index 0000000..d10d73f --- /dev/null +++ b/satrs-example/src/interface/mod.rs @@ -0,0 +1,3 @@ +//! This module contains all component related to the direct interface of the example. +pub mod tcp; +pub mod udp; diff --git a/satrs-example/src/tcp.rs b/satrs-example/src/interface/tcp.rs similarity index 99% rename from satrs-example/src/tcp.rs rename to satrs-example/src/interface/tcp.rs index 7db4c2c..b12d4b4 100644 --- a/satrs-example/src/tcp.rs +++ b/satrs-example/src/interface/tcp.rs @@ -11,7 +11,7 @@ use satrs::{ tmtc::{CcsdsDistributor, CcsdsError, ReceivesCcsdsTc, TmPacketSourceCore}, }; -use crate::ccsds::CcsdsReceiver; +use crate::tmtc::ccsds::CcsdsReceiver; #[derive(Default)] pub struct ConnectionFinishedHandler {} diff --git a/satrs-example/src/udp.rs b/satrs-example/src/interface/udp.rs similarity index 100% rename from satrs-example/src/udp.rs rename to satrs-example/src/interface/udp.rs diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index 8e6ee8f..2ecc23a 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -1,18 +1,16 @@ mod acs; -mod ccsds; mod events; mod hk; +mod interface; mod logger; mod pus; mod requests; -mod tcp; -mod tm_funnel; mod tmtc; -mod udp; use crate::events::EventHandler; +use crate::interface::udp::DynamicUdpTmHandler; use crate::pus::stack::PusStack; -use crate::tm_funnel::{TmFunnelDynamic, TmFunnelStatic}; +use crate::tmtc::tm_funnel::{TmFunnelDynamic, TmFunnelStatic}; use log::info; use pus::test::create_test_service_dynamic; use satrs::hal::std::tcp_server::ServerConfig; @@ -25,10 +23,10 @@ use satrs_example::config::tasks::{ }; use satrs_example::config::{OBSW_SERVER_ADDR, PACKET_ID_VALIDATOR, SERVER_PORT}; use tmtc::PusTcSourceProviderDynamic; -use udp::DynamicUdpTmHandler; use crate::acs::mgm::{MgmHandlerLis3Mdl, MpscModeLeafInterface, SpiDummyInterface}; -use crate::ccsds::CcsdsReceiver; +use crate::interface::tcp::{SyncTcpTmSource, TcpTask}; +use crate::interface::udp::{StaticUdpTmHandler, UdpTmtcServer}; use crate::logger::setup_logger; use crate::pus::action::{create_action_service_dynamic, create_action_service_static}; use crate::pus::event::{create_event_service_dynamic, create_event_service_static}; @@ -38,11 +36,10 @@ use crate::pus::scheduler::{create_scheduler_service_dynamic, create_scheduler_s use crate::pus::test::create_test_service_static; use crate::pus::{PusReceiver, PusTcMpscRouter}; use crate::requests::{CompositeRequest, GenericRequestRouter}; -use crate::tcp::{SyncTcpTmSource, TcpTask}; +use crate::tmtc::ccsds::CcsdsReceiver; use crate::tmtc::{ PusTcSourceProviderSharedPool, SharedTcPool, TcSourceTaskDynamic, TcSourceTaskStatic, }; -use crate::udp::{StaticUdpTmHandler, UdpTmtcServer}; use satrs::mode::ModeRequest; use satrs::pus::event_man::EventRequestWithToken; use satrs::pus::TmInSharedPoolSender; diff --git a/satrs-example/src/queue.rs b/satrs-example/src/queue.rs deleted file mode 100644 index 65e2fde..0000000 --- a/satrs-example/src/queue.rs +++ /dev/null @@ -1,45 +0,0 @@ -/// Generic error type for sending something via a message queue. -#[derive(Debug, Copy, Clone)] -pub enum GenericSendError { - RxDisconnected, - QueueFull(Option), -} - -impl Display for GenericSendError { - fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { - match self { - GenericSendError::RxDisconnected => { - write!(f, "rx side has disconnected") - } - GenericSendError::QueueFull(max_cap) => { - write!(f, "queue with max capacity of {max_cap:?} is full") - } - } - } -} - -#[cfg(feature = "std")] -impl Error for GenericSendError {} - -/// Generic error type for sending something via a message queue. -#[derive(Debug, Copy, Clone)] -pub enum GenericRecvError { - Empty, - TxDisconnected, -} - -impl Display for GenericRecvError { - fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { - match self { - Self::TxDisconnected => { - write!(f, "tx side has disconnected") - } - Self::Empty => { - write!(f, "nothing to receive") - } - } - } -} - -#[cfg(feature = "std")] -impl Error for GenericRecvError {} diff --git a/satrs-example/src/ccsds.rs b/satrs-example/src/tmtc/ccsds.rs similarity index 100% rename from satrs-example/src/ccsds.rs rename to satrs-example/src/tmtc/ccsds.rs diff --git a/satrs-example/src/tmtc.rs b/satrs-example/src/tmtc/mod.rs similarity index 99% rename from satrs-example/src/tmtc.rs rename to satrs-example/src/tmtc/mod.rs index 43d5889..93d2927 100644 --- a/satrs-example/src/tmtc.rs +++ b/satrs-example/src/tmtc/mod.rs @@ -12,6 +12,9 @@ use satrs::spacepackets::ecss::tc::PusTcReader; use satrs::spacepackets::ecss::PusPacket; use satrs::tmtc::ReceivesCcsdsTc; +pub mod ccsds; +pub mod tm_funnel; + #[derive(Debug, Clone, PartialEq, Eq, Error)] pub enum MpscStoreAndSendError { #[error("Store error: {0}")] diff --git a/satrs-example/src/tm_funnel.rs b/satrs-example/src/tmtc/tm_funnel.rs similarity index 99% rename from satrs-example/src/tm_funnel.rs rename to satrs-example/src/tmtc/tm_funnel.rs index 61cddd1..f81d6bf 100644 --- a/satrs-example/src/tm_funnel.rs +++ b/satrs-example/src/tmtc/tm_funnel.rs @@ -16,7 +16,7 @@ use satrs::{ tmtc::tm_helper::SharedTmPool, }; -use crate::tcp::SyncTcpTmSource; +use crate::interface::tcp::SyncTcpTmSource; #[derive(Default)] pub struct CcsdsSeqCounterMap {