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
3 changed files with 30 additions and 15 deletions
Showing only changes of commit 1d92084e65 - Show all commits

View File

@ -1,7 +1,10 @@
use lazy_static::lazy_static;
use num_enum::{IntoPrimitive, TryFromPrimitive}; use num_enum::{IntoPrimitive, TryFromPrimitive};
use satrs_mib::res_code::ResultU16Info; use satrs_mib::res_code::ResultU16Info;
use satrs_mib::resultcode; use satrs_mib::resultcode;
use std::env;
use std::net::Ipv4Addr; use std::net::Ipv4Addr;
use std::path::{Path, PathBuf};
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 HOME_FOLER_EXPERIMENT: &str = "/home/exp278";
@ -26,6 +29,19 @@ pub enum GroupId {
Action = 3, Action = 3,
} }
lazy_static! {
pub static ref HOME_PATH: PathBuf = {
let home_path_default = env::var("HOME").expect("HOME env variable not set");
let mut home_path = PathBuf::new();
home_path.push(if Path::new(HOME_FOLER_EXPERIMENT).exists() {
HOME_FOLER_EXPERIMENT
} else {
&home_path_default
});
home_path
};
}
pub mod tmtc_err { pub mod tmtc_err {
use super::*; use super::*;
use satrs::res_code::ResultU16; use satrs::res_code::ResultU16;

View File

@ -10,7 +10,7 @@ use std::{
sync::{atomic::AtomicBool, mpsc, Arc}, 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, HOME_PATH, STOP_FILE_NAME};
use crate::requests::CompositeRequest; use crate::requests::CompositeRequest;
@ -30,13 +30,12 @@ pub struct ExperimentController {
impl ExperimentController { impl ExperimentController {
pub fn new( pub fn new(
home_dir: &Path,
composite_request_rx: mpsc::Receiver<GenericMessage<CompositeRequest>>, composite_request_rx: mpsc::Receiver<GenericMessage<CompositeRequest>>,
action_reply_tx: mpsc::Sender<GenericMessage<PusActionReply>>, action_reply_tx: mpsc::Sender<GenericMessage<PusActionReply>>,
stop_signal: Arc<AtomicBool>, stop_signal: Arc<AtomicBool>,
) -> Self { ) -> Self {
let mut home_path_stop_file = PathBuf::new(); let mut home_path_stop_file = PathBuf::new();
home_path_stop_file.push(home_dir); home_path_stop_file.push(HOME_PATH.as_path());
home_path_stop_file.push(STOP_FILE_NAME); home_path_stop_file.push(STOP_FILE_NAME);
let mut tmp_path_stop_file = temp_dir(); let mut tmp_path_stop_file = temp_dir();
tmp_path_stop_file.push(STOP_FILE_NAME); tmp_path_stop_file.push(STOP_FILE_NAME);
@ -107,9 +106,18 @@ impl ExperimentController {
let check_at_path = |path: &Path| { let check_at_path = |path: &Path| {
if path.exists() { 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 path
); );
// By default, clear the stop file.
let result = std::fs::remove_file(path);
if result.is_err() {
log::error!(
"failed to remove stop file at {:?}: {}",
path,
result.unwrap_err()
);
}
self.stop_signal self.stop_signal
.store(true, std::sync::atomic::Ordering::Relaxed); .store(true, std::sync::atomic::Ordering::Relaxed);
} }

View File

@ -1,7 +1,5 @@
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,
@ -11,7 +9,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, HOME_FOLER_EXPERIMENT, EXPERIMENT_APID,
}; };
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::{
@ -161,14 +159,7 @@ 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(),