more improvements
This commit is contained in:
parent
d0835f9393
commit
1d92084e65
@ -1,7 +1,10 @@
|
||||
use lazy_static::lazy_static;
|
||||
use num_enum::{IntoPrimitive, TryFromPrimitive};
|
||||
use satrs_mib::res_code::ResultU16Info;
|
||||
use satrs_mib::resultcode;
|
||||
use std::env;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub const STOP_FILE_NAME: &str = "stop-experiment";
|
||||
pub const HOME_FOLER_EXPERIMENT: &str = "/home/exp278";
|
||||
@ -26,6 +29,19 @@ pub enum GroupId {
|
||||
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 {
|
||||
use super::*;
|
||||
use satrs::res_code::ResultU16;
|
||||
|
@ -10,7 +10,7 @@ use std::{
|
||||
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;
|
||||
|
||||
@ -30,13 +30,12 @@ pub struct ExperimentController {
|
||||
|
||||
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(HOME_PATH.as_path());
|
||||
home_path_stop_file.push(STOP_FILE_NAME);
|
||||
let mut tmp_path_stop_file = temp_dir();
|
||||
tmp_path_stop_file.push(STOP_FILE_NAME);
|
||||
@ -107,9 +106,18 @@ impl ExperimentController {
|
||||
let check_at_path = |path: &Path| {
|
||||
if path.exists() {
|
||||
log::warn!(
|
||||
"Detected stop file name at {}. Initiating experiment shutdown",
|
||||
STOP_FILE_NAME
|
||||
"Detected stop file name at {:?}. Initiating experiment shutdown",
|
||||
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
|
||||
.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
|
11
src/main.rs
11
src/main.rs
@ -1,7 +1,5 @@
|
||||
use std::{
|
||||
env,
|
||||
net::{IpAddr, SocketAddr},
|
||||
path::Path,
|
||||
sync::{atomic::AtomicBool, mpsc, Arc},
|
||||
thread,
|
||||
time::Duration,
|
||||
@ -11,7 +9,7 @@ use log::info;
|
||||
use ops_sat_rs::config::{
|
||||
components::CONTROLLER_ID,
|
||||
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 satrs::{
|
||||
@ -161,14 +159,7 @@ 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(),
|
||||
|
Loading…
Reference in New Issue
Block a user