From b86c2eb1d1bc13390145657080fb2d2b85e33e62 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 8 May 2024 21:02:16 +0200 Subject: [PATCH] added some test stubs --- satrs-example/src/acs/mgm.rs | 5 +++++ satrs-example/src/config.rs | 1 + satrs-example/src/interface/sim_client_udp.rs | 13 +++++++++++-- satrs-example/src/main.rs | 13 ++++++++++--- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/satrs-example/src/acs/mgm.rs b/satrs-example/src/acs/mgm.rs index 3f7edf3..81bb1f7 100644 --- a/satrs-example/src/acs/mgm.rs +++ b/satrs-example/src/acs/mgm.rs @@ -340,3 +340,8 @@ impl ModeRequestHandler Ok(()) } } + +#[cfg(test)] +mod tests { + // TODO: Add some basic tests for the modes of the device. +} diff --git a/satrs-example/src/config.rs b/satrs-example/src/config.rs index deacd12..9e3ec6f 100644 --- a/satrs-example/src/config.rs +++ b/satrs-example/src/config.rs @@ -226,4 +226,5 @@ pub mod tasks { pub const FREQ_MS_UDP_TMTC: u64 = 200; pub const FREQ_MS_AOCS: u64 = 500; pub const FREQ_MS_PUS_STACK: u64 = 200; + pub const SIM_CLIENT_IDLE_DELAY_MS: u64 = 5; } diff --git a/satrs-example/src/interface/sim_client_udp.rs b/satrs-example/src/interface/sim_client_udp.rs index 0da3c3e..d16adfd 100644 --- a/satrs-example/src/interface/sim_client_udp.rs +++ b/satrs-example/src/interface/sim_client_udp.rs @@ -5,6 +5,7 @@ use std::{ time::Duration, }; +use satrs::pus::HandlingStatus; use satrs_minisim::{ udp::SIM_CTRL_PORT, SerializableSimMsgPayload, SimComponent, SimMessageProvider, SimReply, SimRequest, @@ -94,7 +95,7 @@ impl SimClientUdp { } } - pub fn operation(&mut self) { + pub fn operation(&mut self) -> HandlingStatus { let mut no_sim_requests_handled = true; let mut no_data_from_udp_server_received = true; loop { @@ -157,8 +158,9 @@ impl SimClientUdp { } } if no_sim_requests_handled && no_data_from_udp_server_received { - std::thread::sleep(Duration::from_millis(5)); + return HandlingStatus::Empty; } + HandlingStatus::HandledOne } pub fn add_reply_recipient( @@ -169,3 +171,10 @@ impl SimClientUdp { self.reply_map.0.insert(component, reply_sender); } } + +#[cfg(test)] +pub mod tests { + // TODO: Write some basic tests which verify that the ping/pong handling/check for the + // constructor works as expected. + fn test_basic() {} +} diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index bd7ba0b..a0babb8 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -16,10 +16,13 @@ use log::info; use pus::test::create_test_service_dynamic; use satrs::hal::std::tcp_server::ServerConfig; use satrs::hal::std::udp_server::UdpTcServer; +use satrs::pus::HandlingStatus; use satrs::request::GenericMessage; use satrs::tmtc::{PacketSenderWithSharedPool, SharedPacketPool}; use satrs_example::config::pool::{create_sched_tc_pool, create_static_pools}; -use satrs_example::config::tasks::{FREQ_MS_AOCS, FREQ_MS_PUS_STACK, FREQ_MS_UDP_TMTC}; +use satrs_example::config::tasks::{ + FREQ_MS_AOCS, FREQ_MS_PUS_STACK, FREQ_MS_UDP_TMTC, SIM_CLIENT_IDLE_DELAY_MS, +}; use satrs_example::config::{OBSW_SERVER_ADDR, PACKET_ID_VALIDATOR, SERVER_PORT}; use crate::acs::mgm::{ @@ -269,7 +272,9 @@ fn static_tmtc_pool_main() { thread::Builder::new() .name("sat-rs sim adapter".to_string()) .spawn(move || loop { - sim_client.operation(); + if sim_client.operation() == HandlingStatus::Empty { + std::thread::sleep(Duration::from_millis(SIM_CLIENT_IDLE_DELAY_MS)); + } }) .unwrap(), ); @@ -506,7 +511,9 @@ fn dyn_tmtc_pool_main() { thread::Builder::new() .name("sat-rs sim adapter".to_string()) .spawn(move || loop { - sim_client.operation(); + if sim_client.operation() == HandlingStatus::Empty { + std::thread::sleep(Duration::from_millis(SIM_CLIENT_IDLE_DELAY_MS)); + } }) .unwrap(), );