Skip to content

Commit

Permalink
added some test stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed May 8, 2024
1 parent fe4126f commit b86c2eb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
5 changes: 5 additions & 0 deletions satrs-example/src/acs/mgm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,8 @@ impl<ComInterface: SpiInterface, TmSender: EcssTmSender> ModeRequestHandler
Ok(())
}
}

#[cfg(test)]
mod tests {
// TODO: Add some basic tests for the modes of the device.
}
1 change: 1 addition & 0 deletions satrs-example/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
13 changes: 11 additions & 2 deletions satrs-example/src/interface/sim_client_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
time::Duration,
};

use satrs::pus::HandlingStatus;
use satrs_minisim::{
udp::SIM_CTRL_PORT, SerializableSimMsgPayload, SimComponent, SimMessageProvider, SimReply,
SimRequest,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand All @@ -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() {}
}
13 changes: 10 additions & 3 deletions satrs-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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(),
);
Expand Down Expand Up @@ -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(),
);
Expand Down

0 comments on commit b86c2eb

Please sign in to comment.