Add action service and controller component #5

Merged
muellerr merged 11 commits from add-action-service-controller-obj into main 2024-04-13 11:19:13 +02:00
5 changed files with 62 additions and 15 deletions
Showing only changes of commit d0835f9393 - Show all commits

View File

@ -4,6 +4,7 @@ use satrs_mib::resultcode;
use std::net::Ipv4Addr; use std::net::Ipv4Addr;
pub const STOP_FILE_NAME: &str = "stop-experiment"; 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 OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::UNSPECIFIED;
pub const SERVER_PORT: u16 = 7301; pub const SERVER_PORT: u16 = 7301;

View File

@ -1,11 +1,14 @@
use derive_new::new;
use num_enum::TryFromPrimitive; use num_enum::TryFromPrimitive;
use satrs::{ use satrs::{
action::ActionRequest, action::ActionRequest,
pus::action::{ActionReplyVariant, PusActionReply}, pus::action::{ActionReplyVariant, PusActionReply},
request::{GenericMessage, MessageMetadata}, 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}; use ops_sat_rs::config::{action_err::INVALID_ACTION_ID, STOP_FILE_NAME};
@ -17,11 +20,34 @@ pub enum ActionId {
StopExperiment = 1, StopExperiment = 1,
} }
#[derive(new)]
pub struct ExperimentController { pub struct ExperimentController {
pub composite_request_rx: mpsc::Receiver<GenericMessage<CompositeRequest>>, pub composite_request_rx: mpsc::Receiver<GenericMessage<CompositeRequest>>,
pub action_reply_tx: mpsc::Sender<GenericMessage<PusActionReply>>, pub action_reply_tx: mpsc::Sender<GenericMessage<PusActionReply>>,
pub stop_signal: Arc<AtomicBool>, 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 { impl ExperimentController {
@ -78,7 +104,8 @@ impl ExperimentController {
} }
pub fn check_stop_file(&self) { 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!( log::warn!(
"Detected stop file name at {}. Initiating experiment shutdown", "Detected stop file name at {}. Initiating experiment shutdown",
STOP_FILE_NAME STOP_FILE_NAME
@ -86,5 +113,8 @@ impl ExperimentController {
self.stop_signal self.stop_signal
.store(true, std::sync::atomic::Ordering::Relaxed); .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());
} }
} }

View File

@ -1,5 +1,7 @@
use std::{ use std::{
env,
net::{IpAddr, SocketAddr}, net::{IpAddr, SocketAddr},
path::Path,
sync::{atomic::AtomicBool, mpsc, Arc}, sync::{atomic::AtomicBool, mpsc, Arc},
thread, thread,
time::Duration, time::Duration,
@ -9,7 +11,7 @@ use log::info;
use ops_sat_rs::config::{ use ops_sat_rs::config::{
components::CONTROLLER_ID, components::CONTROLLER_ID,
tasks::{FREQ_MS_CTRL, FREQ_MS_PUS_STACK}, 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 ops_sat_rs::config::{tasks::FREQ_MS_UDP_TMTC, OBSW_SERVER_ADDR, SERVER_PORT};
use satrs::{ use satrs::{
@ -159,7 +161,14 @@ fn main() {
stop_signal.clone(), 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( let mut controller = ExperimentController::new(
home_path,
controller_composite_rx, controller_composite_rx,
pus_action_reply_tx, pus_action_reply_tx,
stop_signal.clone(), stop_signal.clone(),

View File

@ -247,7 +247,8 @@ impl TargetedPusService for ActionServiceWrapper {
PusPacketHandlerResult::Empty => return HandlingStatus::Empty, PusPacketHandlerResult::Empty => return HandlingStatus::Empty,
}, },
Err(error) => { Err(error) => {
error!("PUS packet handling error: {error:?}") error!("PUS packet handling error: {error:?}");
return HandlingStatus::Empty;
} }
} }
HandlingStatus::HandledOne HandlingStatus::HandledOne

View File

@ -33,7 +33,8 @@ impl PusStack {
loop { loop {
let mut nothing_to_do = true; let mut nothing_to_do = true;
let mut is_srv_finished = let mut is_srv_finished =
|tc_handling_status: HandlingStatus, |_srv_id: u8,
tc_handling_status: HandlingStatus,
reply_handling_status: Option<HandlingStatus>| { reply_handling_status: Option<HandlingStatus>| {
if tc_handling_status == HandlingStatus::HandledOne if tc_handling_status == HandlingStatus::HandledOne
|| (reply_handling_status.is_some() || (reply_handling_status.is_some()
@ -42,10 +43,15 @@ impl PusStack {
nothing_to_do = false; 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.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(self.event_srv.poll_and_handle_next_tc(&time_stamp), None);
is_srv_finished( is_srv_finished(
8,
self.action_srv_wrapper.poll_and_handle_next_tc(&time_stamp), self.action_srv_wrapper.poll_and_handle_next_tc(&time_stamp),
Some( Some(
self.action_srv_wrapper self.action_srv_wrapper