better error handling

This commit is contained in:
Robin Müller 2023-02-15 23:32:19 +01:00
parent 5cc9860a43
commit 6ac53f8322

View File

@ -526,6 +526,19 @@ impl PusReceiver {
.expect("Sending start failure TM failed"); .expect("Sending start failure TM failed");
} }
let app_data = app_data.unwrap(); let app_data = app_data.unwrap();
let mut invalid_subservice_handler = || {
self.tm_args
.verif_reporter
.start_failure(
token,
FailParams::new(
Some(self.stamp_helper.stamp()),
&tmtc_err::INVALID_PUS_SUBSERVICE,
Some(&[PusPacket::subservice(pus_tc)]),
),
)
.expect("Sending start failure TM failed");
};
let subservice = mode::Subservice::try_from(PusPacket::subservice(pus_tc)); let subservice = mode::Subservice::try_from(PusPacket::subservice(pus_tc));
if let Ok(subservice) = subservice { if let Ok(subservice) = subservice {
let forward_mode_request = |target_id, mode_request: ModeRequest| match self let forward_mode_request = |target_id, mode_request: ModeRequest| match self
@ -540,6 +553,7 @@ impl PusReceiver {
.expect("sending mode request failed"); .expect("sending mode request failed");
} }
}; };
let mut valid_subservice = true;
match subservice { match subservice {
Subservice::TcSetMode => { Subservice::TcSetMode => {
let target_id = u32::from_be_bytes(app_data[0..4].try_into().unwrap()); let target_id = u32::from_be_bytes(app_data[0..4].try_into().unwrap());
@ -585,21 +599,19 @@ impl PusReceiver {
forward_mode_request(target_id, ModeRequest::AnnounceModeRecursive(target_id)); forward_mode_request(target_id, ModeRequest::AnnounceModeRecursive(target_id));
} }
_ => { _ => {
warn!("Can not process mode request with subservice {subservice:?}") warn!("Can not process mode request with subservice {subservice:?}");
invalid_subservice_handler();
valid_subservice = false;
} }
} }
} else { if valid_subservice {
self.tm_args self.tm_args
.verif_reporter .verif_reporter
.start_failure( .start_success(token, Some(self.stamp_helper.stamp()))
token, .expect("sending start success TM failed");
FailParams::new( }
Some(self.stamp_helper.stamp()), } else {
&tmtc_err::INVALID_PUS_SUBSERVICE, invalid_subservice_handler();
Some(&[PusPacket::subservice(pus_tc)]),
),
)
.expect("Sending start failure TM failed");
} }
} }
} }