less arguments
Some checks failed
Rust/sat-rs/pipeline/head There was a failure building this commit

This commit is contained in:
Robin Müller 2024-04-29 23:35:17 +02:00
parent 6b3fd931be
commit b675253222
Signed by: muellerr
GPG Key ID: A649FB78196E3849
2 changed files with 44 additions and 40 deletions

View File

@ -6,7 +6,7 @@ use satrs::pus::action::{
};
use satrs::pus::verification::{
handle_completion_failure_with_error_as_params, handle_step_failure_with_error_as_params,
FailParams, TcStateAccepted, TcStateStarted, VerificationReporter,
FailParamHelper, FailParams, TcStateAccepted, TcStateStarted, VerificationReporter,
VerificationReportingProvider, VerificationToken,
};
use satrs::pus::{
@ -73,10 +73,12 @@ impl PusReplyHandler<ActivePusActionRequestStd, ActionReplyPus> for ActionReplyH
tm_sender,
verif_token,
verification_handler,
timestamp,
error_code,
&mut self.fail_data_buf,
params.as_ref(),
FailParamHelper {
error_code,
params: params.as_ref(),
timestamp,
small_data_buf: &mut self.fail_data_buf,
},
)?;
if !error_propagated {
log::warn!(
@ -95,11 +97,13 @@ impl PusReplyHandler<ActivePusActionRequestStd, ActionReplyPus> for ActionReplyH
tm_sender,
verif_token,
verification_handler,
timestamp,
FailParamHelper {
error_code,
params: params.as_ref(),
timestamp,
small_data_buf: &mut self.fail_data_buf,
},
&EcssEnumU16::new(*step),
error_code,
&mut self.fail_data_buf,
params.as_ref(),
)?;
if !error_propagated {
log::warn!(

View File

@ -354,7 +354,7 @@ pub struct FailParams<'stamp, 'fargs> {
impl<'stamp, 'fargs> FailParams<'stamp, 'fargs> {
pub fn new(
time_stamp: &'stamp [u8],
failure_code: &'fargs impl EcssEnumeration,
failure_code: &'fargs dyn EcssEnumeration,
failure_data: &'fargs [u8],
) -> Self {
Self {
@ -382,7 +382,7 @@ impl<'stamp, 'fargs> FailParamsWithStep<'stamp, 'fargs> {
pub fn new(
time_stamp: &'stamp [u8],
step: &'fargs impl EcssEnumeration,
failure_code: &'fargs impl EcssEnumeration,
failure_code: &'fargs dyn EcssEnumeration,
failure_data: &'fargs [u8],
) -> Self {
Self {
@ -1172,6 +1172,13 @@ pub mod alloc_mod {
}
}
pub struct FailParamHelper<'stamp, 'fargs, 'buf, 'params> {
pub timestamp: &'stamp [u8],
pub error_code: &'fargs dyn EcssEnumeration,
pub small_data_buf: &'buf mut [u8],
pub params: Option<&'params Params>,
}
/// This helper function simplifies generating completion failures where the error data has
/// the generic [Params] type.
///
@ -1187,32 +1194,29 @@ pub fn handle_completion_failure_with_error_as_params<TcState: WasAtLeastAccepte
tm_sender: &(impl EcssTmSender + ?Sized),
verif_token: VerificationToken<TcState>,
verif_reporter: &impl VerificationReportingProvider,
timestamp: &[u8],
error_code: &impl EcssEnumeration,
small_data_buf: &mut [u8],
error_params: Option<&Params>,
helper: FailParamHelper,
) -> Result<bool, EcssTmtcError> {
let mut error_params_propagated = true;
if error_params.is_none() {
if helper.params.is_none() {
verif_reporter.completion_failure(
tm_sender,
verif_token,
FailParams::new(timestamp, error_code, &[]),
FailParams::new(helper.timestamp, helper.error_code, &[]),
)?;
return Ok(true);
}
let error_params = error_params.unwrap();
let error_params = helper.params.unwrap();
match error_params {
Params::Heapless(heapless_param) => {
heapless_param
.write_to_be_bytes(&mut small_data_buf[..heapless_param.written_len()])?;
.write_to_be_bytes(&mut helper.small_data_buf[..heapless_param.written_len()])?;
verif_reporter.completion_failure(
tm_sender,
verif_token,
FailParams::new(
timestamp,
error_code,
&small_data_buf[..heapless_param.written_len()],
helper.timestamp,
helper.error_code,
&helper.small_data_buf[..heapless_param.written_len()],
),
)?;
}
@ -1220,21 +1224,21 @@ pub fn handle_completion_failure_with_error_as_params<TcState: WasAtLeastAccepte
verif_reporter.completion_failure(
tm_sender,
verif_token,
FailParams::new(timestamp, error_code, vec),
FailParams::new(helper.timestamp, helper.error_code, vec),
)?;
}
Params::String(str) => {
verif_reporter.completion_failure(
tm_sender,
verif_token,
FailParams::new(timestamp, error_code, str.as_bytes()),
FailParams::new(helper.timestamp, helper.error_code, str.as_bytes()),
)?;
}
_ => {
verif_reporter.completion_failure(
tm_sender,
verif_token,
FailParams::new(timestamp, error_code, &[]),
FailParams::new(helper.timestamp, helper.error_code, &[]),
)?;
error_params_propagated = false;
}
@ -1244,39 +1248,35 @@ pub fn handle_completion_failure_with_error_as_params<TcState: WasAtLeastAccepte
/// This function is similar to [handle_completion_failure_with_error_as_params] but handles the
/// step failure case.
#[allow(clippy::too_many_arguments)]
pub fn handle_step_failure_with_error_as_params(
tm_sender: &(impl EcssTmSender + ?Sized),
verif_token: VerificationToken<TcStateStarted>,
verif_reporter: &impl VerificationReportingProvider,
timestamp: &[u8],
helper: FailParamHelper,
step: &impl EcssEnumeration,
error_code: &impl EcssEnumeration,
small_data_buf: &mut [u8],
error_params: Option<&Params>,
) -> Result<bool, EcssTmtcError> {
if error_params.is_none() {
if helper.params.is_none() {
verif_reporter.step_failure(
tm_sender,
verif_token,
FailParamsWithStep::new(timestamp, step, error_code, &[]),
FailParamsWithStep::new(helper.timestamp, step, helper.error_code, &[]),
)?;
return Ok(true);
}
let error_params = error_params.unwrap();
let error_params = helper.params.unwrap();
let mut error_params_propagated = true;
match error_params {
Params::Heapless(heapless_param) => {
heapless_param
.write_to_be_bytes(&mut small_data_buf[..heapless_param.written_len()])?;
.write_to_be_bytes(&mut helper.small_data_buf[..heapless_param.written_len()])?;
verif_reporter.step_failure(
tm_sender,
verif_token,
FailParamsWithStep::new(
timestamp,
helper.timestamp,
step,
error_code,
&small_data_buf[..heapless_param.written_len()],
helper.error_code,
&helper.small_data_buf[..heapless_param.written_len()],
),
)?;
}
@ -1284,21 +1284,21 @@ pub fn handle_step_failure_with_error_as_params(
verif_reporter.step_failure(
tm_sender,
verif_token,
FailParamsWithStep::new(timestamp, step, error_code, vec),
FailParamsWithStep::new(helper.timestamp, step, helper.error_code, vec),
)?;
}
Params::String(str) => {
verif_reporter.step_failure(
tm_sender,
verif_token,
FailParamsWithStep::new(timestamp, step, error_code, str.as_bytes()),
FailParamsWithStep::new(helper.timestamp, step, helper.error_code, str.as_bytes()),
)?;
}
_ => {
verif_reporter.step_failure(
tm_sender,
verif_token,
FailParamsWithStep::new(timestamp, step, error_code, &[]),
FailParamsWithStep::new(helper.timestamp, step, helper.error_code, &[]),
)?;
error_params_propagated = false;
}