Merge branch 'stop-logic' into add-action-service-controller-obj
This commit is contained in:
66
src/main.rs
66
src/main.rs
@ -1,12 +1,16 @@
|
||||
use std::{
|
||||
net::{IpAddr, SocketAddr},
|
||||
sync::mpsc,
|
||||
sync::{atomic::AtomicBool, mpsc, Arc},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use log::info;
|
||||
use ops_sat_rs::config::{components::CONTROLLER_ID, tasks::FREQ_MS_PUS_STACK, EXPERIMENT_APID};
|
||||
use ops_sat_rs::config::{
|
||||
components::CONTROLLER_ID,
|
||||
tasks::{FREQ_MS_CTRL, FREQ_MS_PUS_STACK},
|
||||
EXPERIMENT_APID, STOP_FILE_NAME,
|
||||
};
|
||||
use ops_sat_rs::config::{tasks::FREQ_MS_UDP_TMTC, OBSW_SERVER_ADDR, SERVER_PORT};
|
||||
use satrs::{
|
||||
hal::std::{tcp_server::ServerConfig, udp_server::UdpTcServer},
|
||||
@ -38,10 +42,11 @@ mod requests;
|
||||
mod tm_funnel;
|
||||
mod tmtc;
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn main() {
|
||||
setup_logger().expect("setting up logging with fern failed");
|
||||
println!("OPS-SAT Rust experiment OBSW");
|
||||
println!("OPS-SAT Rust Experiment OBSW");
|
||||
|
||||
let stop_signal = Arc::new(AtomicBool::new(false));
|
||||
|
||||
let (tc_source_tx, tc_source_rx) = mpsc::channel();
|
||||
let (tm_funnel_tx, tm_funnel_rx) = mpsc::channel();
|
||||
@ -143,53 +148,94 @@ fn main() {
|
||||
sync_tm_tcp_source.clone(),
|
||||
tcp_ccsds_distributor,
|
||||
vec![PacketId::new_for_tc(true, EXPERIMENT_APID)],
|
||||
// PACKET_ID_VALIDATOR.clone(),
|
||||
stop_signal.clone(),
|
||||
)
|
||||
.expect("tcp server creation failed");
|
||||
|
||||
let mut tm_funnel = TmFunnelDynamic::new(sync_tm_tcp_source, tm_funnel_rx, tm_server_tx);
|
||||
let mut tm_funnel = TmFunnelDynamic::new(
|
||||
sync_tm_tcp_source,
|
||||
tm_funnel_rx,
|
||||
tm_server_tx,
|
||||
stop_signal.clone(),
|
||||
);
|
||||
|
||||
info!("Starting CTRL task");
|
||||
let ctrl_stop_signal = stop_signal.clone();
|
||||
let jh_ctrl_thread = thread::Builder::new()
|
||||
.name("ops-sat ctrl".to_string())
|
||||
.spawn(move || loop {
|
||||
if std::path::Path::new(STOP_FILE_NAME).exists() {
|
||||
log::warn!(
|
||||
"Detected stop file name at {}. Initiating experiment shutdown",
|
||||
STOP_FILE_NAME
|
||||
);
|
||||
ctrl_stop_signal.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
break;
|
||||
}
|
||||
thread::sleep(Duration::from_millis(FREQ_MS_CTRL));
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
info!("Starting TMTC and UDP task");
|
||||
let tmtc_stop_signal = stop_signal.clone();
|
||||
let jh_udp_tmtc = thread::Builder::new()
|
||||
.name("TMTC and UDP".to_string())
|
||||
.name("ops-sat tmtc-udp".to_string())
|
||||
.spawn(move || {
|
||||
info!("Running UDP server on port {SERVER_PORT}");
|
||||
loop {
|
||||
udp_tmtc_server.periodic_operation();
|
||||
tmtc_task.periodic_operation();
|
||||
if tmtc_stop_signal.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
thread::sleep(Duration::from_millis(FREQ_MS_UDP_TMTC));
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let tcp_stop_signal = stop_signal.clone();
|
||||
info!("Starting TCP task");
|
||||
let jh_tcp = thread::Builder::new()
|
||||
.name("TCP".to_string())
|
||||
.name("ops-sat tcp".to_string())
|
||||
.spawn(move || {
|
||||
info!("Running TCP server on port {SERVER_PORT}");
|
||||
loop {
|
||||
tcp_server.periodic_operation();
|
||||
if tcp_stop_signal.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
info!("Starting TM funnel task");
|
||||
let funnel_stop_signal = stop_signal.clone();
|
||||
let jh_tm_funnel = thread::Builder::new()
|
||||
.name("TM Funnel".to_string())
|
||||
.name("ops-sat tm-funnel".to_string())
|
||||
.spawn(move || loop {
|
||||
tm_funnel.operation();
|
||||
if funnel_stop_signal.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
info!("Starting PUS handler thread");
|
||||
let pus_stop_signal = stop_signal.clone();
|
||||
let jh_pus_handler = thread::Builder::new()
|
||||
.name("PUS".to_string())
|
||||
.name("ops-sat pus".to_string())
|
||||
.spawn(move || loop {
|
||||
pus_stack.periodic_operation();
|
||||
if pus_stop_signal.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
thread::sleep(Duration::from_millis(FREQ_MS_PUS_STACK));
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
jh_ctrl_thread
|
||||
.join()
|
||||
.expect("Joining Controller thread failed");
|
||||
jh_udp_tmtc
|
||||
.join()
|
||||
.expect("Joining UDP TMTC server thread failed");
|
||||
|
Reference in New Issue
Block a user