From 86f6ed8b15a45a3a7c0aa9070568804f8c6a819d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 17 Feb 2024 20:53:37 +0100 Subject: [PATCH] prepare satrs-shared release --- satrs-example/src/acs.rs | 4 +- satrs-example/src/events.rs | 2 +- satrs-example/src/pus/action.rs | 4 +- satrs-example/src/pus/hk.rs | 27 ++-- satrs-example/src/pus/mod.rs | 32 +++-- satrs-example/src/pus/test.rs | 8 +- satrs-mib/Cargo.toml | 1 + satrs-shared/CHANGELOG.md | 4 + satrs-shared/Cargo.toml | 3 +- satrs/src/pus/action.rs | 45 ++++++- satrs/src/pus/event_srv.rs | 2 +- satrs/src/pus/mod.rs | 9 +- satrs/src/pus/scheduler_srv.rs | 16 +-- satrs/src/pus/test.rs | 4 +- satrs/src/pus/verification.rs | 220 +++++++++++++++----------------- satrs/tests/pus_verification.rs | 18 +-- 16 files changed, 208 insertions(+), 191 deletions(-) diff --git a/satrs-example/src/acs.rs b/satrs-example/src/acs.rs index c69b164..5c400f7 100644 --- a/satrs-example/src/acs.rs +++ b/satrs-example/src/acs.rs @@ -90,10 +90,10 @@ impl AcsTask { } let started_token = self .verif_reporter - .start_success(request.token, Some(&self.timestamp)) + .start_success(request.token, &self.timestamp) .expect("Sending start success failed"); self.verif_reporter - .completion_success(started_token, Some(&self.timestamp)) + .completion_success(started_token, &self.timestamp) .expect("Sending completion success failed"); true } diff --git a/satrs-example/src/events.rs b/satrs-example/src/events.rs index f1c3286..46ba6bb 100644 --- a/satrs-example/src/events.rs +++ b/satrs-example/src/events.rs @@ -76,7 +76,7 @@ impl PusEventHandler { .try_into() .expect("expected start verification token"); self.verif_handler - .completion_success(started_token, Some(timestamp)) + .completion_success(started_token, timestamp) .expect("Sending completion success failed"); }; // handle event requests diff --git a/satrs-example/src/pus/action.rs b/satrs-example/src/pus/action.rs index fd196dd..6338c23 100644 --- a/satrs-example/src/pus/action.rs +++ b/satrs-example/src/pus/action.rs @@ -42,7 +42,7 @@ impl PusActionToRequestConverter for ExampleActionRequestConverter { verif_reporter .start_failure( token, - FailParams::new(Some(time_stamp), &tmtc_err::NOT_ENOUGH_APP_DATA, None), + FailParams::new_no_fail_data(time_stamp, &tmtc_err::NOT_ENOUGH_APP_DATA), ) .expect("Sending start failure failed"); return Err(PusPacketHandlingError::NotEnoughAppData( @@ -63,7 +63,7 @@ impl PusActionToRequestConverter for ExampleActionRequestConverter { verif_reporter .start_failure( token, - FailParams::new(Some(time_stamp), &tmtc_err::INVALID_PUS_SUBSERVICE, None), + FailParams::new_no_fail_data(time_stamp, &tmtc_err::INVALID_PUS_SUBSERVICE), ) .expect("Sending start failure failed"); Err(PusPacketHandlingError::InvalidSubservice(subservice)) diff --git a/satrs-example/src/pus/hk.rs b/satrs-example/src/pus/hk.rs index f82c89a..1dd82c0 100644 --- a/satrs-example/src/pus/hk.rs +++ b/satrs-example/src/pus/hk.rs @@ -38,10 +38,16 @@ impl PusHkToRequestConverter for ExampleHkRequestConverter { ) -> Result<(TargetId, HkRequest), Self::Error> { let user_data = tc.user_data(); if user_data.is_empty() { + let user_data_len = user_data.len() as u32; + let user_data_len_raw = user_data_len.to_be_bytes(); verif_reporter .start_failure( token, - FailParams::new(Some(time_stamp), &tmtc_err::NOT_ENOUGH_APP_DATA, None), + FailParams::new( + time_stamp, + &tmtc_err::NOT_ENOUGH_APP_DATA, + &user_data_len_raw, + ), ) .expect("Sending start failure TM failed"); return Err(PusPacketHandlingError::NotEnoughAppData( @@ -54,8 +60,10 @@ impl PusHkToRequestConverter for ExampleHkRequestConverter { } else { &hk_err::UNIQUE_ID_MISSING }; + let user_data_len = user_data.len() as u32; + let user_data_len_raw = user_data_len.to_be_bytes(); verif_reporter - .start_failure(token, FailParams::new(Some(time_stamp), err, None)) + .start_failure(token, FailParams::new(time_stamp, err, &user_data_len_raw)) .expect("Sending start failure TM failed"); return Err(PusPacketHandlingError::NotEnoughAppData( "Expected at least 8 bytes of app data".into(), @@ -70,11 +78,7 @@ impl PusHkToRequestConverter for ExampleHkRequestConverter { verif_reporter .start_failure( token, - FailParams::new( - Some(time_stamp), - &tmtc_err::INVALID_PUS_SUBSERVICE, - Some(&[subservice]), - ), + FailParams::new(time_stamp, &tmtc_err::INVALID_PUS_SUBSERVICE, &[subservice]), ) .expect("Sending start failure TM failed"); return Err(PusPacketHandlingError::InvalidSubservice(subservice)); @@ -99,10 +103,9 @@ impl PusHkToRequestConverter for ExampleHkRequestConverter { verif_reporter .start_failure( token, - FailParams::new( - Some(time_stamp), + FailParams::new_no_fail_data( + time_stamp, &tmtc_err::NOT_ENOUGH_APP_DATA, - None, ), ) .expect("Sending start failure TM failed"); @@ -122,9 +125,9 @@ impl PusHkToRequestConverter for ExampleHkRequestConverter { .start_failure( token, FailParams::new( - Some(time_stamp), + time_stamp, &tmtc_err::PUS_SUBSERVICE_NOT_IMPLEMENTED, - Some(&[subservice]), + &[subservice], ), ) .expect("Sending start failure TM failed"); diff --git a/satrs-example/src/pus/mod.rs b/satrs-example/src/pus/mod.rs index 5688492..ffa5988 100644 --- a/satrs-example/src/pus/mod.rs +++ b/satrs-example/src/pus/mod.rs @@ -82,7 +82,7 @@ impl PusReceiver { self.stamp_helper.update_from_now(); let accepted_token = self .verif_reporter - .acceptance_success(init_token, Some(self.stamp_helper.stamp())) + .acceptance_success(init_token, self.stamp_helper.stamp()) .expect("Acceptance success failure"); let service = PusServiceId::try_from(service); match service { @@ -119,9 +119,9 @@ impl PusReceiver { let result = self.verif_reporter.start_failure( accepted_token, FailParams::new( - Some(self.stamp_helper.stamp()), + self.stamp_helper.stamp(), &tmtc_err::PUS_SERVICE_NOT_IMPLEMENTED, - Some(&[standard_service as u8]), + &[standard_service as u8], ), ); if result.is_err() { @@ -143,9 +143,9 @@ impl PusReceiver { .start_failure( accepted_token, FailParams::new( - Some(self.stamp_helper.stamp()), + self.stamp_helper.stamp(), &tmtc_err::INVALID_PUS_SUBSERVICE, - Some(&[e.number]), + &[e.number], ), ) .expect("Start failure verification failed") @@ -168,7 +168,7 @@ impl PusRoutingErrorHandler for GenericRoutingErrorHandler token: satrs::pus::verification::VerificationToken< satrs::pus::verification::TcStateAccepted, >, - _tc: &PusTcReader, + tc: &PusTcReader, error: Self::Error, time_stamp: &[u8], verif_reporter: &impl VerificationReportingProvider, @@ -181,11 +181,7 @@ impl PusRoutingErrorHandler for GenericRoutingErrorHandler verif_reporter .start_failure( token, - FailParams::new( - Some(time_stamp), - &tmtc_err::UNKNOWN_TARGET_ID, - Some(&fail_data), - ), + FailParams::new(time_stamp, &tmtc_err::UNKNOWN_TARGET_ID, &fail_data), ) .expect("Sending start failure failed"); } @@ -195,19 +191,21 @@ impl PusRoutingErrorHandler for GenericRoutingErrorHandler verif_reporter .start_failure( token, - FailParams::new( - Some(time_stamp), - &tmtc_err::ROUTING_ERROR, - Some(&fail_data), - ), + FailParams::new(time_stamp, &tmtc_err::ROUTING_ERROR, &fail_data), ) .expect("Sending start failure failed"); } GenericRoutingError::NotEnoughAppData => { + let app_data_len = tc.app_data().len() as u32; + let app_data_len_raw = app_data_len.to_be_bytes(); verif_reporter .start_failure( token, - FailParams::new(Some(time_stamp), &tmtc_err::NOT_ENOUGH_APP_DATA, None), + FailParams::new( + time_stamp, + &tmtc_err::NOT_ENOUGH_APP_DATA, + &app_data_len_raw, + ), ) .expect("Sending start failure failed"); } diff --git a/satrs-example/src/pus/test.rs b/satrs-example/src/pus/test.rs index ab308a7..fe52af7 100644 --- a/satrs-example/src/pus/test.rs +++ b/satrs-example/src/pus/test.rs @@ -127,13 +127,13 @@ impl Service17CustomWrapper Service17CustomWrapper"] homepage = "https://absatsw.irs.uni-stuttgart.de/projects/sat-rs/" @@ -19,7 +19,6 @@ optional = true [dependencies.spacepackets] version = "0.10" -git = "https://github.com/us-irs/spacepackets-rs.git" default-features = false [features] diff --git a/satrs/src/pus/action.rs b/satrs/src/pus/action.rs index 936a694..77c2050 100644 --- a/satrs/src/pus/action.rs +++ b/satrs/src/pus/action.rs @@ -171,20 +171,25 @@ mod tests { use delegate::delegate; use alloc::{collections::VecDeque, vec::Vec}; + use satrs_shared::res_code::ResultU16; use spacepackets::{ ecss::{ - tc::{PusTcCreator, PusTcReader}, + tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader}, tm::PusTmReader, PusPacket, }, - CcsdsPacket, + CcsdsPacket, SequenceFlags, SpHeader, }; use crate::pus::{ - tests::{PusServiceHandlerWithVecCommon, PusTestHarness, SimplePusPacketHandler}, - verification::{tests::TestVerificationReporter, RequestId, VerificationReportingProvider}, + tests::{ + PusServiceHandlerWithVecCommon, PusTestHarness, SimplePusPacketHandler, TEST_APID, + }, + verification::{ + tests::TestVerificationReporter, FailParams, RequestId, VerificationReportingProvider, + }, EcssTcInVecConverter, GenericRoutingError, PusPacketHandlerResult, PusPacketHandlingError, - PusRoutingErrorHandler, PusServiceHelper, + PusRoutingErrorHandler, }; use super::*; @@ -234,6 +239,8 @@ mod tests { pub conversion_request: VecDeque>, } + const APP_DATA_TOO_SHORT: ResultU16 = ResultU16::new(1, 1); + impl PusActionToRequestConverter for TestConverter { type Error = PusPacketHandlingError; fn convert( @@ -245,9 +252,24 @@ mod tests { ) -> Result<(TargetId, ActionRequest), Self::Error> { self.conversion_request.push_back(tc.raw_data().to_vec()); let target_id = tc.apid(); + if tc.user_data().len() < 4 { + verif_reporter + .start_failure( + token, + FailParams::new( + time_stamp, + &APP_DATA_TOO_SHORT, + (tc.user_data().len() as u32).to_be_bytes().as_ref(), + ), + ) + .expect("start success failure"); + return Err(PusPacketHandlingError::NotEnoughAppData( + "user data too short".into(), + )); + } if tc.subservice() == 1 { verif_reporter - .start_success(token, Some(time_stamp)) + .start_success(token, time_stamp) .expect("start success failure"); return Ok(( target_id.into(), @@ -314,6 +336,15 @@ mod tests { #[test] fn basic_test() { - let _action_handler = Pus8HandlerWithVecTester::new(); + let mut action_handler = Pus8HandlerWithVecTester::new(); + let mut sp_header = SpHeader::tc(TEST_APID, SequenceFlags::Unsegmented, 0, 0).unwrap(); + let sec_header = PusTcSecondaryHeader::new_simple(8, 1); + let action_id: u32 = 1; + let action_id_raw = action_id.to_be_bytes(); + let tc = PusTcCreator::new(&mut sp_header, sec_header, action_id_raw.as_ref(), true); + let token = action_handler.send_tc(&tc); + let request_id = token.req_id(); + let result = action_handler.handle_one_tc(); + assert!(result.is_ok()); } } diff --git a/satrs/src/pus/event_srv.rs b/satrs/src/pus/event_srv.rs index fbb9079..0987e6b 100644 --- a/satrs/src/pus/event_srv.rs +++ b/satrs/src/pus/event_srv.rs @@ -62,7 +62,7 @@ impl< .service_helper .common .verification_handler - .start_success(ecss_tc_and_token.token, Some(&stamp)) + .start_success(ecss_tc_and_token.token, &stamp) .map_err(|_| PartialPusHandlingError::Verification); let partial_error = start_token.clone().err(); let mut token: TcStateToken = ecss_tc_and_token.token.into(); diff --git a/satrs/src/pus/mod.rs b/satrs/src/pus/mod.rs index aa83876..b6ea08f 100644 --- a/satrs/src/pus/mod.rs +++ b/satrs/src/pus/mod.rs @@ -947,7 +947,7 @@ pub mod tests { use crate::pus::verification::RequestId; use crate::tmtc::tm_helper::SharedTmPool; - use super::verification::tests::TestVerificationReporter; + use super::verification::tests::{SharedVerificationMap, TestVerificationReporter}; use super::verification::{ TcStateAccepted, VerificationReporterCfg, VerificationReporterWithSender, VerificationReportingProvider, VerificationToken, @@ -1059,7 +1059,7 @@ pub mod tests { let token = self.verification_handler.add_tc(tc); let token = self .verification_handler - .acceptance_success(token, Some(&[0; 7])) + .acceptance_success(token, &[0; 7]) .unwrap(); let tc_size = tc.write_to_bytes(&mut self.pus_buf).unwrap(); let mut tc_pool = self.tc_pool.write().unwrap(); @@ -1158,7 +1158,8 @@ pub mod tests { let test_srv_tm_sender = MpscTmAsVecSender::new(0, "test-sender", tm_tx); let test_srv_tc_receiver = MpscTcReceiver::new(0, "test-receiver", test_srv_tc_rx); let in_store_converter = EcssTcInVecConverter::default(); - let verification_handler = TestVerificationReporter::default(); + let shared_verif_map = SharedVerificationMap::default(); + let verification_handler = TestVerificationReporter::new(shared_verif_map); ( Self { current_tm: None, @@ -1184,7 +1185,7 @@ pub mod tests { let token = self.verification_handler.add_tc(tc); let token = self .verification_handler - .acceptance_success(token, Some(&[0; 7])) + .acceptance_success(token, &[0; 7]) .unwrap(); // Send accepted TC to test service handler. self.tc_sender diff --git a/satrs/src/pus/scheduler_srv.rs b/satrs/src/pus/scheduler_srv.rs index fc66667..72e8a7b 100644 --- a/satrs/src/pus/scheduler_srv.rs +++ b/satrs/src/pus/scheduler_srv.rs @@ -79,7 +79,7 @@ impl< .service_helper .common .verification_handler - .start_success(ecss_tc_and_token.token, Some(&time_stamp)) + .start_success(ecss_tc_and_token.token, &time_stamp) .expect("Error sending start success"); self.scheduler.enable(); @@ -87,7 +87,7 @@ impl< self.service_helper .common .verification_handler - .completion_success(start_token, Some(&time_stamp)) + .completion_success(start_token, &time_stamp) .expect("Error sending completion success"); } else { return Err(PusPacketHandlingError::Other( @@ -100,7 +100,7 @@ impl< .service_helper .common .verification_handler - .start_success(ecss_tc_and_token.token, Some(&time_stamp)) + .start_success(ecss_tc_and_token.token, &time_stamp) .expect("Error sending start success"); self.scheduler.disable(); @@ -108,7 +108,7 @@ impl< self.service_helper .common .verification_handler - .completion_success(start_token, Some(&time_stamp)) + .completion_success(start_token, &time_stamp) .expect("Error sending completion success"); } else { return Err(PusPacketHandlingError::Other( @@ -121,7 +121,7 @@ impl< .service_helper .common .verification_handler - .start_success(ecss_tc_and_token.token, Some(&time_stamp)) + .start_success(ecss_tc_and_token.token, &time_stamp) .expect("Error sending start success"); self.scheduler @@ -131,7 +131,7 @@ impl< self.service_helper .common .verification_handler - .completion_success(start_token, Some(&time_stamp)) + .completion_success(start_token, &time_stamp) .expect("Error sending completion success"); } scheduling::Subservice::TcInsertActivity => { @@ -139,7 +139,7 @@ impl< .service_helper .common .verification_handler - .start_success(ecss_tc_and_token.token, Some(&time_stamp)) + .start_success(ecss_tc_and_token.token, &time_stamp) .expect("error sending start success"); // let mut pool = self.sched_tc_pool.write().expect("locking pool failed"); @@ -150,7 +150,7 @@ impl< self.service_helper .common .verification_handler - .completion_success(start_token, Some(&time_stamp)) + .completion_success(start_token, &time_stamp) .expect("sending completion success failed"); } _ => { diff --git a/satrs/src/pus/test.rs b/satrs/src/pus/test.rs index c8fa1e3..bfea48b 100644 --- a/satrs/src/pus/test.rs +++ b/satrs/src/pus/test.rs @@ -49,7 +49,7 @@ impl< .service_helper .common .verification_handler - .start_success(ecss_tc_and_token.token, Some(&time_stamp)) + .start_success(ecss_tc_and_token.token, &time_stamp) .map_err(|_| PartialPusHandlingError::Verification); let start_token = if let Ok(result) = result { Some(result) @@ -77,7 +77,7 @@ impl< .service_helper .common .verification_handler - .completion_success(start_token, Some(&time_stamp)) + .completion_success(start_token, &time_stamp) .is_err() { partial_error = Some(PartialPusHandlingError::Verification) diff --git a/satrs/src/pus/verification.rs b/satrs/src/pus/verification.rs index dd7048e..369b46e 100644 --- a/satrs/src/pus/verification.rs +++ b/satrs/src/pus/verification.rs @@ -45,9 +45,9 @@ //! let init_token = reporter.add_tc(&pus_tc_0); //! //! // Complete success sequence for a telecommand -//! let accepted_token = reporter.acceptance_success(init_token, Some(&EMPTY_STAMP)).unwrap(); -//! let started_token = reporter.start_success(accepted_token, Some(&EMPTY_STAMP)).unwrap(); -//! reporter.completion_success(started_token, Some(&EMPTY_STAMP)).unwrap(); +//! let accepted_token = reporter.acceptance_success(init_token, &EMPTY_STAMP).unwrap(); +//! let started_token = reporter.start_success(accepted_token, &EMPTY_STAMP).unwrap(); +//! reporter.completion_success(started_token, &EMPTY_STAMP).unwrap(); //! //! // Verify it arrives correctly on receiver end //! let mut tm_buf: [u8; 1024] = [0; 1024]; @@ -281,16 +281,16 @@ impl VerificationToken { /// Composite helper struct to pass failure parameters to the [VerificationReporter] pub struct FailParams<'stamp, 'fargs> { - time_stamp: Option<&'stamp [u8]>, + time_stamp: &'stamp [u8], failure_code: &'fargs dyn EcssEnumeration, - failure_data: Option<&'fargs [u8]>, + failure_data: &'fargs [u8], } impl<'stamp, 'fargs> FailParams<'stamp, 'fargs> { pub fn new( - time_stamp: Option<&'stamp [u8]>, + time_stamp: &'stamp [u8], failure_code: &'fargs impl EcssEnumeration, - failure_data: Option<&'fargs [u8]>, + failure_data: &'fargs [u8], ) -> Self { Self { time_stamp, @@ -298,6 +298,13 @@ impl<'stamp, 'fargs> FailParams<'stamp, 'fargs> { failure_data, } } + + pub fn new_no_fail_data( + time_stamp: &'stamp [u8], + failure_code: &'fargs impl EcssEnumeration, + ) -> Self { + Self::new(time_stamp, failure_code, &[]) + } } /// Composite helper struct to pass step failure parameters to the [VerificationReporter] @@ -308,10 +315,10 @@ pub struct FailParamsWithStep<'stamp, 'fargs> { impl<'stamp, 'fargs> FailParamsWithStep<'stamp, 'fargs> { pub fn new( - time_stamp: Option<&'stamp [u8]>, + time_stamp: &'stamp [u8], step: &'fargs impl EcssEnumeration, failure_code: &'fargs impl EcssEnumeration, - failure_data: Option<&'fargs [u8]>, + failure_data: &'fargs [u8], ) -> Self { Self { bp: FailParams::new(time_stamp, failure_code, failure_data), @@ -414,7 +421,7 @@ pub trait VerificationReportingProvider { fn acceptance_success( &self, token: VerificationToken, - time_stamp: Option<&[u8]>, + time_stamp: &[u8], ) -> Result, VerificationOrSendErrorWithToken>; fn acceptance_failure( @@ -426,7 +433,7 @@ pub trait VerificationReportingProvider { fn start_success( &self, token: VerificationToken, - time_stamp: Option<&[u8]>, + time_stamp: &[u8], ) -> Result, VerificationOrSendErrorWithToken>; fn start_failure( @@ -438,7 +445,7 @@ pub trait VerificationReportingProvider { fn step_success( &self, token: &VerificationToken, - time_stamp: Option<&[u8]>, + time_stamp: &[u8], step: impl EcssEnumeration, ) -> Result<(), EcssTmtcError>; @@ -451,7 +458,7 @@ pub trait VerificationReportingProvider { fn completion_success( &self, token: VerificationToken, - time_stamp: Option<&[u8]>, + time_stamp: &[u8], ) -> Result<(), VerificationOrSendErrorWithToken>; fn completion_failure( @@ -518,7 +525,7 @@ impl VerificationReporterCore { token: VerificationToken, seq_count: u16, msg_count: u16, - time_stamp: Option<&'src_data [u8]>, + time_stamp: &'src_data [u8], ) -> Result< VerificationSendable<'src_data, State, VerifSuccess>, VerificationErrorWithToken, @@ -575,7 +582,7 @@ impl VerificationReporterCore { token: VerificationToken, seq_count: u16, msg_count: u16, - time_stamp: Option<&'src_data [u8]>, + time_stamp: &'src_data [u8], ) -> Result< VerificationSendable<'src_data, TcStateNone, VerifSuccess>, VerificationErrorWithToken, @@ -646,7 +653,7 @@ impl VerificationReporterCore { token: VerificationToken, seq_count: u16, msg_count: u16, - time_stamp: Option<&'src_data [u8]>, + time_stamp: &'src_data [u8], ) -> Result< VerificationSendable<'src_data, TcStateAccepted, VerifSuccess>, VerificationErrorWithToken, @@ -720,7 +727,7 @@ impl VerificationReporterCore { token: &VerificationToken, seq_count: u16, msg_count: u16, - time_stamp: Option<&'src_data [u8]>, + time_stamp: &'src_data [u8], step: impl EcssEnumeration, ) -> Result, EcssTmtcError> { Ok(VerificationSendable::new_no_token( @@ -776,7 +783,7 @@ impl VerificationReporterCore { token: VerificationToken, seq_counter: u16, msg_counter: u16, - time_stamp: Option<&'src_data [u8]>, + time_stamp: &'src_data [u8], ) -> Result< VerificationSendable<'src_data, TcState, VerifSuccess>, VerificationErrorWithToken, @@ -850,7 +857,7 @@ impl VerificationReporterCore { seq_count: u16, msg_counter: u16, req_id: &RequestId, - time_stamp: Option<&'src_data [u8]>, + time_stamp: &'src_data [u8], step: Option<&(impl EcssEnumeration + ?Sized)>, ) -> Result, EcssTmtcError> { let mut source_data_len = size_of::(); @@ -894,9 +901,7 @@ impl VerificationReporterCore { if let Some(step) = step { source_data_len += step.size(); } - if let Some(failure_data) = params.failure_data { - source_data_len += failure_data.len(); - } + source_data_len += params.failure_data.len(); source_buffer_large_enough(src_data_buf.len(), source_data_len)?; req_id.to_bytes(&mut src_data_buf[0..RequestId::SIZE_AS_BYTES]); idx += RequestId::SIZE_AS_BYTES; @@ -911,9 +916,7 @@ impl VerificationReporterCore { .write_to_be_bytes(&mut src_data_buf[idx..idx + params.failure_code.size()]) .map_err(PusError::ByteConversion)?; idx += params.failure_code.size(); - if let Some(failure_data) = params.failure_data { - src_data_buf[idx..idx + failure_data.len()].copy_from_slice(failure_data); - } + src_data_buf[idx..idx + params.failure_data.len()].copy_from_slice(params.failure_data); let mut sp_header = SpHeader::tm_unseg(self.apid(), seq_count, 0).unwrap(); Ok(self.create_pus_verif_tm_base( src_data_buf, @@ -931,11 +934,11 @@ impl VerificationReporterCore { subservice: u8, msg_counter: u16, sp_header: &mut SpHeader, - time_stamp: Option<&'src_data [u8]>, + time_stamp: &'src_data [u8], source_data_len: usize, ) -> PusTmCreator<'src_data> { let tm_sec_header = - PusTmSecondaryHeader::new(1, subservice, msg_counter, self.dest_id, time_stamp); + PusTmSecondaryHeader::new(1, subservice, msg_counter, self.dest_id, Some(time_stamp)); PusTmCreator::new( sp_header, tm_sec_header, @@ -1032,7 +1035,7 @@ mod alloc_mod { &self, token: VerificationToken, sender: &(impl EcssTmSenderCore + ?Sized), - time_stamp: Option<&[u8]>, + time_stamp: &[u8], ) -> Result, VerificationOrSendErrorWithToken> { let seq_count = self @@ -1087,7 +1090,7 @@ mod alloc_mod { &self, token: VerificationToken, sender: &(impl EcssTmSenderCore + ?Sized), - time_stamp: Option<&[u8]>, + time_stamp: &[u8], ) -> Result< VerificationToken, VerificationOrSendErrorWithToken, @@ -1147,7 +1150,7 @@ mod alloc_mod { &self, token: &VerificationToken, sender: &(impl EcssTmSenderCore + ?Sized), - time_stamp: Option<&[u8]>, + time_stamp: &[u8], step: impl EcssEnumeration, ) -> Result<(), EcssTmtcError> { let seq_count = self @@ -1210,7 +1213,7 @@ mod alloc_mod { &self, token: VerificationToken, sender: &(impl EcssTmSenderCore + ?Sized), - time_stamp: Option<&[u8]>, + time_stamp: &[u8], ) -> Result<(), VerificationOrSendErrorWithToken> { let seq_count = self .seq_count_provider @@ -1308,7 +1311,7 @@ mod alloc_mod { fn acceptance_success( &self, token: VerificationToken, - time_stamp: Option<&[u8]>, + time_stamp: &[u8], ) -> Result, VerificationOrSendErrorWithToken> { self.reporter @@ -1327,7 +1330,7 @@ mod alloc_mod { fn start_success( &self, token: VerificationToken, - time_stamp: Option<&[u8]>, + time_stamp: &[u8], ) -> Result< VerificationToken, VerificationOrSendErrorWithToken, @@ -1348,7 +1351,7 @@ mod alloc_mod { fn step_success( &self, token: &VerificationToken, - time_stamp: Option<&[u8]>, + time_stamp: &[u8], step: impl EcssEnumeration, ) -> Result<(), EcssTmtcError> { self.reporter @@ -1367,7 +1370,7 @@ mod alloc_mod { fn completion_success( &self, token: VerificationToken, - time_stamp: Option<&[u8]>, + time_stamp: &[u8], ) -> Result<(), VerificationOrSendErrorWithToken> { self.reporter .completion_success(token, self.sender.as_ref(), time_stamp) @@ -1437,9 +1440,17 @@ pub mod tests { pub fail_enum: Option, } - #[derive(Default, Clone)] + pub type SharedVerificationMap = Arc>>>; + + #[derive(Clone)] pub struct TestVerificationReporter { - pub verification_map: Arc>>>, + pub verification_map: SharedVerificationMap, + } + + impl TestVerificationReporter { + pub fn new(verification_map: SharedVerificationMap) -> Self { + Self { verification_map } + } } impl VerificationReportingProvider for TestVerificationReporter { @@ -1466,7 +1477,7 @@ pub mod tests { fn acceptance_success( &self, token: VerificationToken, - _time_stamp: Option<&[u8]>, + _time_stamp: &[u8], ) -> Result< VerificationToken, super::VerificationOrSendErrorWithToken, @@ -1494,7 +1505,7 @@ pub mod tests { match verif_map.borrow_mut().get_mut(&token.req_id) { Some(entry) => { entry.accepted = Some(false); - entry.failure_data = params.failure_data.map(|v| v.to_vec()); + entry.failure_data = Some(params.failure_data.to_vec()); entry.fail_enum = Some(params.failure_code.value()); } None => panic!( @@ -1508,7 +1519,7 @@ pub mod tests { fn start_success( &self, token: VerificationToken, - _time_stamp: Option<&[u8]>, + _time_stamp: &[u8], ) -> Result< VerificationToken, super::VerificationOrSendErrorWithToken, @@ -1533,7 +1544,7 @@ pub mod tests { match verif_map.borrow_mut().get_mut(&token.req_id) { Some(entry) => { entry.started = Some(false); - entry.failure_data = params.failure_data.map(|v| v.to_vec()); + entry.failure_data = Some(params.failure_data.to_vec()); entry.fail_enum = Some(params.failure_code.value()); } None => panic!("unexpected start failure for request ID {}", token.req_id()), @@ -1544,7 +1555,7 @@ pub mod tests { fn step_success( &self, token: &VerificationToken, - _time_stamp: Option<&[u8]>, + _time_stamp: &[u8], step: impl spacepackets::ecss::EcssEnumeration, ) -> Result<(), EcssTmtcError> { let verif_map = self.verification_map.lock().unwrap(); @@ -1576,7 +1587,7 @@ pub mod tests { fn completion_success( &self, token: VerificationToken, - _time_stamp: Option<&[u8]>, + _time_stamp: &[u8], ) -> Result<(), super::VerificationOrSendErrorWithToken> { let verif_map = self.verification_map.lock().unwrap(); match verif_map.borrow_mut().get_mut(&token.req_id) { @@ -1598,7 +1609,7 @@ pub mod tests { match verif_map.borrow_mut().get_mut(&token.req_id) { Some(entry) => { entry.completed = Some(false); - entry.failure_data = params.failure_data.map(|v| v.to_vec()); + entry.failure_data = Some(params.failure_data.to_vec()); entry.fail_enum = Some(params.failure_code.value()); } None => panic!( @@ -1763,7 +1774,7 @@ pub mod tests { fn test_basic_acceptance_success() { let (b, tok) = base_init(false); let mut sender = TestSender::default(); - b.vr.acceptance_success(tok, &sender, Some(&EMPTY_STAMP)) + b.vr.acceptance_success(tok, &sender, &EMPTY_STAMP) .expect("Sending acceptance success failed"); acceptance_check(&mut sender, &tok.req_id); } @@ -1772,7 +1783,7 @@ pub mod tests { fn test_basic_acceptance_success_with_helper() { let (mut b, tok) = base_with_helper_init(); b.helper - .acceptance_success(tok, Some(&EMPTY_STAMP)) + .acceptance_success(tok, &EMPTY_STAMP) .expect("Sending acceptance success failed"); let sender: &mut TestSender = b.helper.sender.downcast_mut().unwrap(); acceptance_check(sender, &tok.req_id); @@ -1803,7 +1814,7 @@ pub mod tests { let stamp_buf = [1, 2, 3, 4, 5, 6, 7]; let mut sender = TestSender::default(); let fail_code = EcssEnumU16::new(2); - let fail_params = FailParams::new(Some(stamp_buf.as_slice()), &fail_code, None); + let fail_params = FailParams::new_no_fail_data(stamp_buf.as_slice(), &fail_code); b.vr.acceptance_failure(tok, &sender, fail_params) .expect("Sending acceptance success failed"); acceptance_fail_check(&mut sender, tok.req_id, stamp_buf); @@ -1815,7 +1826,7 @@ pub mod tests { b.rep().reporter.dest_id = 5; let stamp_buf = [1, 2, 3, 4, 5, 6, 7]; let fail_code = EcssEnumU16::new(2); - let fail_params = FailParams::new(Some(stamp_buf.as_slice()), &fail_code, None); + let fail_params = FailParams::new_no_fail_data(stamp_buf.as_slice(), &fail_code); b.helper .acceptance_failure(tok, fail_params) .expect("Sending acceptance success failed"); @@ -1832,11 +1843,7 @@ pub mod tests { let fail_data: [u8; 16] = [0; 16]; // 4 req ID + 1 byte step + 2 byte error code + 8 byte fail data assert_eq!(b.rep().allowed_source_data_len(), 15); - let fail_params = FailParams::new( - Some(stamp_buf.as_slice()), - &fail_code, - Some(fail_data.as_slice()), - ); + let fail_params = FailParams::new(stamp_buf.as_slice(), &fail_code, fail_data.as_slice()); let res = b.helper.acceptance_failure(tok, fail_params); assert!(res.is_err()); let err_with_token = res.unwrap_err(); @@ -1868,11 +1875,7 @@ pub mod tests { let fail_data = EcssEnumU32::new(12); let mut fail_data_raw = [0; 4]; fail_data.write_to_be_bytes(&mut fail_data_raw).unwrap(); - let fail_params = FailParams::new( - Some(&EMPTY_STAMP), - &fail_code, - Some(fail_data_raw.as_slice()), - ); + let fail_params = FailParams::new(&EMPTY_STAMP, &fail_code, fail_data_raw.as_slice()); b.vr.acceptance_failure(tok, &sender, fail_params) .expect("Sending acceptance success failed"); let cmp_info = TmInfo { @@ -1932,14 +1935,10 @@ pub mod tests { let fail_data: i32 = -12; let mut fail_data_raw = [0; 4]; fail_data_raw.copy_from_slice(fail_data.to_be_bytes().as_slice()); - let fail_params = FailParams::new( - Some(&EMPTY_STAMP), - &fail_code, - Some(fail_data_raw.as_slice()), - ); + let fail_params = FailParams::new(&EMPTY_STAMP, &fail_code, fail_data_raw.as_slice()); let accepted_token = - b.vr.acceptance_success(tok, &sender, Some(&EMPTY_STAMP)) + b.vr.acceptance_success(tok, &sender, &EMPTY_STAMP) .expect("Sending acceptance success failed"); b.vr.start_failure(accepted_token, &sender, fail_params) .expect("Start failure failure"); @@ -1953,15 +1952,11 @@ pub mod tests { let fail_data: i32 = -12; let mut fail_data_raw = [0; 4]; fail_data_raw.copy_from_slice(fail_data.to_be_bytes().as_slice()); - let fail_params = FailParams::new( - Some(&EMPTY_STAMP), - &fail_code, - Some(fail_data_raw.as_slice()), - ); + let fail_params = FailParams::new(&EMPTY_STAMP, &fail_code, fail_data_raw.as_slice()); let accepted_token = b .helper - .acceptance_success(tok, Some(&EMPTY_STAMP)) + .acceptance_success(tok, &EMPTY_STAMP) .expect("Sending acceptance success failed"); b.helper .start_failure(accepted_token, fail_params) @@ -2032,27 +2027,17 @@ pub mod tests { let mut sender = TestSender::default(); let accepted_token = b .rep() - .acceptance_success(tok, &sender, Some(&EMPTY_STAMP)) + .acceptance_success(tok, &sender, &EMPTY_STAMP) .expect("Sending acceptance success failed"); let started_token = b .rep() - .start_success(accepted_token, &sender, Some(&[0, 1, 0, 1, 0, 1, 0])) + .start_success(accepted_token, &sender, &[0, 1, 0, 1, 0, 1, 0]) .expect("Sending start success failed"); b.rep() - .step_success( - &started_token, - &sender, - Some(&EMPTY_STAMP), - EcssEnumU8::new(0), - ) + .step_success(&started_token, &sender, &EMPTY_STAMP, EcssEnumU8::new(0)) .expect("Sending step 0 success failed"); - b.vr.step_success( - &started_token, - &sender, - Some(&EMPTY_STAMP), - EcssEnumU8::new(1), - ) - .expect("Sending step 1 success failed"); + b.vr.step_success(&started_token, &sender, &EMPTY_STAMP, EcssEnumU8::new(1)) + .expect("Sending step 1 success failed"); assert_eq!(sender.service_queue.borrow().len(), 4); step_success_check(&mut sender, tok.req_id); } @@ -2062,17 +2047,17 @@ pub mod tests { let (mut b, tok) = base_with_helper_init(); let accepted_token = b .helper - .acceptance_success(tok, Some(&EMPTY_STAMP)) + .acceptance_success(tok, &EMPTY_STAMP) .expect("Sending acceptance success failed"); let started_token = b .helper - .start_success(accepted_token, Some(&[0, 1, 0, 1, 0, 1, 0])) + .start_success(accepted_token, &[0, 1, 0, 1, 0, 1, 0]) .expect("Sending start success failed"); b.helper - .step_success(&started_token, Some(&EMPTY_STAMP), EcssEnumU8::new(0)) + .step_success(&started_token, &EMPTY_STAMP, EcssEnumU8::new(0)) .expect("Sending step 0 success failed"); b.helper - .step_success(&started_token, Some(&EMPTY_STAMP), EcssEnumU8::new(1)) + .step_success(&started_token, &EMPTY_STAMP, EcssEnumU8::new(1)) .expect("Sending step 1 success failed"); let sender: &mut TestSender = b.helper.sender.downcast_mut().unwrap(); assert_eq!(sender.service_queue.borrow().len(), 4); @@ -2157,25 +2142,20 @@ pub mod tests { fail_data_raw.copy_from_slice(fail_data.to_be_bytes().as_slice()); let fail_step = EcssEnumU8::new(1); let fail_params = FailParamsWithStep::new( - Some(&EMPTY_STAMP), + &EMPTY_STAMP, &fail_step, &fail_code, - Some(fail_data_raw.as_slice()), + fail_data_raw.as_slice(), ); let accepted_token = - b.vr.acceptance_success(tok, &sender, Some(&EMPTY_STAMP)) + b.vr.acceptance_success(tok, &sender, &EMPTY_STAMP) .expect("Sending acceptance success failed"); let started_token = - b.vr.start_success(accepted_token, &sender, Some(&[0, 1, 0, 1, 0, 1, 0])) + b.vr.start_success(accepted_token, &sender, &[0, 1, 0, 1, 0, 1, 0]) .expect("Sending start success failed"); - b.vr.step_success( - &started_token, - &sender, - Some(&EMPTY_STAMP), - EcssEnumU8::new(0), - ) - .expect("Sending completion success failed"); + b.vr.step_success(&started_token, &sender, &EMPTY_STAMP, EcssEnumU8::new(0)) + .expect("Sending completion success failed"); b.vr.step_failure(started_token, &sender, fail_params) .expect("Step failure failed"); check_step_failure(&mut sender, req_id, fail_data_raw); @@ -2191,22 +2171,22 @@ pub mod tests { fail_data_raw.copy_from_slice(fail_data.to_be_bytes().as_slice()); let fail_step = EcssEnumU8::new(1); let fail_params = FailParamsWithStep::new( - Some(&EMPTY_STAMP), + &EMPTY_STAMP, &fail_step, &fail_code, - Some(fail_data_raw.as_slice()), + fail_data_raw.as_slice(), ); let accepted_token = b .helper - .acceptance_success(tok, Some(&EMPTY_STAMP)) + .acceptance_success(tok, &EMPTY_STAMP) .expect("Sending acceptance success failed"); let started_token = b .helper - .start_success(accepted_token, Some(&[0, 1, 0, 1, 0, 1, 0])) + .start_success(accepted_token, &[0, 1, 0, 1, 0, 1, 0]) .expect("Sending start success failed"); b.helper - .step_success(&started_token, Some(&EMPTY_STAMP), EcssEnumU8::new(0)) + .step_success(&started_token, &EMPTY_STAMP, EcssEnumU8::new(0)) .expect("Sending completion success failed"); b.helper .step_failure(started_token, fail_params) @@ -2267,13 +2247,13 @@ pub mod tests { let mut sender = TestSender::default(); let req_id = tok.req_id; let fail_code = EcssEnumU32::new(0x1020); - let fail_params = FailParams::new(Some(&EMPTY_STAMP), &fail_code, None); + let fail_params = FailParams::new_no_fail_data(&EMPTY_STAMP, &fail_code); let accepted_token = - b.vr.acceptance_success(tok, &sender, Some(&EMPTY_STAMP)) + b.vr.acceptance_success(tok, &sender, &EMPTY_STAMP) .expect("Sending acceptance success failed"); let started_token = - b.vr.start_success(accepted_token, &sender, Some(&[0, 1, 0, 1, 0, 1, 0])) + b.vr.start_success(accepted_token, &sender, &[0, 1, 0, 1, 0, 1, 0]) .expect("Sending start success failed"); b.vr.completion_failure(started_token, &sender, fail_params) .expect("Completion failure"); @@ -2285,15 +2265,15 @@ pub mod tests { let (mut b, tok) = base_with_helper_init(); let req_id = tok.req_id; let fail_code = EcssEnumU32::new(0x1020); - let fail_params = FailParams::new(Some(&EMPTY_STAMP), &fail_code, None); + let fail_params = FailParams::new_no_fail_data(&EMPTY_STAMP, &fail_code); let accepted_token = b .helper - .acceptance_success(tok, Some(&EMPTY_STAMP)) + .acceptance_success(tok, &EMPTY_STAMP) .expect("Sending acceptance success failed"); let started_token = b .helper - .start_success(accepted_token, Some(&[0, 1, 0, 1, 0, 1, 0])) + .start_success(accepted_token, &[0, 1, 0, 1, 0, 1, 0]) .expect("Sending start success failed"); b.helper .completion_failure(started_token, fail_params) @@ -2351,12 +2331,12 @@ pub mod tests { let (b, tok) = base_init(false); let mut sender = TestSender::default(); let accepted_token = - b.vr.acceptance_success(tok, &sender, Some(&EMPTY_STAMP)) + b.vr.acceptance_success(tok, &sender, &EMPTY_STAMP) .expect("Sending acceptance success failed"); let started_token = - b.vr.start_success(accepted_token, &sender, Some(&[0, 1, 0, 1, 0, 1, 0])) + b.vr.start_success(accepted_token, &sender, &[0, 1, 0, 1, 0, 1, 0]) .expect("Sending start success failed"); - b.vr.completion_success(started_token, &sender, Some(&EMPTY_STAMP)) + b.vr.completion_success(started_token, &sender, &EMPTY_STAMP) .expect("Sending completion success failed"); completion_success_check(&mut sender, tok.req_id); } @@ -2366,14 +2346,14 @@ pub mod tests { let (mut b, tok) = base_with_helper_init(); let accepted_token = b .helper - .acceptance_success(tok, Some(&EMPTY_STAMP)) + .acceptance_success(tok, &EMPTY_STAMP) .expect("Sending acceptance success failed"); let started_token = b .helper - .start_success(accepted_token, Some(&[0, 1, 0, 1, 0, 1, 0])) + .start_success(accepted_token, &[0, 1, 0, 1, 0, 1, 0]) .expect("Sending start success failed"); b.helper - .completion_success(started_token, Some(&EMPTY_STAMP)) + .completion_success(started_token, &EMPTY_STAMP) .expect("Sending completion success failed"); let sender: &mut TestSender = b.helper.sender.downcast_mut().unwrap(); completion_success_check(sender, tok.req_id); @@ -2399,13 +2379,13 @@ pub mod tests { // Complete success sequence for a telecommand let accepted_token = reporter - .acceptance_success(init_token, Some(&EMPTY_STAMP)) + .acceptance_success(init_token, &EMPTY_STAMP) .unwrap(); let started_token = reporter - .start_success(accepted_token, Some(&EMPTY_STAMP)) + .start_success(accepted_token, &EMPTY_STAMP) .unwrap(); reporter - .completion_success(started_token, Some(&EMPTY_STAMP)) + .completion_success(started_token, &EMPTY_STAMP) .unwrap(); // Verify it arrives correctly on receiver end diff --git a/satrs/tests/pus_verification.rs b/satrs/tests/pus_verification.rs index c777c61..dd72394 100644 --- a/satrs/tests/pus_verification.rs +++ b/satrs/tests/pus_verification.rs @@ -1,4 +1,4 @@ -//#[cfg(feature = "crossbeam")] +#[cfg(feature = "crossbeam")] pub mod crossbeam_test { use hashbrown::HashMap; use satrs::pool::{PoolProvider, PoolProviderWithGuards, StaticMemoryPool, StaticPoolConfig}; @@ -90,24 +90,24 @@ pub mod crossbeam_test { let token = reporter_with_sender_0.add_tc_with_req_id(req_id_0); let accepted_token = reporter_with_sender_0 - .acceptance_success(token, Some(&FIXED_STAMP)) + .acceptance_success(token, &FIXED_STAMP) .expect("Acceptance success failed"); // Do some start handling here let started_token = reporter_with_sender_0 - .start_success(accepted_token, Some(&FIXED_STAMP)) + .start_success(accepted_token, &FIXED_STAMP) .expect("Start success failed"); // Do some step handling here reporter_with_sender_0 - .step_success(&started_token, Some(&FIXED_STAMP), EcssEnumU8::new(0)) + .step_success(&started_token, &FIXED_STAMP, EcssEnumU8::new(0)) .expect("Start success failed"); // Finish up reporter_with_sender_0 - .step_success(&started_token, Some(&FIXED_STAMP), EcssEnumU8::new(1)) + .step_success(&started_token, &FIXED_STAMP, EcssEnumU8::new(1)) .expect("Start success failed"); reporter_with_sender_0 - .completion_success(started_token, Some(&FIXED_STAMP)) + .completion_success(started_token, &FIXED_STAMP) .expect("Completion success failed"); }); @@ -125,13 +125,13 @@ pub mod crossbeam_test { let (tc, _) = PusTcReader::new(&tc_buf[0..tc_len]).unwrap(); let token = reporter_with_sender_1.add_tc(&tc); let accepted_token = reporter_with_sender_1 - .acceptance_success(token, Some(&FIXED_STAMP)) + .acceptance_success(token, &FIXED_STAMP) .expect("Acceptance success failed"); let started_token = reporter_with_sender_1 - .start_success(accepted_token, Some(&FIXED_STAMP)) + .start_success(accepted_token, &FIXED_STAMP) .expect("Start success failed"); let fail_code = EcssEnumU16::new(2); - let params = FailParams::new(Some(&FIXED_STAMP), &fail_code, None); + let params = FailParams::new_no_fail_data(&FIXED_STAMP, &fail_code); reporter_with_sender_1 .completion_failure(started_token, params) .expect("Completion success failed");