Merge pull request 'added host feature' (#22) from introduce-host-feature into main

Reviewed-on: #22
This commit is contained in:
Robin Müller 2024-04-26 19:20:36 +02:00
commit d86172c436
5 changed files with 66 additions and 21 deletions

View File

@ -36,6 +36,9 @@ version = ">=0.1.2, <0.2"
env_logger = "0.11" env_logger = "0.11"
tempfile = "3" tempfile = "3"
[features]
host = []
# I don't think we need insane performance. If anything, a small binary is easier to upload # I don't think we need insane performance. If anything, a small binary is easier to upload
# to the satellite. # to the satellite.
[profile.release] [profile.release]

View File

@ -37,7 +37,7 @@ You can use the regular cargo workflow for this.
### Running ### Running
```sh ```sh
cargo run cargo run --features host
``` ```
### Testing ### Testing

View File

@ -1,5 +1,6 @@
use lazy_static::lazy_static; use lazy_static::lazy_static;
use num_enum::{IntoPrimitive, TryFromPrimitive}; use num_enum::{IntoPrimitive, TryFromPrimitive};
use once_cell::sync::OnceCell;
use satrs::events::{EventU32TypedSev, SeverityInfo}; use satrs::events::{EventU32TypedSev, SeverityInfo};
use satrs::spacepackets::PacketId; use satrs::spacepackets::PacketId;
use satrs_mib::res_code::ResultU16Info; use satrs_mib::res_code::ResultU16Info;
@ -10,8 +11,8 @@ use std::path::{Path, PathBuf};
pub const STOP_FILE_NAME: &str = "stop-experiment"; pub const STOP_FILE_NAME: &str = "stop-experiment";
pub const CONFIG_FILE_NAME: &str = "exp278.toml"; pub const CONFIG_FILE_NAME: &str = "exp278.toml";
pub const HOME_FOLDER_EXPERIMENT: &str = "/home/exp278"; // also where IMS-100 images are placed 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_FOLDER_NAME: &str = "toGround";
pub const TO_GROUND_LP_FOLDER_EXPERIMENT: &str = "/home/exp278/toGroundLP"; pub const TO_GROUND_LP_FOLDER_NAME: &str = "toGroundLP";
pub const LOG_FOLDER: &str = "logs"; pub const LOG_FOLDER: &str = "logs";
pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::UNSPECIFIED; pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::UNSPECIFIED;
@ -27,6 +28,9 @@ pub const VALID_PACKET_ID_LIST: &[PacketId] = &[PacketId::new_for_tc(true, EXPER
pub const SPP_CLIENT_WIRETAPPING_RX: bool = false; pub const SPP_CLIENT_WIRETAPPING_RX: bool = false;
pub const SPP_CLIENT_WIRETAPPING_TX: bool = false; pub const SPP_CLIENT_WIRETAPPING_TX: bool = false;
pub static TO_GROUND_FOLDER_DIR: OnceCell<PathBuf> = OnceCell::new();
pub static TO_GROUND_LP_FOLDER_DIR: OnceCell<PathBuf> = OnceCell::new();
#[derive(Copy, Clone, PartialEq, Eq, Debug, TryFromPrimitive, IntoPrimitive)] #[derive(Copy, Clone, PartialEq, Eq, Debug, TryFromPrimitive, IntoPrimitive)]
#[repr(u8)] #[repr(u8)]
pub enum CustomPusServiceId { pub enum CustomPusServiceId {
@ -66,6 +70,49 @@ lazy_static! {
}; };
} }
pub fn set_up_low_prio_ground_dir() {
#[cfg(feature = "host")]
let mut to_ground_lp_dir = std::env::current_dir().expect("getting current dir failed");
#[cfg(not(feature = "host"))]
let mut to_ground_lp_dir = HOME_PATH.clone();
to_ground_lp_dir.push(TO_GROUND_LP_FOLDER_NAME);
if !Path::new(&to_ground_lp_dir).exists() {
log::info!(
"creating low priority to ground directory at {:?}",
to_ground_lp_dir
);
if std::fs::create_dir_all(&to_ground_lp_dir).is_err() {
log::error!(
"Failed to create low priority to ground directory '{:?}'",
to_ground_lp_dir
);
}
}
TO_GROUND_LP_FOLDER_DIR
.set(to_ground_lp_dir)
.expect("attemting to set once cell twice");
}
pub fn set_up_ground_dir() {
#[cfg(feature = "host")]
let mut to_ground_dir = std::env::current_dir().expect("getting current dir failed");
#[cfg(not(feature = "host"))]
let mut to_ground_dir = HOME_PATH.clone();
to_ground_dir.push(TO_GROUND_FOLDER_NAME);
if !Path::new(&to_ground_dir).exists() {
log::info!("creating to ground directory at {:?}", to_ground_dir);
if std::fs::create_dir_all(&to_ground_dir).is_err() {
log::error!(
"Failed to create low priority to ground directory '{:?}'",
to_ground_dir
);
}
}
TO_GROUND_FOLDER_DIR
.set(to_ground_dir)
.expect("attemting to set once cell twice");
}
pub mod cfg_file { pub mod cfg_file {
use std::{ use std::{
fs::File, fs::File,
@ -322,15 +369,3 @@ pub mod tasks {
pub const STOP_CHECK_FREQUENCY_MS: u64 = 400; pub const STOP_CHECK_FREQUENCY_MS: u64 = 400;
pub const STOP_CHECK_FREQUENCY: Duration = Duration::from_millis(STOP_CHECK_FREQUENCY_MS); pub const STOP_CHECK_FREQUENCY: Duration = Duration::from_millis(STOP_CHECK_FREQUENCY_MS);
} }
pub fn create_low_priority_ground_dir() {
log::info!("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
);
}
}

View File

@ -1,9 +1,9 @@
use crate::logger::LOGFILE_PATH; use crate::logger::LOGFILE_PATH;
use num_enum::TryFromPrimitive; use num_enum::TryFromPrimitive;
use ops_sat_rs::config::{action_err::INVALID_ACTION_ID, HOME_FOLDER_EXPERIMENT};
use ops_sat_rs::config::{ use ops_sat_rs::config::{
action_err::INVALID_ACTION_ID, HOME_FOLDER_EXPERIMENT, TO_GROUND_FOLDER_EXPERIMENT, HOME_PATH, STOP_FILE_NAME, TO_GROUND_FOLDER_DIR, TO_GROUND_LP_FOLDER_DIR,
}; };
use ops_sat_rs::config::{HOME_PATH, STOP_FILE_NAME, TO_GROUND_LP_FOLDER_EXPERIMENT};
use satrs::action::ActionRequestVariant; use satrs::action::ActionRequestVariant;
use satrs::{ use satrs::{
action::ActionRequest, action::ActionRequest,
@ -60,8 +60,14 @@ impl Default for ControllerPathCollection {
Self { Self {
stop_file_home_path: home_path_stop_file, stop_file_home_path: home_path_stop_file,
stop_file_tmp_path: tmp_path_stop_file, stop_file_tmp_path: tmp_path_stop_file,
to_ground_dir: PathBuf::from(TO_GROUND_FOLDER_EXPERIMENT), to_ground_dir: TO_GROUND_FOLDER_DIR
to_ground_low_prio_dir: PathBuf::from(TO_GROUND_LP_FOLDER_EXPERIMENT), .get()
.expect("to ground directory not set")
.clone(),
to_ground_low_prio_dir: TO_GROUND_LP_FOLDER_DIR
.get()
.expect("to ground low prio directory not set")
.clone(),
} }
} }
} }

View File

@ -11,8 +11,8 @@ use log::info;
use ops_sat_rs::config::{ use ops_sat_rs::config::{
cfg_file::create_app_config, cfg_file::create_app_config,
components::{CONTROLLER_ID, TCP_SERVER, TCP_SPP_CLIENT, UDP_SERVER}, components::{CONTROLLER_ID, TCP_SERVER, TCP_SPP_CLIENT, UDP_SERVER},
create_low_priority_ground_dir,
pool::create_sched_tc_pool, pool::create_sched_tc_pool,
set_up_ground_dir, set_up_low_prio_ground_dir,
tasks::{FREQ_MS_CAMERA_HANDLING, FREQ_MS_CTRL, FREQ_MS_PUS_STACK, STOP_CHECK_FREQUENCY}, tasks::{FREQ_MS_CAMERA_HANDLING, FREQ_MS_CTRL, FREQ_MS_PUS_STACK, STOP_CHECK_FREQUENCY},
HOME_PATH, STOP_FILE_NAME, VALID_PACKET_ID_LIST, VERSION, HOME_PATH, STOP_FILE_NAME, VALID_PACKET_ID_LIST, VERSION,
}; };
@ -58,7 +58,8 @@ fn main() {
let version_str = VERSION.unwrap_or("?"); let version_str = VERSION.unwrap_or("?");
println!("OPS-SAT Rust Experiment OBSW v{}", version_str); println!("OPS-SAT Rust Experiment OBSW v{}", version_str);
setup_logger().expect("setting up logging with fern failed"); setup_logger().expect("setting up logging with fern failed");
create_low_priority_ground_dir(); set_up_low_prio_ground_dir();
set_up_ground_dir();
let app_cfg = create_app_config(); let app_cfg = create_app_config();
info!("App Configuration: {:?}", app_cfg); info!("App Configuration: {:?}", app_cfg);