Add action service and controller component #5
@ -4,6 +4,7 @@ use satrs_mib::resultcode;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
pub const STOP_FILE_NAME: &str = "stop-experiment";
|
||||
pub const HOME_FOLER_EXPERIMENT: &str = "/home/exp278";
|
||||
|
||||
pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::UNSPECIFIED;
|
||||
pub const SERVER_PORT: u16 = 7301;
|
||||
|
@ -1,11 +1,14 @@
|
||||
use derive_new::new;
|
||||
use num_enum::TryFromPrimitive;
|
||||
use satrs::{
|
||||
action::ActionRequest,
|
||||
pus::action::{ActionReplyVariant, PusActionReply},
|
||||
request::{GenericMessage, MessageMetadata},
|
||||
};
|
||||
use std::sync::{atomic::AtomicBool, mpsc, Arc};
|
||||
use std::{
|
||||
env::temp_dir,
|
||||
path::{Path, PathBuf},
|
||||
sync::{atomic::AtomicBool, mpsc, Arc},
|
||||
};
|
||||
|
||||
use ops_sat_rs::config::{action_err::INVALID_ACTION_ID, STOP_FILE_NAME};
|
||||
|
||||
@ -17,11 +20,34 @@ pub enum ActionId {
|
||||
StopExperiment = 1,
|
||||
}
|
||||
|
||||
#[derive(new)]
|
||||
pub struct ExperimentController {
|
||||
pub composite_request_rx: mpsc::Receiver<GenericMessage<CompositeRequest>>,
|
||||
pub action_reply_tx: mpsc::Sender<GenericMessage<PusActionReply>>,
|
||||
pub stop_signal: Arc<AtomicBool>,
|
||||
home_path_stop_file: PathBuf,
|
||||
tmp_path_stop_file: PathBuf,
|
||||
}
|
||||
|
||||
impl ExperimentController {
|
||||
pub fn new(
|
||||
home_dir: &Path,
|
||||
composite_request_rx: mpsc::Receiver<GenericMessage<CompositeRequest>>,
|
||||
action_reply_tx: mpsc::Sender<GenericMessage<PusActionReply>>,
|
||||
stop_signal: Arc<AtomicBool>,
|
||||
) -> Self {
|
||||
let mut home_path_stop_file = PathBuf::new();
|
||||
home_path_stop_file.push(home_dir);
|
||||
home_path_stop_file.push(STOP_FILE_NAME);
|
||||
let mut tmp_path_stop_file = temp_dir();
|
||||
tmp_path_stop_file.push(STOP_FILE_NAME);
|
||||
Self {
|
||||
composite_request_rx,
|
||||
action_reply_tx,
|
||||
stop_signal,
|
||||
home_path_stop_file,
|
||||
tmp_path_stop_file,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExperimentController {
|
||||
@ -78,7 +104,8 @@ impl ExperimentController {
|
||||
}
|
||||
|
||||
pub fn check_stop_file(&self) {
|
||||
if std::path::Path::new(STOP_FILE_NAME).exists() {
|
||||
let check_at_path = |path: &Path| {
|
||||
if path.exists() {
|
||||
log::warn!(
|
||||
"Detected stop file name at {}. Initiating experiment shutdown",
|
||||
STOP_FILE_NAME
|
||||
@ -86,5 +113,8 @@ impl ExperimentController {
|
||||
self.stop_signal
|
||||
.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
};
|
||||
check_at_path(self.tmp_path_stop_file.as_path());
|
||||
check_at_path(self.home_path_stop_file.as_path());
|
||||
}
|
||||
}
|
||||
|
11
src/main.rs
11
src/main.rs
@ -1,5 +1,7 @@
|
||||
use std::{
|
||||
env,
|
||||
net::{IpAddr, SocketAddr},
|
||||
path::Path,
|
||||
sync::{atomic::AtomicBool, mpsc, Arc},
|
||||
thread,
|
||||
time::Duration,
|
||||
@ -9,7 +11,7 @@ use log::info;
|
||||
use ops_sat_rs::config::{
|
||||
components::CONTROLLER_ID,
|
||||
tasks::{FREQ_MS_CTRL, FREQ_MS_PUS_STACK},
|
||||
EXPERIMENT_APID,
|
||||
EXPERIMENT_APID, HOME_FOLER_EXPERIMENT,
|
||||
};
|
||||
use ops_sat_rs::config::{tasks::FREQ_MS_UDP_TMTC, OBSW_SERVER_ADDR, SERVER_PORT};
|
||||
use satrs::{
|
||||
@ -159,7 +161,14 @@ fn main() {
|
||||
stop_signal.clone(),
|
||||
);
|
||||
|
||||
let home_path_default = env::var("HOME").expect("HOME env variable not set");
|
||||
let home_path = Path::new(if Path::new(HOME_FOLER_EXPERIMENT).exists() {
|
||||
HOME_FOLER_EXPERIMENT
|
||||
} else {
|
||||
&home_path_default
|
||||
});
|
||||
let mut controller = ExperimentController::new(
|
||||
home_path,
|
||||
controller_composite_rx,
|
||||
pus_action_reply_tx,
|
||||
stop_signal.clone(),
|
||||
|
@ -247,7 +247,8 @@ impl TargetedPusService for ActionServiceWrapper {
|
||||
PusPacketHandlerResult::Empty => return HandlingStatus::Empty,
|
||||
},
|
||||
Err(error) => {
|
||||
error!("PUS packet handling error: {error:?}")
|
||||
error!("PUS packet handling error: {error:?}");
|
||||
return HandlingStatus::Empty;
|
||||
}
|
||||
}
|
||||
HandlingStatus::HandledOne
|
||||
|
@ -33,7 +33,8 @@ impl PusStack {
|
||||
loop {
|
||||
let mut nothing_to_do = true;
|
||||
let mut is_srv_finished =
|
||||
|tc_handling_status: HandlingStatus,
|
||||
|_srv_id: u8,
|
||||
tc_handling_status: HandlingStatus,
|
||||
reply_handling_status: Option<HandlingStatus>| {
|
||||
if tc_handling_status == HandlingStatus::HandledOne
|
||||
|| (reply_handling_status.is_some()
|
||||
@ -42,10 +43,15 @@ impl PusStack {
|
||||
nothing_to_do = false;
|
||||
}
|
||||
};
|
||||
is_srv_finished(self.test_srv.poll_and_handle_next_packet(&time_stamp), None);
|
||||
is_srv_finished(
|
||||
17,
|
||||
self.test_srv.poll_and_handle_next_packet(&time_stamp),
|
||||
None,
|
||||
);
|
||||
// is_srv_finished(self.schedule_srv.poll_and_handle_next_tc(&time_stamp), None);
|
||||
// is_srv_finished(self.event_srv.poll_and_handle_next_tc(&time_stamp), None);
|
||||
is_srv_finished(
|
||||
8,
|
||||
self.action_srv_wrapper.poll_and_handle_next_tc(&time_stamp),
|
||||
Some(
|
||||
self.action_srv_wrapper
|
||||
|
Loading…
Reference in New Issue
Block a user