diff --git a/src/config.rs b/src/config.rs index 30e0614..ec9912b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,7 +9,9 @@ use std::path::{Path, PathBuf}; pub const STOP_FILE_NAME: &str = "stop-experiment"; pub const CONFIG_FILE_NAME: &str = "exp278.toml"; -pub const HOME_FOLDER_EXPERIMENT: &str = "/home/exp278"; +pub const HOME_FOLDER_EXPERIMENT: &str = "/home/exp278"; // also where IMS-100 images are placed +pub const TO_GROUND_FOLDER_EXPERIMENT: &str = "/home/exp278/toGround"; +pub const TO_GROUND_LP_FOLDER_EXPERIMENT: &str = "/home/exp278/toGroundLP"; pub const LOG_FOLDER: &str = "logs"; pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::UNSPECIFIED; @@ -291,3 +293,10 @@ pub mod tasks { pub const STOP_CHECK_FREQUENCY_MS: u64 = 400; pub const STOP_CHECK_FREQUENCY: Duration = Duration::from_millis(STOP_CHECK_FREQUENCY_MS); } + +pub fn create_low_priority_ground_dir() { + log::debug!("Creating low priority to ground directory"); + if !Path::new(TO_GROUND_LP_FOLDER_EXPERIMENT).exists() && std::fs::create_dir_all(TO_GROUND_LP_FOLDER_EXPERIMENT).is_err() { + log::error!("Failed to create low priority to ground directory '{}'", TO_GROUND_LP_FOLDER_EXPERIMENT); + } +} diff --git a/src/controller.rs b/src/controller.rs index 69c27c8..c1e5ae4 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -10,7 +10,8 @@ use std::{ sync::{atomic::AtomicBool, mpsc, Arc}, }; -use ops_sat_rs::config::{action_err::INVALID_ACTION_ID, HOME_PATH, STOP_FILE_NAME}; +use ops_sat_rs::config::{action_err::INVALID_ACTION_ID, HOME_PATH, STOP_FILE_NAME, TO_GROUND_FOLDER_EXPERIMENT}; +use crate::logger::LOGFILE_PATH; use crate::requests::CompositeRequest; @@ -18,6 +19,7 @@ use crate::requests::CompositeRequest; #[repr(u32)] pub enum ActionId { StopExperiment = 1, + DownlinkLogfile = 2, } pub struct ExperimentController { @@ -96,7 +98,19 @@ impl ExperimentController { ActionReplyVariant::Completed, )); if result.is_err() { - log::error!("sending action reply failed"); + log::error!("Sending action reply failed"); + } + } + ActionId::DownlinkLogfile => { + if let Some(logfile_path) = LOGFILE_PATH.get() { + if let Ok(logfile_path) = ::clone(logfile_path).into_os_string().into_string() { + let ground_folder_path = TO_GROUND_FOLDER_EXPERIMENT.to_string(); + if std::fs::copy(logfile_path.as_str(), ground_folder_path.as_str()).is_err() { + log::error!("Copying logfile into downlink path failed") + } + } + } else { + log::error!("Downlink path emtpy") } } } diff --git a/src/main.rs b/src/main.rs index af84c9d..0308b76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,14 +5,8 @@ use std::{ time::Duration, }; -use log::info; -use ops_sat_rs::config::{ - cfg_file::create_app_config, - components::{CONTROLLER_ID, TCP_SERVER, TCP_SPP_CLIENT, UDP_SERVER}, - pool::create_sched_tc_pool, - tasks::{FREQ_MS_CAMERA_HANDLING, FREQ_MS_CTRL, FREQ_MS_PUS_STACK, STOP_CHECK_FREQUENCY}, - VALID_PACKET_ID_LIST, VERSION, -}; +use log::{debug, info}; +use ops_sat_rs::config::{cfg_file::create_app_config, components::{CONTROLLER_ID, TCP_SERVER, TCP_SPP_CLIENT, UDP_SERVER}, create_low_priority_ground_dir, pool::create_sched_tc_pool, tasks::{FREQ_MS_CAMERA_HANDLING, FREQ_MS_CTRL, FREQ_MS_PUS_STACK, STOP_CHECK_FREQUENCY}, VALID_PACKET_ID_LIST, VERSION}; use ops_sat_rs::config::{components::CAMERA_HANDLER, tasks::FREQ_MS_EVENT_HANDLING}; use ops_sat_rs::config::{tasks::FREQ_MS_UDP_TMTC, OBSW_SERVER_ADDR, SERVER_PORT}; use ops_sat_rs::TimeStampHelper; @@ -54,10 +48,11 @@ mod tmtc; fn main() { setup_logger().expect("setting up logging with fern failed"); let version_str = VERSION.unwrap_or("?"); - println!("OPS-SAT Rust Experiment OBSW v{}", version_str); + debug!("OPS-SAT Rust Experiment OBSW v{}", version_str); + create_low_priority_ground_dir(); let app_cfg = create_app_config(); - println!("App Configuration: {:?}", app_cfg); + debug!("App Configuration: {:?}", app_cfg); let stop_signal = Arc::new(AtomicBool::new(false));