implement move images command
- Also implement various importantr bugfixes for shutdown handling
This commit is contained in:
@ -323,17 +323,11 @@ pub fn move_images_inside_home_dir_to_low_prio_ground_dir(
|
||||
if path_name_str.contains("img_msec_") {
|
||||
let mut target_path = PathBuf::new();
|
||||
target_path.push(low_prio_target_dir);
|
||||
target_path.push(path_name);
|
||||
log::info!(
|
||||
"moving image file from {:?} to {:?}",
|
||||
dir_entry,
|
||||
target_path
|
||||
);
|
||||
target_path.push(&path_name);
|
||||
log::info!("moving file {}", &path_name_str);
|
||||
std::fs::rename(dir_entry.path(), target_path)?;
|
||||
moved_files += 1;
|
||||
}
|
||||
|
||||
log::info!("found image file: {:?}", dir_entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
30
src/main.rs
30
src/main.rs
@ -154,14 +154,20 @@ fn main() {
|
||||
);
|
||||
|
||||
let sock_addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
|
||||
let udp_tc_server = UdpTcServer::new(UDP_SERVER.id(), sock_addr, 2048, tc_source_tx.clone())
|
||||
.expect("creating UDP TMTC server failed");
|
||||
let mut udp_tmtc_server = UdpTmtcServer {
|
||||
udp_tc_server,
|
||||
tm_handler: DynamicUdpTmHandler {
|
||||
tm_rx: tm_tcp_server_rx,
|
||||
},
|
||||
};
|
||||
let udp_tc_server_result =
|
||||
UdpTcServer::new(UDP_SERVER.id(), sock_addr, 2048, tc_source_tx.clone());
|
||||
if udp_tc_server_result.is_err() {
|
||||
log::error!("UDP server creation failed");
|
||||
}
|
||||
let mut opt_udp_tmtc_server = None;
|
||||
if let Ok(udp_tc_server) = udp_tc_server_result {
|
||||
opt_udp_tmtc_server = Some(UdpTmtcServer {
|
||||
udp_tc_server,
|
||||
tm_handler: DynamicUdpTmHandler {
|
||||
tm_rx: tm_tcp_server_rx,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
let tcp_server_cfg = ServerConfig::new(
|
||||
TCP_SERVER.id(),
|
||||
@ -243,7 +249,9 @@ fn main() {
|
||||
.spawn(move || {
|
||||
info!("Running UDP server on port {SERVER_PORT}");
|
||||
loop {
|
||||
udp_tmtc_server.periodic_operation();
|
||||
if let Some(ref mut udp_tmtc_server) = opt_udp_tmtc_server {
|
||||
udp_tmtc_server.periodic_operation();
|
||||
}
|
||||
tmtc_task.periodic_operation();
|
||||
if tmtc_stop_signal.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
break;
|
||||
@ -307,10 +315,14 @@ fn main() {
|
||||
.unwrap();
|
||||
|
||||
info!("Starting event handling task");
|
||||
let event_stop_signal = stop_signal.clone();
|
||||
let jh_event_handling = thread::Builder::new()
|
||||
.name("sat-rs events".to_string())
|
||||
.spawn(move || loop {
|
||||
event_handler.periodic_operation();
|
||||
if event_stop_signal.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
thread::sleep(Duration::from_millis(FREQ_MS_EVENT_HANDLING));
|
||||
})
|
||||
.unwrap();
|
||||
|
@ -252,24 +252,29 @@ impl TargetedPusService for ActionServiceWrapper {
|
||||
fn poll_and_handle_next_tc(&mut self, time_stamp: &[u8]) -> HandlingStatus {
|
||||
match self.service.poll_and_handle_next_tc(time_stamp) {
|
||||
Ok(result) => match result {
|
||||
PusPacketHandlerResult::RequestHandled => {}
|
||||
PusPacketHandlerResult::RequestHandled => {
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {
|
||||
warn!("PUS 8 partial packet handling success: {e:?}")
|
||||
warn!("PUS 8 partial packet handling success: {e:?}");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::CustomSubservice(invalid, _) => {
|
||||
warn!("PUS 8 invalid subservice {invalid}");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::SubserviceNotImplemented(subservice, _) => {
|
||||
warn!("PUS 8 subservice {subservice} not implemented");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::Empty => return HandlingStatus::Empty,
|
||||
PusPacketHandlerResult::Empty => (),
|
||||
},
|
||||
Err(error) => {
|
||||
error!("PUS packet handling error: {error:?}");
|
||||
return HandlingStatus::Empty;
|
||||
}
|
||||
}
|
||||
HandlingStatus::HandledOne
|
||||
// To avoid permanent loops, treat queue empty by default (all tasks done).
|
||||
HandlingStatus::Empty
|
||||
}
|
||||
|
||||
fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> HandlingStatus {
|
||||
|
@ -45,22 +45,28 @@ impl EventServiceWrapper {
|
||||
pub fn poll_and_handle_next_tc(&mut self, time_stamp: &[u8]) -> HandlingStatus {
|
||||
match self.handler.poll_and_handle_next_tc(time_stamp) {
|
||||
Ok(result) => match result {
|
||||
PusPacketHandlerResult::RequestHandled => {}
|
||||
PusPacketHandlerResult::RequestHandled => {
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {
|
||||
warn!("PUS 5 partial packet handling success: {e:?}")
|
||||
warn!("PUS 5 partial packet handling success: {e:?}");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::CustomSubservice(invalid, _) => {
|
||||
warn!("PUS 5 invalid subservice {invalid}");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::SubserviceNotImplemented(subservice, _) => {
|
||||
warn!("PUS 5 subservice {subservice} not implemented");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::Empty => return HandlingStatus::Empty,
|
||||
PusPacketHandlerResult::Empty => (),
|
||||
},
|
||||
Err(error) => {
|
||||
error!("PUS packet handling error: {error:?}")
|
||||
error!("PUS packet handling error: {error:?}");
|
||||
}
|
||||
}
|
||||
HandlingStatus::HandledOne
|
||||
// To avoid permanent loops, treat queue empty by default (all tasks done).
|
||||
HandlingStatus::Empty
|
||||
}
|
||||
}
|
||||
|
@ -271,25 +271,29 @@ impl HkServiceWrapper {
|
||||
pub fn poll_and_handle_next_tc(&mut self, time_stamp: &[u8]) -> HandlingStatus {
|
||||
match self.service.poll_and_handle_next_tc(time_stamp) {
|
||||
Ok(result) => match result {
|
||||
PusPacketHandlerResult::RequestHandled => {}
|
||||
PusPacketHandlerResult::RequestHandled => {
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {
|
||||
warn!("PUS 3 partial packet handling success: {e:?}")
|
||||
warn!("PUS 3 partial packet handling success: {e:?}");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::CustomSubservice(invalid, _) => {
|
||||
warn!("PUS 3 invalid subservice {invalid}");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::SubserviceNotImplemented(subservice, _) => {
|
||||
warn!("PUS 3 subservice {subservice} not implemented");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::Empty => return HandlingStatus::Empty,
|
||||
PusPacketHandlerResult::Empty => (),
|
||||
},
|
||||
Err(error) => {
|
||||
error!("PUS packet handling error: {error:?}");
|
||||
// To avoid permanent loops on error cases.
|
||||
return HandlingStatus::Empty;
|
||||
}
|
||||
}
|
||||
HandlingStatus::HandledOne
|
||||
// To avoid permanent loops, treat queue empty by default (all tasks done).
|
||||
HandlingStatus::Empty
|
||||
}
|
||||
|
||||
pub fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> HandlingStatus {
|
||||
|
@ -243,25 +243,29 @@ impl TargetedPusService for ModeServiceWrapper {
|
||||
fn poll_and_handle_next_tc(&mut self, time_stamp: &[u8]) -> HandlingStatus {
|
||||
match self.service.poll_and_handle_next_tc(time_stamp) {
|
||||
Ok(result) => match result {
|
||||
PusPacketHandlerResult::RequestHandled => {}
|
||||
PusPacketHandlerResult::RequestHandled => {
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {
|
||||
warn!("PUS mode service: partial packet handling success: {e:?}")
|
||||
warn!("PUS mode service: partial packet handling success: {e:?}");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::CustomSubservice(invalid, _) => {
|
||||
warn!("PUS mode service: invalid subservice {invalid}");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::SubserviceNotImplemented(subservice, _) => {
|
||||
warn!("PUS mode service: {subservice} not implemented");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::Empty => return HandlingStatus::Empty,
|
||||
PusPacketHandlerResult::Empty => (),
|
||||
},
|
||||
Err(error) => {
|
||||
error!("PUS mode service: packet handling error: {error:?}");
|
||||
// To avoid permanent loops on error cases.
|
||||
return HandlingStatus::Empty;
|
||||
}
|
||||
}
|
||||
HandlingStatus::HandledOne
|
||||
// To avoid permanent loops, treat queue empty by default (all tasks done).
|
||||
HandlingStatus::Empty
|
||||
}
|
||||
|
||||
fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> HandlingStatus {
|
||||
|
@ -106,23 +106,29 @@ impl SchedulingService {
|
||||
.poll_and_handle_next_tc(time_stamp, &mut self.sched_tc_pool)
|
||||
{
|
||||
Ok(result) => match result {
|
||||
PusPacketHandlerResult::RequestHandled => {}
|
||||
PusPacketHandlerResult::RequestHandled => {
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {
|
||||
warn!("PUS11 partial packet handling success: {e:?}")
|
||||
warn!("PUS11 partial packet handling success: {e:?}");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::CustomSubservice(invalid, _) => {
|
||||
warn!("PUS11 invalid subservice {invalid}");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::SubserviceNotImplemented(subservice, _) => {
|
||||
warn!("PUS11: Subservice {subservice} not implemented");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::Empty => return HandlingStatus::Empty,
|
||||
PusPacketHandlerResult::Empty => (),
|
||||
},
|
||||
Err(error) => {
|
||||
error!("PUS packet handling error: {error:?}")
|
||||
}
|
||||
}
|
||||
HandlingStatus::HandledOne
|
||||
// To avoid permanent loops, treat queue empty by default (all tasks done).
|
||||
HandlingStatus::Empty
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ impl PusStack {
|
||||
.expect("time stamp generation error")
|
||||
.to_vec()
|
||||
.unwrap();
|
||||
let mut loop_count = 0;
|
||||
loop {
|
||||
let mut nothing_to_do = true;
|
||||
let mut is_srv_finished =
|
||||
@ -69,6 +70,12 @@ impl PusStack {
|
||||
self.mode_srv.poll_and_handle_next_tc(&time_stamp),
|
||||
Some(self.mode_srv.poll_and_handle_next_reply(&time_stamp)),
|
||||
);
|
||||
// Safety mechanism to avoid infinite loops.
|
||||
loop_count += 1;
|
||||
if loop_count >= 500 {
|
||||
log::warn!("reached PUS stack loop count 500, breaking");
|
||||
break;
|
||||
}
|
||||
if nothing_to_do {
|
||||
// Timeout checking is only done once.
|
||||
self.action_srv_wrapper.check_for_request_timeouts();
|
||||
|
@ -57,15 +57,18 @@ impl TestCustomServiceWrapper {
|
||||
PusPacketHandlerResult::RequestHandled => {
|
||||
info!("Received PUS ping command TC[17,1]");
|
||||
info!("Sent ping reply PUS TM[17,2]");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::RequestHandledPartialSuccess(partial_err) => {
|
||||
warn!(
|
||||
"Handled PUS ping command with partial success: {:?}",
|
||||
partial_err
|
||||
);
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::SubserviceNotImplemented(subservice, _) => {
|
||||
warn!("PUS17: Subservice {subservice} not implemented")
|
||||
warn!("PUS17: Subservice {subservice} not implemented");
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
// TODO: adapt interface events are implemented
|
||||
PusPacketHandlerResult::CustomSubservice(subservice, token) => {
|
||||
@ -115,9 +118,11 @@ impl TestCustomServiceWrapper {
|
||||
)
|
||||
.expect("Sending start failure verification failed");
|
||||
}
|
||||
return HandlingStatus::HandledOne;
|
||||
}
|
||||
PusPacketHandlerResult::Empty => return HandlingStatus::Empty,
|
||||
PusPacketHandlerResult::Empty => (),
|
||||
}
|
||||
HandlingStatus::HandledOne
|
||||
// To avoid permanent loops, treat queue empty by default (all tasks done).
|
||||
HandlingStatus::Empty
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user