changelog
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
Robin Müller 2024-04-02 20:25:20 +02:00
parent 52d16e0fe7
commit dd39b374bf
Signed by: muellerr
GPG Key ID: A649FB78196E3849
17 changed files with 268 additions and 349 deletions

View File

@ -17,7 +17,6 @@ use satrs::{
verification::{TcStateStarted, VerificationReportingProvider, VerificationToken},
},
spacepackets::time::cds::CdsTime,
ComponentId,
};
use satrs_example::config::components;
use satrs_example::config::components::PUS_EVENT_MANAGEMENT;
@ -27,7 +26,6 @@ use crate::update_time;
/// The PUS event handler subscribes for all events and converts them into ECSS PUS 5 event
/// packets. It also handles the verification completion of PUS event service requests.
pub struct PusEventHandler<TmSender: EcssTmSenderCore> {
id: ComponentId,
event_request_rx: mpsc::Receiver<EventRequestWithToken>,
pus_event_dispatcher: DefaultPusEventU32Dispatcher<()>,
pus_event_man_rx: mpsc::Receiver<(EventU32, Option<Params>)>,
@ -39,7 +37,6 @@ pub struct PusEventHandler<TmSender: EcssTmSenderCore> {
impl<TmSender: EcssTmSenderCore> PusEventHandler<TmSender> {
pub fn new(
id: ComponentId,
tm_sender: TmSender,
verif_handler: VerificationReporter,
event_manager: &mut EventManagerWithBoundedMpsc,
@ -68,7 +65,6 @@ impl<TmSender: EcssTmSenderCore> PusEventHandler<TmSender> {
event_manager.add_sender(pus_event_man_send_provider);
Self {
id,
event_request_rx,
pus_event_dispatcher,
pus_event_man_rx,
@ -86,7 +82,7 @@ impl<TmSender: EcssTmSenderCore> PusEventHandler<TmSender> {
.try_into()
.expect("expected start verification token");
self.verif_handler
.completion_success(self.id, &self.tm_sender, started_token, timestamp)
.completion_success(&self.tm_sender, started_token, timestamp)
.expect("Sending completion success failed");
};
// handle event requests
@ -169,9 +165,8 @@ impl<TmSender: EcssTmSenderCore> EventHandler<TmSender> {
) -> Self {
let mut event_man_wrapper = EventManagerWrapper::new();
let pus_event_handler = PusEventHandler::new(
PUS_EVENT_MANAGEMENT.raw(),
tm_sender,
create_verification_reporter(PUS_EVENT_MANAGEMENT.apid),
create_verification_reporter(PUS_EVENT_MANAGEMENT.id(), PUS_EVENT_MANAGEMENT.apid),
event_man_wrapper.event_manager(),
event_request_rx,
);

View File

@ -18,7 +18,6 @@ use satrs::pus::{
use satrs::request::{GenericMessage, UniqueApidTargetId};
use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::{EcssEnumU16, PusPacket};
use satrs::ComponentId;
use satrs_example::config::components::PUS_ACTION_SERVICE;
use satrs_example::config::tmtc_err;
use std::sync::mpsc;
@ -48,7 +47,6 @@ impl PusReplyHandler<ActivePusActionRequestStd, PusActionReply> for ActionReplyH
fn handle_unrequested_reply(
&mut self,
_caller_id: ComponentId,
reply: &GenericMessage<PusActionReply>,
_tm_sender: &impl EcssTmSenderCore,
) -> Result<(), Self::Error> {
@ -58,7 +56,6 @@ impl PusReplyHandler<ActivePusActionRequestStd, PusActionReply> for ActionReplyH
fn handle_reply(
&mut self,
caller_id: ComponentId,
reply: &GenericMessage<PusActionReply>,
active_request: &ActivePusActionRequestStd,
tm_sender: &(impl EcssTmSenderCore + ?Sized),
@ -76,7 +73,6 @@ impl PusReplyHandler<ActivePusActionRequestStd, PusActionReply> for ActionReplyH
fail_data_len = params.write_to_be_bytes(&mut self.fail_data_buf)?;
}
verification_handler.completion_failure(
caller_id,
tm_sender,
verif_token,
FailParams::new(time_stamp, error_code, &self.fail_data_buf[..fail_data_len]),
@ -93,7 +89,6 @@ impl PusReplyHandler<ActivePusActionRequestStd, PusActionReply> for ActionReplyH
fail_data_len = params.write_to_be_bytes(&mut self.fail_data_buf)?;
}
verification_handler.step_failure(
caller_id,
tm_sender,
verif_token,
FailParamsWithStep::new(
@ -106,17 +101,11 @@ impl PusReplyHandler<ActivePusActionRequestStd, PusActionReply> for ActionReplyH
true
}
ActionReplyVariant::Completed => {
verification_handler.completion_success(
caller_id,
tm_sender,
verif_token,
time_stamp,
)?;
verification_handler.completion_success(tm_sender, verif_token, time_stamp)?;
true
}
ActionReplyVariant::StepSuccess { step } => {
verification_handler.step_success(
caller_id,
tm_sender,
&verif_token,
time_stamp,
@ -131,14 +120,12 @@ impl PusReplyHandler<ActivePusActionRequestStd, PusActionReply> for ActionReplyH
fn handle_request_timeout(
&mut self,
caller_id: ComponentId,
active_request: &ActivePusActionRequestStd,
tm_sender: &impl EcssTmSenderCore,
verification_handler: &impl VerificationReportingProvider,
time_stamp: &[u8],
) -> Result<(), Self::Error> {
generic_pus_request_timeout_handler(
caller_id,
tm_sender,
active_request,
verification_handler,
@ -156,7 +143,6 @@ impl PusTcToRequestConverter<ActivePusActionRequestStd, ActionRequest> for Actio
fn convert(
&mut self,
caller_id: ComponentId,
token: VerificationToken<TcStateAccepted>,
tc: &PusTcReader,
tm_sender: &(impl EcssTmSenderCore + ?Sized),
@ -168,7 +154,6 @@ impl PusTcToRequestConverter<ActivePusActionRequestStd, ActionRequest> for Actio
if user_data.len() < 8 {
verif_reporter
.start_failure(
caller_id,
tm_sender,
token,
FailParams::new_no_fail_data(time_stamp, &tmtc_err::NOT_ENOUGH_APP_DATA),
@ -199,7 +184,6 @@ impl PusTcToRequestConverter<ActivePusActionRequestStd, ActionRequest> for Actio
} else {
verif_reporter
.start_failure(
caller_id,
tm_sender,
token,
FailParams::new_no_fail_data(time_stamp, &tmtc_err::INVALID_PUS_SUBSERVICE),
@ -219,10 +203,10 @@ pub fn create_action_service_static(
) -> ActionServiceWrapper<MpscTmInSharedPoolSenderBounded, EcssTcInSharedStoreConverter> {
let action_request_handler = PusTargetedRequestService::new(
PusServiceHelper::new(
PUS_ACTION_SERVICE.raw(),
PUS_ACTION_SERVICE.id(),
pus_action_rx,
tm_sender,
create_verification_reporter(PUS_ACTION_SERVICE.apid),
create_verification_reporter(PUS_ACTION_SERVICE.id(), PUS_ACTION_SERVICE.apid),
EcssTcInSharedStoreConverter::new(tc_pool.clone(), 2048),
),
ActionRequestConverter::default(),
@ -246,10 +230,10 @@ pub fn create_action_service_dynamic(
) -> ActionServiceWrapper<MpscTmAsVecSender, EcssTcInVecConverter> {
let action_request_handler = PusTargetedRequestService::new(
PusServiceHelper::new(
PUS_ACTION_SERVICE.raw(),
PUS_ACTION_SERVICE.id(),
pus_action_rx,
tm_funnel_tx,
create_verification_reporter(PUS_ACTION_SERVICE.apid),
create_verification_reporter(PUS_ACTION_SERVICE.id(), PUS_ACTION_SERVICE.apid),
EcssTcInVecConverter::default(),
),
ActionRequestConverter::default(),
@ -323,10 +307,13 @@ impl<TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter> Targete
#[cfg(test)]
mod tests {
use satrs::pus::test_util::{TEST_APID, TEST_COMPONENT_ID, TEST_UNIQUE_ID};
use satrs::pus::test_util::{
TEST_APID, TEST_COMPONENT_ID_0, TEST_COMPONENT_ID_1, TEST_UNIQUE_ID_0, TEST_UNIQUE_ID_1,
};
use satrs::pus::verification;
use satrs::pus::verification::test_util::TestVerificationReporter;
use satrs::request::MessageMetadata;
use satrs::ComponentId;
use satrs::{
res_code::ResultU16,
spacepackets::{
@ -356,21 +343,21 @@ mod tests {
PusActionReply,
>
{
pub fn new_for_action() -> Self {
pub fn new_for_action(owner_id: ComponentId, target_id: ComponentId) -> Self {
let _ = env_logger::builder().is_test(true).try_init();
let (tm_funnel_tx, tm_funnel_rx) = mpsc::channel();
let (pus_action_tx, pus_action_rx) = mpsc::channel();
let (action_reply_tx, action_reply_rx) = mpsc::channel();
let (action_req_tx, action_req_rx) = mpsc::channel();
let verif_reporter = TestVerificationReporter::default();
let verif_reporter = TestVerificationReporter::new(owner_id);
let mut generic_req_router = GenericRequestRouter::default();
generic_req_router
.composite_router_map
.insert(TEST_COMPONENT_ID.id(), action_req_tx);
.insert(target_id, action_req_tx);
Self {
service: PusTargetedRequestService::new(
PusServiceHelper::new(
0,
owner_id,
pus_action_rx,
tm_funnel_tx.clone(),
verif_reporter,
@ -465,12 +452,7 @@ mod tests {
.service
.service_helper
.verif_reporter()
.acceptance_success(
self.service.service_helper.id(),
self.service.service_helper.tm_sender(),
token,
&[0; 7],
)
.acceptance_success(self.service.service_helper.tm_sender(), token, &[0; 7])
.expect("TC acceptance failed");
self.service
.service_helper
@ -489,13 +471,16 @@ mod tests {
#[test]
fn basic_request() {
let mut testbench = TargetedPusRequestTestbench::new_for_action();
let mut testbench = TargetedPusRequestTestbench::new_for_action(
TEST_COMPONENT_ID_0.id(),
TEST_COMPONENT_ID_1.id(),
);
// Create a basic action request and verify forwarding.
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let sec_header = PusTcSecondaryHeader::new_simple(8, 128);
let action_id = 5_u32;
let mut app_data: [u8; 8] = [0; 8];
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID.to_be_bytes());
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_1.to_be_bytes());
app_data[4..8].copy_from_slice(&action_id.to_be_bytes());
let pus8_packet = PusTcCreator::new(&mut sp_header, sec_header, &app_data, true);
testbench.add_tc(&pus8_packet);
@ -528,14 +513,17 @@ mod tests {
#[test]
fn basic_request_routing_error() {
let mut testbench = TargetedPusRequestTestbench::new_for_action();
let mut testbench = TargetedPusRequestTestbench::new_for_action(
TEST_COMPONENT_ID_0.id(),
TEST_COMPONENT_ID_1.id(),
);
// Create a basic action request and verify forwarding.
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let sec_header = PusTcSecondaryHeader::new_simple(8, 128);
let action_id = 5_u32;
let mut app_data: [u8; 8] = [0; 8];
// Invalid ID, routing should fail.
app_data[0..4].copy_from_slice(&(TEST_UNIQUE_ID + 1).to_be_bytes());
app_data[0..4].copy_from_slice(&0_u32.to_be_bytes());
app_data[4..8].copy_from_slice(&action_id.to_be_bytes());
let pus8_packet = PusTcCreator::new(&mut sp_header, sec_header, &app_data, true);
testbench.add_tc(&pus8_packet);
@ -548,17 +536,17 @@ mod tests {
#[test]
fn converter_action_req_no_data() {
let mut testbench = PusConverterTestbench::new(ActionRequestConverter::default());
let mut testbench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.raw(), ActionRequestConverter::default());
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let sec_header = PusTcSecondaryHeader::new_simple(8, 128);
let action_id = 5_u32;
let mut app_data: [u8; 8] = [0; 8];
// Invalid ID, routing should fail.
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID.to_be_bytes());
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.to_be_bytes());
app_data[4..8].copy_from_slice(&action_id.to_be_bytes());
let pus8_packet = PusTcCreator::new(&mut sp_header, sec_header, &app_data, true);
let token = testbench.add_tc(&pus8_packet);
let result = testbench.convert(token, &[], TEST_APID, TEST_UNIQUE_ID);
let result = testbench.convert(token, &[], TEST_APID, TEST_UNIQUE_ID_0);
assert!(result.is_ok());
let (active_req, request) = result.unwrap();
if let ActionRequestVariant::NoData = request.variant {
@ -566,7 +554,7 @@ mod tests {
assert_eq!(active_req.action_id, action_id);
assert_eq!(
active_req.target_id(),
UniqueApidTargetId::new(TEST_APID, TEST_UNIQUE_ID).raw()
UniqueApidTargetId::new(TEST_APID, TEST_UNIQUE_ID_0).raw()
);
assert_eq!(
active_req.token().request_id(),
@ -579,20 +567,20 @@ mod tests {
#[test]
fn converter_action_req_with_data() {
let mut testbench = PusConverterTestbench::new(ActionRequestConverter::default());
let mut testbench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ActionRequestConverter::default());
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let sec_header = PusTcSecondaryHeader::new_simple(8, 128);
let action_id = 5_u32;
let mut app_data: [u8; 16] = [0; 16];
// Invalid ID, routing should fail.
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID.to_be_bytes());
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.to_be_bytes());
app_data[4..8].copy_from_slice(&action_id.to_be_bytes());
for i in 0..8 {
app_data[i + 8] = i as u8;
}
let pus8_packet = PusTcCreator::new(&mut sp_header, sec_header, &app_data, true);
let token = testbench.add_tc(&pus8_packet);
let result = testbench.convert(token, &[], TEST_APID, TEST_UNIQUE_ID);
let result = testbench.convert(token, &[], TEST_APID, TEST_UNIQUE_ID_0);
assert!(result.is_ok());
let (active_req, request) = result.unwrap();
if let ActionRequestVariant::VecData(vec) = request.variant {
@ -606,9 +594,10 @@ mod tests {
#[test]
fn reply_handling_completion_success() {
let mut testbench = ReplyHandlerTestbench::new(ActionReplyHandler::default());
let mut testbench =
ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ActionReplyHandler::default());
let action_id = 5_u32;
let (req_id, active_req) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID, &[]);
let (req_id, active_req) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID_0, &[]);
let active_action_req =
ActivePusActionRequestStd::new_from_common_req(action_id, active_req);
let reply = PusActionReply::new(action_id, ActionReplyVariant::Completed);
@ -617,7 +606,7 @@ mod tests {
assert!(result.is_ok());
assert!(result.unwrap());
testbench.verif_reporter.assert_full_completion_success(
TEST_COMPONENT_ID.id(),
TEST_COMPONENT_ID_0.id(),
req_id,
None,
);
@ -625,9 +614,10 @@ mod tests {
#[test]
fn reply_handling_completion_failure() {
let mut testbench = ReplyHandlerTestbench::new(ActionReplyHandler::default());
let mut testbench =
ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ActionReplyHandler::default());
let action_id = 5_u32;
let (req_id, active_req) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID, &[]);
let (req_id, active_req) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID_0, &[]);
let active_action_req =
ActivePusActionRequestStd::new_from_common_req(action_id, active_req);
let error_code = ResultU16::new(2, 3);
@ -643,7 +633,7 @@ mod tests {
assert!(result.is_ok());
assert!(result.unwrap());
testbench.verif_reporter.assert_completion_failure(
TEST_COMPONENT_ID.into(),
TEST_COMPONENT_ID_0.into(),
req_id,
None,
error_code.raw() as u64,
@ -652,9 +642,9 @@ mod tests {
#[test]
fn reply_handling_step_success() {
let mut testbench = ReplyHandlerTestbench::new(ActionReplyHandler::default());
let mut testbench = ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ActionReplyHandler::default());
let action_id = 5_u32;
let (req_id, active_req) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID, &[]);
let (req_id, active_req) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID_0, &[]);
let active_action_req =
ActivePusActionRequestStd::new_from_common_req(action_id, active_req);
let reply = PusActionReply::new(action_id, ActionReplyVariant::StepSuccess { step: 1 });
@ -666,20 +656,21 @@ mod tests {
testbench.verif_reporter.check_next_was_added(req_id);
testbench
.verif_reporter
.check_next_is_acceptance_success(TEST_COMPONENT_ID.raw(), req_id);
.check_next_is_acceptance_success(TEST_COMPONENT_ID_0.raw(), req_id);
testbench
.verif_reporter
.check_next_is_started_success(TEST_COMPONENT_ID.raw(), req_id);
.check_next_is_started_success(TEST_COMPONENT_ID_0.raw(), req_id);
testbench
.verif_reporter
.check_next_is_step_success(TEST_COMPONENT_ID.raw(), req_id, 1);
.check_next_is_step_success(TEST_COMPONENT_ID_0.raw(), req_id, 1);
}
#[test]
fn reply_handling_step_failure() {
let mut testbench = ReplyHandlerTestbench::new(ActionReplyHandler::default());
let mut testbench =
ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ActionReplyHandler::default());
let action_id = 5_u32;
let (req_id, active_req) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID, &[]);
let (req_id, active_req) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID_0, &[]);
let active_action_req =
ActivePusActionRequestStd::new_from_common_req(action_id, active_req);
let error_code = ResultU16::new(2, 3);
@ -698,12 +689,12 @@ mod tests {
testbench.verif_reporter.check_next_was_added(req_id);
testbench
.verif_reporter
.check_next_is_acceptance_success(TEST_COMPONENT_ID.id(), req_id);
.check_next_is_acceptance_success(TEST_COMPONENT_ID_0.id(), req_id);
testbench
.verif_reporter
.check_next_is_started_success(TEST_COMPONENT_ID.id(), req_id);
.check_next_is_started_success(TEST_COMPONENT_ID_0.id(), req_id);
testbench.verif_reporter.check_next_is_step_failure(
TEST_COMPONENT_ID.id(),
TEST_COMPONENT_ID_0.id(),
req_id,
error_code.raw().into(),
);
@ -711,7 +702,8 @@ mod tests {
#[test]
fn reply_handling_unrequested_reply() {
let mut testbench = ReplyHandlerTestbench::new(ActionReplyHandler::default());
let mut testbench =
ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ActionReplyHandler::default());
let action_reply = PusActionReply::new(5_u32, ActionReplyVariant::Completed);
let unrequested_reply =
GenericMessage::new(MessageMetadata::new(10_u32, 15_u64), action_reply);
@ -723,16 +715,17 @@ mod tests {
#[test]
fn reply_handling_reply_timeout() {
let mut testbench = ReplyHandlerTestbench::new(ActionReplyHandler::default());
let mut testbench =
ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ActionReplyHandler::default());
let action_id = 5_u32;
let (req_id, active_request) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID, &[]);
let (req_id, active_request) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID_0, &[]);
let result = testbench.handle_request_timeout(
&ActivePusActionRequestStd::new_from_common_req(action_id, active_request),
&[],
);
assert!(result.is_ok());
testbench.verif_reporter.assert_completion_failure(
TEST_COMPONENT_ID.raw(),
TEST_COMPONENT_ID_0.raw(),
req_id,
None,
tmtc_err::REQUEST_TIMEOUT.raw() as u64,

View File

@ -21,10 +21,10 @@ pub fn create_event_service_static(
) -> EventServiceWrapper<MpscTmInSharedPoolSenderBounded, EcssTcInSharedStoreConverter> {
let pus_5_handler = PusEventServiceHandler::new(
PusServiceHelper::new(
PUS_EVENT_MANAGEMENT.raw(),
PUS_EVENT_MANAGEMENT.id(),
pus_event_rx,
tm_sender,
create_verification_reporter(PUS_EVENT_MANAGEMENT.apid),
create_verification_reporter(PUS_EVENT_MANAGEMENT.id(), PUS_EVENT_MANAGEMENT.apid),
EcssTcInSharedStoreConverter::new(tc_pool.clone(), 2048),
),
event_request_tx,
@ -41,10 +41,10 @@ pub fn create_event_service_dynamic(
) -> EventServiceWrapper<MpscTmAsVecSender, EcssTcInVecConverter> {
let pus_5_handler = PusEventServiceHandler::new(
PusServiceHelper::new(
PUS_EVENT_MANAGEMENT.raw(),
PUS_EVENT_MANAGEMENT.id(),
pus_event_rx,
tm_funnel_tx,
create_verification_reporter(PUS_EVENT_MANAGEMENT.apid),
create_verification_reporter(PUS_EVENT_MANAGEMENT.id(), PUS_EVENT_MANAGEMENT.apid),
EcssTcInVecConverter::default(),
),
event_request_tx,

View File

@ -16,7 +16,6 @@ use satrs::pus::{
use satrs::request::{GenericMessage, UniqueApidTargetId};
use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::{hk, PusPacket};
use satrs::ComponentId;
use satrs_example::config::components::PUS_HK_SERVICE;
use satrs_example::config::{hk_err, tmtc_err};
use std::sync::mpsc;
@ -46,7 +45,6 @@ impl PusReplyHandler<ActivePusRequestStd, HkReply> for HkReplyHandler {
fn handle_unrequested_reply(
&mut self,
_caller_id: ComponentId,
reply: &GenericMessage<HkReply>,
_tm_sender: &impl EcssTmSenderCore,
) -> Result<(), Self::Error> {
@ -56,7 +54,6 @@ impl PusReplyHandler<ActivePusRequestStd, HkReply> for HkReplyHandler {
fn handle_reply(
&mut self,
caller_id: ComponentId,
reply: &GenericMessage<HkReply>,
active_request: &ActivePusRequestStd,
tm_sender: &impl EcssTmSenderCore,
@ -70,7 +67,7 @@ impl PusReplyHandler<ActivePusRequestStd, HkReply> for HkReplyHandler {
match reply.message.variant {
HkReplyVariant::Ack => {
verification_handler
.completion_success(caller_id, tm_sender, started_token, time_stamp)
.completion_success(tm_sender, started_token, time_stamp)
.expect("sending completion success verification failed");
}
};
@ -79,14 +76,12 @@ impl PusReplyHandler<ActivePusRequestStd, HkReply> for HkReplyHandler {
fn handle_request_timeout(
&mut self,
caller_id: ComponentId,
active_request: &ActivePusRequestStd,
tm_sender: &impl EcssTmSenderCore,
verification_handler: &impl VerificationReportingProvider,
time_stamp: &[u8],
) -> Result<(), Self::Error> {
generic_pus_request_timeout_handler(
caller_id,
tm_sender,
active_request,
verification_handler,
@ -114,7 +109,6 @@ impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for HkRequestConver
fn convert(
&mut self,
caller_id: ComponentId,
token: VerificationToken<TcStateAccepted>,
tc: &PusTcReader,
tm_sender: &(impl EcssTmSenderCore + ?Sized),
@ -127,7 +121,6 @@ impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for HkRequestConver
let user_data_len_raw = user_data_len.to_be_bytes();
verif_reporter
.start_failure(
caller_id,
tm_sender,
token,
FailParams::new(
@ -152,7 +145,6 @@ impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for HkRequestConver
let user_data_len_raw = user_data_len.to_be_bytes();
verif_reporter
.start_failure(
caller_id,
tm_sender,
token,
FailParams::new(time_stamp, err, &user_data_len_raw),
@ -171,7 +163,6 @@ impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for HkRequestConver
if standard_subservice.is_err() {
verif_reporter
.start_failure(
caller_id,
tm_sender,
token,
FailParams::new(time_stamp, &tmtc_err::INVALID_PUS_SUBSERVICE, &[subservice]),
@ -196,7 +187,6 @@ impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for HkRequestConver
if user_data.len() < 12 {
verif_reporter
.start_failure(
caller_id,
tm_sender,
token,
FailParams::new_no_fail_data(
@ -222,7 +212,6 @@ impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for HkRequestConver
_ => {
verif_reporter
.start_failure(
caller_id,
tm_sender,
token,
FailParams::new(
@ -251,10 +240,10 @@ pub fn create_hk_service_static(
) -> HkServiceWrapper<MpscTmInSharedPoolSenderBounded, EcssTcInSharedStoreConverter> {
let pus_3_handler = PusTargetedRequestService::new(
PusServiceHelper::new(
PUS_HK_SERVICE.raw(),
PUS_HK_SERVICE.id(),
pus_hk_rx,
tm_sender,
create_verification_reporter(PUS_HK_SERVICE.apid),
create_verification_reporter(PUS_HK_SERVICE.id(), PUS_HK_SERVICE.apid),
EcssTcInSharedStoreConverter::new(tc_pool, 2048),
),
HkRequestConverter::default(),
@ -276,10 +265,10 @@ pub fn create_hk_service_dynamic(
) -> HkServiceWrapper<MpscTmAsVecSender, EcssTcInVecConverter> {
let pus_3_handler = PusTargetedRequestService::new(
PusServiceHelper::new(
PUS_HK_SERVICE.raw(),
PUS_HK_SERVICE.id(),
pus_hk_rx,
tm_funnel_tx,
create_verification_reporter(PUS_HK_SERVICE.apid),
create_verification_reporter(PUS_HK_SERVICE.id(), PUS_HK_SERVICE.apid),
EcssTcInVecConverter::default(),
),
HkRequestConverter::default(),
@ -351,7 +340,7 @@ impl<TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter>
#[cfg(test)]
mod tests {
use satrs::pus::test_util::{TEST_COMPONENT_ID, TEST_UNIQUE_ID};
use satrs::pus::test_util::{TEST_COMPONENT_ID_0, TEST_COMPONENT_ID_1, TEST_UNIQUE_ID_0, TEST_UNIQUE_ID_1};
use satrs::request::MessageMetadata;
use satrs::{
hk::HkRequestVariant,
@ -373,9 +362,9 @@ mod tests {
#[test]
fn hk_converter_one_shot_req() {
let mut hk_bench = PusConverterTestbench::new(HkRequestConverter::default());
let mut hk_bench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), HkRequestConverter::default());
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let target_id = TEST_UNIQUE_ID;
let target_id = TEST_UNIQUE_ID_0;
let unique_id = 5_u32;
let mut app_data: [u8; 8] = [0; 8];
app_data[0..4].copy_from_slice(&target_id.to_be_bytes());
@ -390,7 +379,7 @@ mod tests {
);
let accepted_token = hk_bench.add_tc(&hk_req);
let (_active_req, req) = hk_bench
.convert(accepted_token, &[], TEST_APID, TEST_UNIQUE_ID)
.convert(accepted_token, &[], TEST_APID, TEST_UNIQUE_ID_0)
.expect("conversion failed");
assert_eq!(req.unique_id, unique_id);
@ -402,9 +391,9 @@ mod tests {
#[test]
fn hk_converter_enable_periodic_generation() {
let mut hk_bench = PusConverterTestbench::new(HkRequestConverter::default());
let mut hk_bench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), HkRequestConverter::default());
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let target_id = TEST_UNIQUE_ID;
let target_id = TEST_UNIQUE_ID_0;
let unique_id = 5_u32;
let mut app_data: [u8; 8] = [0; 8];
app_data[0..4].copy_from_slice(&target_id.to_be_bytes());
@ -412,7 +401,7 @@ mod tests {
let mut generic_check = |tc: &PusTcCreator| {
let accepted_token = hk_bench.add_tc(tc);
let (_active_req, req) = hk_bench
.convert(accepted_token, &[], TEST_APID, TEST_UNIQUE_ID)
.convert(accepted_token, &[], TEST_APID, TEST_UNIQUE_ID_0)
.expect("conversion failed");
assert_eq!(req.unique_id, unique_id);
if let HkRequestVariant::EnablePeriodic = req.variant {
@ -440,9 +429,9 @@ mod tests {
#[test]
fn hk_conversion_disable_periodic_generation() {
let mut hk_bench = PusConverterTestbench::new(HkRequestConverter::default());
let mut hk_bench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), HkRequestConverter::default());
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let target_id = TEST_UNIQUE_ID;
let target_id = TEST_UNIQUE_ID_0;
let unique_id = 5_u32;
let mut app_data: [u8; 8] = [0; 8];
app_data[0..4].copy_from_slice(&target_id.to_be_bytes());
@ -450,7 +439,7 @@ mod tests {
let mut generic_check = |tc: &PusTcCreator| {
let accepted_token = hk_bench.add_tc(tc);
let (_active_req, req) = hk_bench
.convert(accepted_token, &[], TEST_APID, TEST_UNIQUE_ID)
.convert(accepted_token, &[], TEST_APID, TEST_UNIQUE_ID_0)
.expect("conversion failed");
assert_eq!(req.unique_id, unique_id);
if let HkRequestVariant::DisablePeriodic = req.variant {
@ -478,9 +467,9 @@ mod tests {
#[test]
fn hk_conversion_modify_interval() {
let mut hk_bench = PusConverterTestbench::new(HkRequestConverter::default());
let mut hk_bench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), HkRequestConverter::default());
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let target_id = TEST_UNIQUE_ID;
let target_id = TEST_UNIQUE_ID_0;
let unique_id = 5_u32;
let mut app_data: [u8; 12] = [0; 12];
let collection_interval_factor = 5_u32;
@ -491,7 +480,7 @@ mod tests {
let mut generic_check = |tc: &PusTcCreator| {
let accepted_token = hk_bench.add_tc(tc);
let (_active_req, req) = hk_bench
.convert(accepted_token, &[], TEST_APID, TEST_UNIQUE_ID)
.convert(accepted_token, &[], TEST_APID, TEST_UNIQUE_ID_0)
.expect("conversion failed");
assert_eq!(req.unique_id, unique_id);
if let HkRequestVariant::ModifyCollectionInterval(interval_factor) = req.variant {
@ -520,7 +509,7 @@ mod tests {
#[test]
fn hk_reply_handler() {
let mut reply_testbench = ReplyHandlerTestbench::new(HkReplyHandler::default());
let mut reply_testbench = ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), HkReplyHandler::default());
let sender_id = 2_u64;
let apid_target_id = 3_u32;
let unique_id = 5_u32;
@ -534,12 +523,12 @@ mod tests {
assert!(result.unwrap());
reply_testbench
.verif_reporter
.assert_full_completion_success(TEST_COMPONENT_ID.raw(), req_id, None);
.assert_full_completion_success(TEST_COMPONENT_ID_0.raw(), req_id, None);
}
#[test]
fn reply_handling_unrequested_reply() {
let mut testbench = ReplyHandlerTestbench::new(HkReplyHandler::default());
let mut testbench = ReplyHandlerTestbench::new(TEST_COMPONENT_ID_1.id(), HkReplyHandler::default());
let action_reply = HkReply::new(5_u32, HkReplyVariant::Ack);
let unrequested_reply =
GenericMessage::new(MessageMetadata::new(10_u32, 15_u64), action_reply);
@ -551,12 +540,12 @@ mod tests {
#[test]
fn reply_handling_reply_timeout() {
let mut testbench = ReplyHandlerTestbench::new(HkReplyHandler::default());
let (req_id, active_request) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID, &[]);
let mut testbench = ReplyHandlerTestbench::new(TEST_COMPONENT_ID_1.id(), HkReplyHandler::default());
let (req_id, active_request) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID_1, &[]);
let result = testbench.handle_request_timeout(&active_request, &[]);
assert!(result.is_ok());
testbench.verif_reporter.assert_completion_failure(
TEST_COMPONENT_ID.raw(),
TEST_COMPONENT_ID_1.raw(),
req_id,
None,
tmtc_err::REQUEST_TIMEOUT.raw() as u64,

View File

@ -30,11 +30,11 @@ pub mod scheduler;
pub mod stack;
pub mod test;
pub fn create_verification_reporter(apid: Apid) -> VerificationReporter {
pub fn create_verification_reporter(owner_id: ComponentId, apid: Apid) -> VerificationReporter {
let verif_cfg = VerificationReporterCfg::new(apid, 1, 2, 8).unwrap();
// Every software component which needs to generate verification telemetry, gets a cloned
// verification reporter.
VerificationReporter::new(&verif_cfg)
VerificationReporter::new(owner_id, &verif_cfg)
}
/// Simple router structure which forwards PUS telecommands to dedicated handlers.
@ -60,7 +60,10 @@ impl<TmSender: EcssTmSenderCore> PusReceiver<TmSender> {
Self {
id: PUS_ROUTING_SERVICE.raw(),
tm_sender,
verif_reporter: create_verification_reporter(PUS_ROUTING_SERVICE.apid),
verif_reporter: create_verification_reporter(
PUS_ROUTING_SERVICE.id(),
PUS_ROUTING_SERVICE.apid,
),
pus_router,
stamp_helper: TimeStampHelper::default(),
}
@ -76,12 +79,7 @@ impl<TmSender: EcssTmSenderCore> PusReceiver<TmSender> {
self.stamp_helper.update_from_now();
let accepted_token = self
.verif_reporter
.acceptance_success(
self.id,
&self.tm_sender,
init_token,
self.stamp_helper.stamp(),
)
.acceptance_success(&self.tm_sender, init_token, self.stamp_helper.stamp())
.expect("Acceptance success failure");
let service = PusServiceId::try_from(service);
match service {
@ -108,7 +106,6 @@ impl<TmSender: EcssTmSenderCore> PusReceiver<TmSender> {
}
_ => {
let result = self.verif_reporter.start_failure(
self.id,
&self.tm_sender,
accepted_token,
FailParams::new(
@ -134,7 +131,6 @@ impl<TmSender: EcssTmSenderCore> PusReceiver<TmSender> {
} else {
self.verif_reporter
.start_failure(
self.id,
&self.tm_sender,
accepted_token,
FailParams::new(
@ -265,7 +261,6 @@ where
.cache(&ecss_tc_and_token.tc_in_memory)?;
let tc = self.service_helper.tc_in_mem_converter().convert()?;
let (mut request_info, request) = match self.request_converter.convert(
self.service_helper.id(),
ecss_tc_and_token.token,
&tc,
self.service_helper.tm_sender(),
@ -293,7 +288,6 @@ where
.service_helper
.verif_reporter()
.start_success(
self.service_helper.id(),
&self.service_helper.common.tm_sender,
accepted_token,
time_stamp,
@ -330,7 +324,6 @@ where
self.service_helper
.verif_reporter()
.completion_failure(
self.service_helper.id(),
self.service_helper.tm_sender(),
token,
FailParams::new(time_stamp, &tmtc_err::INVALID_PUS_SERVICE, &service_slice),
@ -342,7 +335,6 @@ where
self.service_helper
.verif_reporter()
.completion_failure(
self.service_helper.id(),
self.service_helper.tm_sender(),
token,
FailParams::new(
@ -359,7 +351,6 @@ where
self.service_helper
.verif_reporter()
.completion_failure(
self.service_helper.id(),
self.service_helper.tm_sender(),
token,
FailParams::new(time_stamp, &tmtc_err::NOT_ENOUGH_APP_DATA, &context_info),
@ -393,18 +384,14 @@ where
) -> Result<(), EcssTmtcError> {
let active_req_opt = self.active_request_map.get(reply.request_id());
if active_req_opt.is_none() {
self.reply_handler.handle_unrequested_reply(
self.service_helper.id(),
reply,
&self.service_helper.common.tm_sender,
)?;
self.reply_handler
.handle_unrequested_reply(reply, &self.service_helper.common.tm_sender)?;
return Ok(());
}
let active_request = active_req_opt.unwrap();
let request_finished = self
.reply_handler
.handle_reply(
self.service_helper.id(),
reply,
active_request,
&self.service_helper.common.tm_sender,
@ -437,7 +424,6 @@ where
/// Generic timeout handling: Handle the verification failure with a dedicated return code
/// and also log the error.
pub fn generic_pus_request_timeout_handler(
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
active_request: &(impl ActiveRequestProvider + Debug),
verification_handler: &impl VerificationReportingProvider,
@ -450,7 +436,6 @@ pub fn generic_pus_request_timeout_handler(
.try_into()
.expect("token not in expected started state");
verification_handler.completion_failure(
sender_id,
sender,
started_token,
FailParams::new(time_stamp, &tmtc_err::REQUEST_TIMEOUT, &[]),
@ -462,7 +447,7 @@ pub fn generic_pus_request_timeout_handler(
pub(crate) mod tests {
use std::time::Duration;
use satrs::pus::test_util::TEST_COMPONENT_ID;
use satrs::pus::test_util::TEST_COMPONENT_ID_0;
use satrs::pus::{MpscTmAsVecSender, PusTmAsVec, PusTmVariant};
use satrs::request::RequestId;
use satrs::{
@ -505,11 +490,11 @@ pub(crate) mod tests {
Reply,
> ReplyHandlerTestbench<ReplyHandler, ActiveRequestInfo, Reply>
{
pub fn new(reply_handler: ReplyHandler) -> Self {
let test_verif_reporter = TestVerificationReporter::default();
pub fn new(owner_id: ComponentId, reply_handler: ReplyHandler) -> Self {
let test_verif_reporter = TestVerificationReporter::new(owner_id);
let (tm_sender, tm_receiver) = mpsc::channel();
Self {
id: TEST_COMPONENT_ID.raw(),
id: TEST_COMPONENT_ID_0.raw(),
verif_reporter: test_verif_reporter,
reply_handler,
default_timeout: Duration::from_secs(30),
@ -535,11 +520,11 @@ pub(crate) mod tests {
));
let accepted = self
.verif_reporter
.acceptance_success(self.id, &self.tm_sender, init, time_stamp)
.acceptance_success(&self.tm_sender, init, time_stamp)
.expect("acceptance failed");
let started = self
.verif_reporter
.start_success(self.id, &self.tm_sender, accepted, time_stamp)
.start_success(&self.tm_sender, accepted, time_stamp)
.expect("start failed");
(
started.request_id(),
@ -558,7 +543,6 @@ pub(crate) mod tests {
time_stamp: &[u8],
) -> Result<bool, ReplyHandler::Error> {
self.reply_handler.handle_reply(
self.id,
reply,
active_request,
&self.tm_sender,
@ -572,7 +556,7 @@ pub(crate) mod tests {
reply: &GenericMessage<Reply>,
) -> Result<(), ReplyHandler::Error> {
self.reply_handler
.handle_unrequested_reply(self.id, reply, &self.tm_sender)
.handle_unrequested_reply(reply, &self.tm_sender)
}
pub fn handle_request_timeout(
&mut self,
@ -580,7 +564,6 @@ pub(crate) mod tests {
time_stamp: &[u8],
) -> Result<(), ReplyHandler::Error> {
self.reply_handler.handle_request_timeout(
self.id,
active_request_info,
&self.tm_sender,
&self.verif_reporter,
@ -622,10 +605,10 @@ pub(crate) mod tests {
Request,
> PusConverterTestbench<Converter, ActiveRequestInfo, Request>
{
pub fn new(converter: Converter) -> Self {
let test_verif_reporter = TestVerificationReporter::default();
pub fn new(owner_id: ComponentId, converter: Converter) -> Self {
let test_verif_reporter = TestVerificationReporter::new(owner_id);
Self {
id: TEST_COMPONENT_ID.raw(),
id: owner_id,
verif_reporter: test_verif_reporter,
converter,
dummy_sender: DummySender::default(),
@ -640,7 +623,7 @@ pub(crate) mod tests {
self.current_request_id = Some(verification::RequestId::new(tc));
self.current_packet = Some(tc.to_vec().unwrap());
self.verif_reporter
.acceptance_success(self.id, &self.dummy_sender, token, &[])
.acceptance_success(&self.dummy_sender, token, &[])
.expect("acceptance failed")
}
@ -663,7 +646,6 @@ pub(crate) mod tests {
let current_packet = self.current_packet.take().unwrap();
let tc_reader = PusTcReader::new(&current_packet).unwrap();
let (active_info, request) = self.converter.convert(
self.id,
token,
&tc_reader.0,
&self.dummy_sender,

View File

@ -1,3 +1,4 @@
use derive_new::new;
use log::{error, warn};
use std::sync::mpsc;
use std::time::Duration;
@ -41,15 +42,16 @@ use super::{
TargetedPusService,
};
#[derive(Default)]
pub struct ModeReplyHandler {}
#[derive(new)]
pub struct ModeReplyHandler {
owner_id: ComponentId,
}
impl PusReplyHandler<ActivePusRequestStd, ModeReply> for ModeReplyHandler {
type Error = EcssTmtcError;
fn handle_unrequested_reply(
&mut self,
_caller_id: ComponentId,
reply: &GenericMessage<ModeReply>,
_tm_sender: &impl EcssTmSenderCore,
) -> Result<(), Self::Error> {
@ -59,7 +61,6 @@ impl PusReplyHandler<ActivePusRequestStd, ModeReply> for ModeReplyHandler {
fn handle_reply(
&mut self,
caller_id: ComponentId,
reply: &GenericMessage<ModeReply>,
active_request: &ActivePusRequestStd,
tm_sender: &impl EcssTmSenderCore,
@ -87,17 +88,11 @@ impl PusReplyHandler<ActivePusRequestStd, ModeReply> for ModeReplyHandler {
Some(time_stamp),
);
let pus_tm = PusTmCreator::new(&mut sp_header, sec_header, &source_data, true);
tm_sender.send_tm(caller_id, PusTmVariant::Direct(pus_tm))?;
verification_handler.completion_success(
caller_id,
tm_sender,
started_token,
time_stamp,
)?;
tm_sender.send_tm(self.owner_id, PusTmVariant::Direct(pus_tm))?;
verification_handler.completion_success(tm_sender, started_token, time_stamp)?;
}
ModeReply::CantReachMode(error_code) => {
verification_handler.completion_failure(
caller_id,
tm_sender,
started_token,
FailParams::new(time_stamp, &error_code, &[]),
@ -112,7 +107,6 @@ impl PusReplyHandler<ActivePusRequestStd, ModeReply> for ModeReplyHandler {
.write_to_be_bytes(&mut error_info[ModeAndSubmode::RAW_LEN..])
.expect("writing reached mode failed");
verification_handler.completion_failure(
caller_id,
tm_sender,
started_token,
FailParams::new(
@ -128,14 +122,12 @@ impl PusReplyHandler<ActivePusRequestStd, ModeReply> for ModeReplyHandler {
fn handle_request_timeout(
&mut self,
caller_id: ComponentId,
active_request: &ActivePusRequestStd,
tm_sender: &impl EcssTmSenderCore,
verification_handler: &impl VerificationReportingProvider,
time_stamp: &[u8],
) -> Result<(), Self::Error> {
generic_pus_request_timeout_handler(
caller_id,
tm_sender,
active_request,
verification_handler,
@ -154,8 +146,6 @@ impl PusTcToRequestConverter<ActivePusRequestStd, ModeRequest> for ModeRequestCo
fn convert(
&mut self,
caller_id: ComponentId,
token: VerificationToken<TcStateAccepted>,
tc: &PusTcReader,
tm_sender: &(impl EcssTmSenderCore + ?Sized),
@ -167,7 +157,6 @@ impl PusTcToRequestConverter<ActivePusRequestStd, ModeRequest> for ModeRequestCo
let not_enough_app_data = |expected: usize| {
verif_reporter
.start_failure(
caller_id,
tm_sender,
token,
FailParams::new_no_fail_data(time_stamp, &tmtc_err::NOT_ENOUGH_APP_DATA),
@ -189,7 +178,6 @@ impl PusTcToRequestConverter<ActivePusRequestStd, ModeRequest> for ModeRequestCo
// Invalid subservice
verif_reporter
.start_failure(
caller_id,
tm_sender,
token,
FailParams::new_no_fail_data(time_stamp, &tmtc_err::INVALID_PUS_SUBSERVICE),
@ -229,15 +217,15 @@ pub fn create_mode_service_static(
) -> ModeServiceWrapper<MpscTmInSharedPoolSenderBounded, EcssTcInSharedStoreConverter> {
let mode_request_handler = PusTargetedRequestService::new(
PusServiceHelper::new(
PUS_MODE_SERVICE.raw(),
PUS_MODE_SERVICE.id(),
pus_action_rx,
tm_sender,
create_verification_reporter(PUS_MODE_SERVICE.apid),
create_verification_reporter(PUS_MODE_SERVICE.id(), PUS_MODE_SERVICE.apid),
EcssTcInSharedStoreConverter::new(tc_pool, 2048),
),
ModeRequestConverter::default(),
DefaultActiveRequestMap::default(),
ModeReplyHandler::default(),
ModeReplyHandler::new(PUS_MODE_SERVICE.id()),
mode_router,
reply_receiver,
);
@ -254,15 +242,15 @@ pub fn create_mode_service_dynamic(
) -> ModeServiceWrapper<MpscTmAsVecSender, EcssTcInVecConverter> {
let mode_request_handler = PusTargetedRequestService::new(
PusServiceHelper::new(
PUS_MODE_SERVICE.raw(),
PUS_MODE_SERVICE.id(),
pus_action_rx,
tm_funnel_tx,
create_verification_reporter(PUS_MODE_SERVICE.apid),
create_verification_reporter(PUS_MODE_SERVICE.id(), PUS_MODE_SERVICE.apid),
EcssTcInVecConverter::default(),
),
ModeRequestConverter::default(),
DefaultActiveRequestMap::default(),
ModeReplyHandler::default(),
ModeReplyHandler::new(PUS_MODE_SERVICE.id()),
mode_router,
reply_receiver,
);
@ -329,7 +317,7 @@ impl<TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter> Targete
}
#[cfg(test)]
mod tests {
use satrs::pus::test_util::{TEST_APID, TEST_COMPONENT_ID, TEST_UNIQUE_ID};
use satrs::pus::test_util::{TEST_APID, TEST_COMPONENT_ID_0, TEST_UNIQUE_ID_0};
use satrs::request::MessageMetadata;
use satrs::{
mode::{ModeAndSubmode, ModeReply, ModeRequest},
@ -351,72 +339,72 @@ mod tests {
#[test]
fn mode_converter_read_mode_request() {
let mut testbench = PusConverterTestbench::new(ModeRequestConverter::default());
let mut testbench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default());
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcReadMode as u8);
let mut app_data: [u8; 4] = [0; 4];
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID.to_be_bytes());
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.to_be_bytes());
let tc = PusTcCreator::new(&mut sp_header, sec_header, &app_data, true);
let token = testbench.add_tc(&tc);
let (_active_req, req) = testbench
.convert(token, &[], TEST_APID, TEST_UNIQUE_ID)
.convert(token, &[], TEST_APID, TEST_UNIQUE_ID_0)
.expect("conversion has failed");
assert_eq!(req, ModeRequest::ReadMode);
}
#[test]
fn mode_converter_set_mode_request() {
let mut testbench = PusConverterTestbench::new(ModeRequestConverter::default());
let mut testbench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default());
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcSetMode as u8);
let mut app_data: [u8; 4 + ModeAndSubmode::RAW_LEN] = [0; 4 + ModeAndSubmode::RAW_LEN];
let mode_and_submode = ModeAndSubmode::new(2, 1);
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID.to_be_bytes());
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.to_be_bytes());
mode_and_submode
.write_to_be_bytes(&mut app_data[4..])
.unwrap();
let tc = PusTcCreator::new(&mut sp_header, sec_header, &app_data, true);
let token = testbench.add_tc(&tc);
let (_active_req, req) = testbench
.convert(token, &[], TEST_APID, TEST_UNIQUE_ID)
.convert(token, &[], TEST_APID, TEST_UNIQUE_ID_0)
.expect("conversion has failed");
assert_eq!(req, ModeRequest::SetMode(mode_and_submode));
}
#[test]
fn mode_converter_announce_mode() {
let mut testbench = PusConverterTestbench::new(ModeRequestConverter::default());
let mut testbench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default());
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcAnnounceMode as u8);
let mut app_data: [u8; 4] = [0; 4];
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID.to_be_bytes());
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.to_be_bytes());
let tc = PusTcCreator::new(&mut sp_header, sec_header, &app_data, true);
let token = testbench.add_tc(&tc);
let (_active_req, req) = testbench
.convert(token, &[], TEST_APID, TEST_UNIQUE_ID)
.convert(token, &[], TEST_APID, TEST_UNIQUE_ID_0)
.expect("conversion has failed");
assert_eq!(req, ModeRequest::AnnounceMode);
}
#[test]
fn mode_converter_announce_mode_recursively() {
let mut testbench = PusConverterTestbench::new(ModeRequestConverter::default());
let mut testbench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default());
let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
let sec_header =
PusTcSecondaryHeader::new_simple(200, Subservice::TcAnnounceModeRecursive as u8);
let mut app_data: [u8; 4] = [0; 4];
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID.to_be_bytes());
app_data[0..4].copy_from_slice(&TEST_UNIQUE_ID_0.to_be_bytes());
let tc = PusTcCreator::new(&mut sp_header, sec_header, &app_data, true);
let token = testbench.add_tc(&tc);
let (_active_req, req) = testbench
.convert(token, &[], TEST_APID, TEST_UNIQUE_ID)
.convert(token, &[], TEST_APID, TEST_UNIQUE_ID_0)
.expect("conversion has failed");
assert_eq!(req, ModeRequest::AnnounceModeRecursive);
}
#[test]
fn reply_handling_unrequested_reply() {
let mut testbench = ReplyHandlerTestbench::new(ModeReplyHandler::default());
let mut testbench = ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ModeReplyHandler::new(TEST_COMPONENT_ID_0.id()));
let mode_reply = ModeReply::ModeReply(ModeAndSubmode::new(5, 1));
let unrequested_reply =
GenericMessage::new(MessageMetadata::new(10_u32, 15_u64), mode_reply);
@ -428,12 +416,12 @@ mod tests {
#[test]
fn reply_handling_reply_timeout() {
let mut testbench = ReplyHandlerTestbench::new(ModeReplyHandler::default());
let (req_id, active_request) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID, &[]);
let mut testbench = ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ModeReplyHandler::new(TEST_COMPONENT_ID_0.id()));
let (req_id, active_request) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID_0, &[]);
let result = testbench.handle_request_timeout(&active_request, &[]);
assert!(result.is_ok());
testbench.verif_reporter.assert_completion_failure(
TEST_COMPONENT_ID.raw(),
TEST_COMPONENT_ID_0.raw(),
req_id,
None,
tmtc_err::REQUEST_TIMEOUT.raw() as u64,

View File

@ -130,10 +130,10 @@ pub fn create_scheduler_service_static(
.expect("Creating PUS Scheduler failed");
let pus_11_handler = PusSchedServiceHandler::new(
PusServiceHelper::new(
PUS_SCHED_SERVICE.raw(),
PUS_SCHED_SERVICE.id(),
pus_sched_rx,
tm_sender,
create_verification_reporter(PUS_SCHED_SERVICE.apid),
create_verification_reporter(PUS_SCHED_SERVICE.id(), PUS_SCHED_SERVICE.apid),
EcssTcInSharedStoreConverter::new(tc_releaser.clone_backing_pool(), 2048),
),
scheduler,
@ -158,10 +158,10 @@ pub fn create_scheduler_service_dynamic(
.expect("Creating PUS Scheduler failed");
let pus_11_handler = PusSchedServiceHandler::new(
PusServiceHelper::new(
PUS_SCHED_SERVICE.raw(),
PUS_SCHED_SERVICE.id(),
pus_sched_rx,
tm_funnel_tx,
create_verification_reporter(PUS_SCHED_SERVICE.apid),
create_verification_reporter(PUS_SCHED_SERVICE.id(), PUS_SCHED_SERVICE.apid),
EcssTcInVecConverter::default(),
),
scheduler,

View File

@ -25,10 +25,10 @@ pub fn create_test_service_static(
pus_test_rx: mpsc::Receiver<EcssTcAndToken>,
) -> TestCustomServiceWrapper<MpscTmInSharedPoolSenderBounded, EcssTcInSharedStoreConverter> {
let pus17_handler = PusService17TestHandler::new(PusServiceHelper::new(
PUS_TEST_SERVICE.raw(),
PUS_TEST_SERVICE.id(),
pus_test_rx,
tm_sender,
create_verification_reporter(PUS_TEST_SERVICE.apid),
create_verification_reporter(PUS_TEST_SERVICE.id(), PUS_TEST_SERVICE.apid),
EcssTcInSharedStoreConverter::new(tc_pool, 2048),
));
TestCustomServiceWrapper {
@ -43,10 +43,10 @@ pub fn create_test_service_dynamic(
pus_test_rx: mpsc::Receiver<EcssTcAndToken>,
) -> TestCustomServiceWrapper<MpscTmAsVecSender, EcssTcInVecConverter> {
let pus17_handler = PusService17TestHandler::new(PusServiceHelper::new(
PUS_TEST_SERVICE.raw(),
PUS_TEST_SERVICE.id(),
pus_test_rx,
tm_funnel_tx,
create_verification_reporter(PUS_TEST_SERVICE.apid),
create_verification_reporter(PUS_TEST_SERVICE.id(), PUS_TEST_SERVICE.apid),
EcssTcInVecConverter::default(),
));
TestCustomServiceWrapper {
@ -107,18 +107,12 @@ impl<TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter>
.handler
.service_helper
.verif_reporter()
.start_success(
self.handler.service_helper.common.id,
self.handler.service_helper.tm_sender(),
token,
&stamp_buf,
)
.start_success(self.handler.service_helper.tm_sender(), token, &stamp_buf)
.expect("Error sending start success");
self.handler
.service_helper
.verif_reporter()
.completion_success(
self.handler.service_helper.id(),
self.handler.service_helper.tm_sender(),
start_token,
&stamp_buf,
@ -130,7 +124,6 @@ impl<TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter>
.service_helper
.verif_reporter()
.start_failure(
self.handler.service_helper.id(),
self.handler.service_helper.tm_sender(),
token,
FailParams::new(

View File

@ -65,7 +65,6 @@ impl GenericRequestRouter {
fail_data.copy_from_slice(&id.to_be_bytes());
verif_reporter
.completion_failure(
self.id,
tm_sender,
accepted_token,
FailParams::new(time_stamp, &tmtc_err::UNKNOWN_TARGET_ID, &fail_data),
@ -77,7 +76,6 @@ impl GenericRequestRouter {
fail_data.copy_from_slice(&active_request.target_id().to_be_bytes());
verif_reporter
.completion_failure(
self.id,
tm_sender,
accepted_token,
FailParams::new(time_stamp, &tmtc_err::ROUTING_ERROR, &fail_data),

View File

@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased]
## Added
- Added `params::WritableToBeBytes::to_vec`.
- New `ComponentId` (`u64` typedef for now) which replaces former `TargetId` as a generic
way to identify components.
- Various abstraction and objects for targeted requests. This includes mode request/reply
types for actions, HK and modes.
- `VerificationReportingProvider::owner_id` method.
## Changed
- Refactored `EventManager` to heavily use generics instead of trait objects.
@ -28,11 +37,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Replace `TargetId` by `ComponentId`.
- Replace most usages of `ChannelId` by `ComponentId`. A dedicated channel ID has limited usage
due to the nature of typed channels in Rust.
- `CheckTimer` renamed to `CountdownProvider`.
- Renamed `TargetId` to `ComponentId`.
- Replaced most `ChannelId` occurences with `ComponentId`. For typed channels, there is generally
no need for dedicated channel IDs.
- Changed `params::WritableToBeBytes::raw_len` to `written_len` for consistency.
- `EventReporter` caches component ID.
- Renamed `PusService11SchedHandler` to `PusSchedServiceHandler`.
- Fixed general naming of PUS handlers from `handle_one_tc` to `poll_and_handle_next_tc`.
- Reworked verification module: The sender (`impl EcssTmSenderCore`)
now need to be passed explicitely to the `VerificationReportingProvider` abstraction. This
allows easier sharing of the TM sender component.
## Fixed
- Update deprecated API for `PusScheduler::insert_wrapped_tc_cds_short`
and `PusScheduler::insert_wrapped_tc_cds_long`.
- `EventReporter` uses interior mutability pattern to allow non-mutable API.
## Removed
- Remove `objects` module.
# [v0.2.0-rc.0] 2024-02-21

View File

@ -234,7 +234,7 @@ mod alloc_mod {
mod tests {
use super::*;
use crate::events::{EventU32, Severity};
use crate::pus::test_util::TEST_COMPONENT_ID;
use crate::pus::test_util::TEST_COMPONENT_ID_0;
use crate::pus::tests::CommonTmInfo;
use crate::pus::{ChannelWithId, PusTmVariant};
use crate::ComponentId;
@ -344,7 +344,7 @@ mod tests {
) {
let mut sender = TestSender::default();
let reporter =
EventReporter::new(TEST_COMPONENT_ID.id(), EXAMPLE_APID, max_event_aux_data_buf);
EventReporter::new(TEST_COMPONENT_ID_0.id(), EXAMPLE_APID, max_event_aux_data_buf);
assert!(reporter.is_some());
let mut reporter = reporter.unwrap();
let time_stamp_empty: [u8; 7] = [0; 7];
@ -374,7 +374,7 @@ mod tests {
assert_eq!(tm_info.common.msg_counter, 0);
assert_eq!(tm_info.common.apid, EXAMPLE_APID);
assert_eq!(tm_info.event, event);
assert_eq!(tm_info.sender_id, TEST_COMPONENT_ID.id());
assert_eq!(tm_info.sender_id, TEST_COMPONENT_ID_0.id());
assert_eq!(tm_info.aux_data, error_copy);
}

View File

@ -84,7 +84,6 @@ impl<
.common
.verif_reporter
.start_success(
self.service_helper.common.id,
&self.service_helper.common.tm_sender,
ecss_tc_and_token.token,
time_stamp,
@ -209,12 +208,7 @@ mod tests {
self.handler
.service_helper
.verif_reporter()
.acceptance_success(
self.handler.service_helper.id(),
self.handler.service_helper.tm_sender(),
init_token,
&[0; 7],
)
.acceptance_success(self.handler.service_helper.tm_sender(), init_token, &[0; 7])
.expect("acceptance success failure")
}

View File

@ -324,7 +324,6 @@ pub trait PusReplyHandler<ActiveRequestInfo: ActiveRequestProvider, ReplyType> {
/// is finished. A finished PUS request will be removed from the active request map.
fn handle_reply(
&mut self,
caller_id: ComponentId,
reply: &GenericMessage<ReplyType>,
active_request: &ActiveRequestInfo,
tm_sender: &impl EcssTmSenderCore,
@ -334,7 +333,6 @@ pub trait PusReplyHandler<ActiveRequestInfo: ActiveRequestProvider, ReplyType> {
fn handle_unrequested_reply(
&mut self,
caller_id: ComponentId,
reply: &GenericMessage<ReplyType>,
tm_sender: &impl EcssTmSenderCore,
) -> Result<(), Self::Error>;
@ -342,7 +340,6 @@ pub trait PusReplyHandler<ActiveRequestInfo: ActiveRequestProvider, ReplyType> {
/// Handle the timeout of an active request.
fn handle_request_timeout(
&mut self,
caller_id: ComponentId,
active_request: &ActiveRequestInfo,
tm_sender: &impl EcssTmSenderCore,
verification_handler: &impl VerificationReportingProvider,
@ -457,7 +454,6 @@ pub mod alloc_mod {
type Error;
fn convert(
&mut self,
caller_id: ComponentId,
token: VerificationToken<TcStateAccepted>,
tc: &PusTcReader,
tm_sender: &(impl EcssTmSenderCore + ?Sized),
@ -1387,9 +1383,12 @@ pub mod test_util {
};
pub const TEST_APID: u16 = 0x101;
pub const TEST_UNIQUE_ID: u32 = 0x05;
pub const TEST_COMPONENT_ID: UniqueApidTargetId =
UniqueApidTargetId::new(TEST_APID, TEST_UNIQUE_ID);
pub const TEST_UNIQUE_ID_0: u32 = 0x05;
pub const TEST_UNIQUE_ID_1: u32 = 0x06;
pub const TEST_COMPONENT_ID_0: UniqueApidTargetId =
UniqueApidTargetId::new(TEST_APID, TEST_UNIQUE_ID_0);
pub const TEST_COMPONENT_ID_1: UniqueApidTargetId =
UniqueApidTargetId::new(TEST_APID, TEST_UNIQUE_ID_1);
pub trait PusTestHarness {
fn init_verification(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted>;
@ -1427,7 +1426,7 @@ pub mod tests {
use crate::tmtc::tm_helper::SharedTmPool;
use crate::ComponentId;
use super::test_util::{TEST_APID, TEST_COMPONENT_ID};
use super::test_util::{TEST_APID, TEST_COMPONENT_ID_0};
use super::verification::test_util::TestVerificationReporter;
use super::verification::{
@ -1508,7 +1507,7 @@ pub mod tests {
let (tm_tx, tm_rx) = mpsc::sync_channel(10);
let verif_cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
let verification_handler = VerificationReporter::new(&verif_cfg);
let verification_handler = VerificationReporter::new(TEST_COMPONENT_ID_0.id(), &verif_cfg);
let test_srv_tm_sender = TmInSharedPoolSender::new(shared_tm_pool.clone(), tm_tx);
let in_store_converter =
EcssTcInSharedStoreConverter::new(shared_tc_pool.clone(), 2048);
@ -1596,7 +1595,7 @@ pub mod tests {
let (tm_tx, tm_rx) = mpsc::channel();
let verif_cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
let verification_handler = VerificationReporter::new(&verif_cfg);
let verification_handler = VerificationReporter::new(TEST_COMPONENT_ID_0.id(), &verif_cfg);
let in_store_converter = EcssTcInVecConverter::default();
(
Self {
@ -1616,7 +1615,7 @@ pub mod tests {
}
impl PusServiceHandlerWithVecCommon {
pub fn new_with_test_verif_sender() -> (
pub fn new_with_test_verif_sender(id: ComponentId) -> (
Self,
PusServiceHelper<
MpscTcReceiver,
@ -1629,7 +1628,7 @@ pub mod tests {
let (tm_tx, tm_rx) = mpsc::channel();
let in_store_converter = EcssTcInVecConverter::default();
let verification_handler = TestVerificationReporter::default();
let verification_handler = TestVerificationReporter::new(id);
(
Self {
current_tm: None,
@ -1638,7 +1637,7 @@ pub mod tests {
//verification_handler: verification_handler.clone(),
},
PusServiceHelper::new(
TEST_COMPONENT_ID.raw(),
id,
test_srv_tc_rx,
tm_tx,
verification_handler,

View File

@ -93,7 +93,6 @@ impl<
.service_helper
.verif_reporter()
.start_success(
self.service_helper.common.id,
&self.service_helper.common.tm_sender,
ecss_tc_and_token.token,
time_stamp,
@ -105,7 +104,6 @@ impl<
self.service_helper
.verif_reporter()
.completion_success(
self.service_helper.common.id,
&self.service_helper.common.tm_sender,
start_token,
time_stamp,
@ -122,7 +120,6 @@ impl<
.service_helper
.verif_reporter()
.start_success(
self.service_helper.common.id,
&self.service_helper.common.tm_sender,
ecss_tc_and_token.token,
time_stamp,
@ -134,7 +131,6 @@ impl<
self.service_helper
.verif_reporter()
.completion_success(
self.service_helper.common.id,
&self.service_helper.common.tm_sender,
start_token,
time_stamp,
@ -151,7 +147,6 @@ impl<
.service_helper
.verif_reporter()
.start_success(
self.service_helper.common.id,
&self.service_helper.common.tm_sender,
ecss_tc_and_token.token,
time_stamp,
@ -165,7 +160,6 @@ impl<
self.service_helper
.verif_reporter()
.completion_success(
self.service_helper.common.id,
&self.service_helper.common.tm_sender,
start_token,
time_stamp,
@ -178,7 +172,6 @@ impl<
.common
.verif_reporter
.start_success(
self.service_helper.common.id,
&self.service_helper.common.tm_sender,
ecss_tc_and_token.token,
time_stamp,
@ -193,7 +186,6 @@ impl<
self.service_helper
.verif_reporter()
.completion_success(
self.service_helper.common.id,
&self.service_helper.common.tm_sender,
start_token,
time_stamp,
@ -321,12 +313,7 @@ mod tests {
self.handler
.service_helper
.verif_reporter()
.acceptance_success(
self.handler.service_helper.id(),
self.handler.service_helper.tm_sender(),
init_token,
&[0; 7],
)
.acceptance_success(self.handler.service_helper.tm_sender(), init_token, &[0; 7])
.expect("acceptance success failure")
}

View File

@ -66,7 +66,6 @@ impl<
.service_helper
.verif_reporter()
.start_success(
self.service_helper.common.id,
&self.service_helper.common.tm_sender,
ecss_tc_and_token.token,
time_stamp,
@ -98,7 +97,6 @@ impl<
.service_helper
.verif_reporter()
.completion_success(
self.service_helper.common.id,
&self.service_helper.common.tm_sender,
start_token,
time_stamp,
@ -208,12 +206,7 @@ mod tests {
self.handler
.service_helper
.verif_reporter()
.acceptance_success(
self.handler.service_helper.id(),
self.handler.service_helper.tm_sender(),
init_token,
&[0; 7],
)
.acceptance_success(self.handler.service_helper.tm_sender(), init_token, &[0; 7])
.expect("acceptance success failure")
}
@ -264,12 +257,7 @@ mod tests {
self.handler
.service_helper
.verif_reporter()
.acceptance_success(
self.handler.service_helper.id(),
self.handler.service_helper.tm_sender(),
init_token,
&[0; 7],
)
.acceptance_success(self.handler.service_helper.tm_sender(), init_token, &[0; 7])
.expect("acceptance success failure")
}

View File

@ -404,6 +404,10 @@ impl<'stamp, 'fargs> FailParamsWithStep<'stamp, 'fargs> {
/// or to swap the actual reporter with a test reporter for unit tests.
/// For general purposes, the [VerificationReporter] should be sufficient.
pub trait VerificationReportingProvider {
/// It is generally assumed that the reporting provider is owned by some PUS service with
/// a unique ID.
fn owner_id(&self) -> ComponentId;
fn set_apid(&mut self, apid: Apid);
fn apid(&self) -> Apid;
@ -418,7 +422,6 @@ pub trait VerificationReportingProvider {
fn acceptance_success(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateNone>,
time_stamp: &[u8],
@ -426,7 +429,6 @@ pub trait VerificationReportingProvider {
fn acceptance_failure(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateNone>,
params: FailParams,
@ -434,7 +436,6 @@ pub trait VerificationReportingProvider {
fn start_success(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateAccepted>,
time_stamp: &[u8],
@ -442,7 +443,6 @@ pub trait VerificationReportingProvider {
fn start_failure(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateAccepted>,
params: FailParams,
@ -450,7 +450,6 @@ pub trait VerificationReportingProvider {
fn step_success(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: &VerificationToken<TcStateStarted>,
time_stamp: &[u8],
@ -459,7 +458,6 @@ pub trait VerificationReportingProvider {
fn step_failure(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateStarted>,
params: FailParamsWithStep,
@ -467,7 +465,6 @@ pub trait VerificationReportingProvider {
fn completion_success<TcState: WasAtLeastAccepted + Copy>(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcState>,
time_stamp: &[u8],
@ -475,7 +472,6 @@ pub trait VerificationReportingProvider {
fn completion_failure<TcState: WasAtLeastAccepted + Copy>(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcState>,
params: FailParams,
@ -944,15 +940,17 @@ pub mod alloc_mod {
pub struct VerificationReporter<
VerificationHook: VerificationHookProvider = DummyVerificationHook,
> {
owner_id: ComponentId,
source_data_buf: RefCell<alloc::vec::Vec<u8>>,
pub reporter_creator: VerificationReportCreator,
pub tm_hook: VerificationHook,
}
impl VerificationReporter<DummyVerificationHook> {
pub fn new(cfg: &VerificationReporterCfg) -> Self {
pub fn new(owner_id: ComponentId, cfg: &VerificationReporterCfg) -> Self {
let reporter = VerificationReportCreator::new(cfg.apid).unwrap();
Self {
owner_id,
source_data_buf: RefCell::new(alloc::vec![
0;
RequestId::SIZE_AS_BYTES
@ -969,9 +967,14 @@ pub mod alloc_mod {
impl<VerificationHook: VerificationHookProvider> VerificationReporter<VerificationHook> {
/// The provided [VerificationHookProvider] can be used to modify a verification packet
/// before it is sent.
pub fn new_with_hook(cfg: &VerificationReporterCfg, tm_hook: VerificationHook) -> Self {
pub fn new_with_hook(
owner_id: ComponentId,
cfg: &VerificationReporterCfg,
tm_hook: VerificationHook,
) -> Self {
let reporter = VerificationReportCreator::new(cfg.apid).unwrap();
Self {
owner_id,
source_data_buf: RefCell::new(alloc::vec![
0;
RequestId::SIZE_AS_BYTES
@ -1012,10 +1015,13 @@ pub mod alloc_mod {
}
);
fn owner_id(&self) -> ComponentId {
self.owner_id
}
/// Package and send a PUS TM\[1, 1\] packet, see 8.1.2.1 of the PUS standard
fn acceptance_success(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateNone>,
time_stamp: &[u8],
@ -1026,14 +1032,13 @@ pub mod alloc_mod {
.acceptance_success(source_data_buf.as_mut_slice(), token, 0, 0, time_stamp)
.map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(sender_id, PusTmVariant::Direct(tm_creator))?;
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
Ok(token)
}
/// Package and send a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard
fn acceptance_failure(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateNone>,
params: FailParams,
@ -1044,7 +1049,7 @@ pub mod alloc_mod {
.acceptance_failure(buf.as_mut_slice(), token, 0, 0, params)
.map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(sender_id, PusTmVariant::Direct(tm_creator))?;
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
Ok(())
}
@ -1053,7 +1058,6 @@ pub mod alloc_mod {
/// Requires a token previously acquired by calling [Self::acceptance_success].
fn start_success(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateAccepted>,
time_stamp: &[u8],
@ -1064,7 +1068,7 @@ pub mod alloc_mod {
.start_success(buf.as_mut_slice(), token, 0, 0, time_stamp)
.map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(sender_id, PusTmVariant::Direct(tm_creator))?;
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
Ok(started_token)
}
@ -1074,7 +1078,6 @@ pub mod alloc_mod {
/// the token because verification handling is done.
fn start_failure(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateAccepted>,
params: FailParams,
@ -1085,7 +1088,7 @@ pub mod alloc_mod {
.start_failure(buf.as_mut_slice(), token, 0, 0, params)
.map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(sender_id, PusTmVariant::Direct(tm_creator))?;
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
Ok(())
}
@ -1094,7 +1097,6 @@ pub mod alloc_mod {
/// Requires a token previously acquired by calling [Self::start_success].
fn step_success(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: &VerificationToken<TcStateStarted>,
time_stamp: &[u8],
@ -1106,7 +1108,7 @@ pub mod alloc_mod {
.step_success(buf.as_mut_slice(), token, 0, 0, time_stamp, step)
.map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(sender_id, PusTmVariant::Direct(tm_creator))?;
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
Ok(())
}
@ -1116,7 +1118,6 @@ pub mod alloc_mod {
/// token because verification handling is done.
fn step_failure(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateStarted>,
params: FailParamsWithStep,
@ -1127,7 +1128,7 @@ pub mod alloc_mod {
.step_failure(buf.as_mut_slice(), token, 0, 0, params)
.map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(sender_id, PusTmVariant::Direct(tm_creator))?;
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
Ok(())
}
@ -1137,7 +1138,7 @@ pub mod alloc_mod {
/// token because verification handling is done.
fn completion_success<TcState: WasAtLeastAccepted + Copy>(
&self,
sender_id: ComponentId,
// sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcState>,
time_stamp: &[u8],
@ -1148,7 +1149,7 @@ pub mod alloc_mod {
.completion_success(buf.as_mut_slice(), token, 0, 0, time_stamp)
.map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(sender_id, PusTmVariant::Direct(tm_creator))?;
sender.send_tm(self.owner_id, PusTmVariant::Direct(tm_creator))?;
Ok(())
}
@ -1158,7 +1159,6 @@ pub mod alloc_mod {
/// token because verification handling is done.
fn completion_failure<TcState: WasAtLeastAccepted + Copy>(
&self,
sender_id: ComponentId,
sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcState>,
params: FailParams,
@ -1169,7 +1169,7 @@ pub mod alloc_mod {
.completion_failure(buf.as_mut_slice(), token, 0, 00, params)
.map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(sender_id, PusTmVariant::Direct(tm_creator))?;
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
Ok(())
}
}
@ -1204,11 +1204,6 @@ pub mod test_util {
use super::*;
#[derive(Default)]
pub struct TestVerificationReporter {
pub report_queue: RefCell<VecDeque<(RequestId, VerificationReportInfo)>>,
}
#[derive(Debug, PartialEq)]
pub struct SuccessData {
pub sender: ComponentId,
@ -1236,6 +1231,20 @@ pub mod test_util {
CompletionFailure(FailureData),
}
pub struct TestVerificationReporter {
pub id: ComponentId,
pub report_queue: RefCell<VecDeque<(RequestId, VerificationReportInfo)>>,
}
impl TestVerificationReporter {
pub fn new(id: ComponentId) -> Self {
Self {
id,
report_queue: Default::default(),
}
}
}
impl VerificationReportingProvider for TestVerificationReporter {
fn set_apid(&mut self, _apid: Apid) {}
@ -1255,7 +1264,6 @@ pub mod test_util {
fn acceptance_success(
&self,
sender_id: ComponentId,
_sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateNone>,
time_stamp: &[u8],
@ -1263,7 +1271,7 @@ pub mod test_util {
self.report_queue.borrow_mut().push_back((
token.request_id(),
VerificationReportInfo::AcceptanceSuccess(SuccessData {
sender: sender_id,
sender: self.owner_id(),
time_stamp: time_stamp.to_vec(),
}),
));
@ -1275,7 +1283,6 @@ pub mod test_util {
fn acceptance_failure(
&self,
sender_id: ComponentId,
_sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateNone>,
params: FailParams,
@ -1283,7 +1290,7 @@ pub mod test_util {
self.report_queue.borrow_mut().push_back((
token.request_id(),
VerificationReportInfo::AcceptanceFailure(FailureData {
sender: sender_id,
sender: self.owner_id(),
error_enum: params.failure_code.value(),
fail_data: params.failure_data.to_vec(),
time_stamp: params.time_stamp.to_vec(),
@ -1294,7 +1301,6 @@ pub mod test_util {
fn start_success(
&self,
sender_id: ComponentId,
_sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateAccepted>,
time_stamp: &[u8],
@ -1302,7 +1308,7 @@ pub mod test_util {
self.report_queue.borrow_mut().push_back((
token.request_id(),
VerificationReportInfo::StartedSuccess(SuccessData {
sender: sender_id,
sender: self.owner_id(),
time_stamp: time_stamp.to_vec(),
}),
));
@ -1314,7 +1320,6 @@ pub mod test_util {
fn start_failure(
&self,
sender_id: ComponentId,
_sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<super::TcStateAccepted>,
params: FailParams,
@ -1322,7 +1327,7 @@ pub mod test_util {
self.report_queue.borrow_mut().push_back((
token.request_id(),
VerificationReportInfo::StartedFailure(FailureData {
sender: sender_id,
sender: self.owner_id(),
error_enum: params.failure_code.value(),
fail_data: params.failure_data.to_vec(),
time_stamp: params.time_stamp.to_vec(),
@ -1333,7 +1338,6 @@ pub mod test_util {
fn step_success(
&self,
sender_id: ComponentId,
_sender: &(impl EcssTmSenderCore + ?Sized),
token: &VerificationToken<TcStateStarted>,
time_stamp: &[u8],
@ -1343,7 +1347,7 @@ pub mod test_util {
token.request_id(),
VerificationReportInfo::StepSuccess {
data: SuccessData {
sender: sender_id,
sender: self.owner_id(),
time_stamp: time_stamp.to_vec(),
},
step: step.value() as u16,
@ -1354,7 +1358,6 @@ pub mod test_util {
fn step_failure(
&self,
sender_id: ComponentId,
_sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcStateStarted>,
params: FailParamsWithStep,
@ -1362,7 +1365,7 @@ pub mod test_util {
self.report_queue.borrow_mut().push_back((
token.request_id(),
VerificationReportInfo::StepFailure(FailureData {
sender: sender_id,
sender: self.owner_id(),
error_enum: params.common.failure_code.value(),
fail_data: params.common.failure_data.to_vec(),
time_stamp: params.common.time_stamp.to_vec(),
@ -1373,7 +1376,6 @@ pub mod test_util {
fn completion_success<TcState: super::WasAtLeastAccepted + Copy>(
&self,
sender_id: ComponentId,
_sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcState>,
time_stamp: &[u8],
@ -1381,7 +1383,7 @@ pub mod test_util {
self.report_queue.borrow_mut().push_back((
token.request_id(),
VerificationReportInfo::CompletionSuccess(SuccessData {
sender: sender_id,
sender: self.owner_id(),
time_stamp: time_stamp.to_vec(),
}),
));
@ -1390,7 +1392,6 @@ pub mod test_util {
fn completion_failure<TcState: WasAtLeastAccepted + Copy>(
&self,
sender_id: ComponentId,
_sender: &(impl EcssTmSenderCore + ?Sized),
token: VerificationToken<TcState>,
params: FailParams,
@ -1398,7 +1399,7 @@ pub mod test_util {
self.report_queue.borrow_mut().push_back((
token.request_id(),
VerificationReportInfo::CompletionFailure(FailureData {
sender: sender_id,
sender: self.owner_id(),
error_enum: params.failure_code.value(),
fail_data: params.failure_data.to_vec(),
time_stamp: params.time_stamp.to_vec(),
@ -1406,6 +1407,10 @@ pub mod test_util {
));
Ok(())
}
fn owner_id(&self) -> ComponentId {
self.id
}
}
impl TestVerificationReporter {
@ -1627,7 +1632,7 @@ pub mod test_util {
#[cfg(test)]
pub mod tests {
use crate::pool::{StaticMemoryPool, StaticPoolConfig};
use crate::pus::test_util::{TEST_APID, TEST_COMPONENT_ID};
use crate::pus::test_util::{TEST_APID, TEST_COMPONENT_ID_0};
use crate::pus::tests::CommonTmInfo;
use crate::pus::verification::{
EcssTmSenderCore, EcssTmtcError, FailParams, FailParamsWithStep, RequestId, TcStateNone,
@ -1739,21 +1744,22 @@ pub mod tests {
tc: Vec<u8>,
}
fn base_reporter() -> VerificationReporter {
fn base_reporter(id: ComponentId) -> VerificationReporter {
let cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
VerificationReporter::new(&cfg)
VerificationReporter::new(id, &cfg)
}
fn reporter_with_hook<VerificationHook: VerificationHookProvider>(
id: ComponentId,
hook: VerificationHook,
) -> VerificationReporter<VerificationHook> {
let cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
VerificationReporter::new_with_hook(&cfg, hook)
VerificationReporter::new_with_hook(id, &cfg, hook)
}
impl<VerificiationHook: VerificationHookProvider> VerificationReporterTestbench<VerificiationHook> {
fn new_with_hook(id: ComponentId, tc: PusTcCreator, tm_hook: VerificiationHook) -> Self {
let reporter = reporter_with_hook(tm_hook);
let reporter = reporter_with_hook(id, tm_hook);
Self {
id,
sender: TestSender::default(),
@ -1778,7 +1784,7 @@ pub mod tests {
time_stamp: &[u8],
) -> Result<VerificationToken<TcStateAccepted>, EcssTmtcError> {
self.reporter
.acceptance_success(self.id, &self.sender, token, time_stamp)
.acceptance_success(&self.sender, token, time_stamp)
}
fn acceptance_failure(
@ -1787,7 +1793,7 @@ pub mod tests {
params: FailParams,
) -> Result<(), EcssTmtcError> {
self.reporter
.acceptance_failure(self.id, &self.sender, token, params)
.acceptance_failure(&self.sender, token, params)
}
fn start_success(
@ -1795,8 +1801,7 @@ pub mod tests {
token: VerificationToken<TcStateAccepted>,
time_stamp: &[u8],
) -> Result<VerificationToken<TcStateStarted>, EcssTmtcError> {
self.reporter
.start_success(self.id, &self.sender, token, time_stamp)
self.reporter.start_success(&self.sender, token, time_stamp)
}
fn start_failure(
@ -1804,8 +1809,7 @@ pub mod tests {
token: VerificationToken<TcStateAccepted>,
params: FailParams,
) -> Result<(), EcssTmtcError> {
self.reporter
.start_failure(self.id, &self.sender, token, params)
self.reporter.start_failure(&self.sender, token, params)
}
fn step_success(
@ -1815,7 +1819,7 @@ pub mod tests {
step: impl EcssEnumeration,
) -> Result<(), EcssTmtcError> {
self.reporter
.step_success(self.id, &self.sender, token, time_stamp, step)
.step_success(&self.sender, token, time_stamp, step)
}
fn step_failure(
@ -1823,8 +1827,7 @@ pub mod tests {
token: VerificationToken<TcStateStarted>,
params: FailParamsWithStep,
) -> Result<(), EcssTmtcError> {
self.reporter
.step_failure(self.id, &self.sender, token, params)
self.reporter.step_failure(&self.sender, token, params)
}
fn completion_success<TcState: WasAtLeastAccepted + Copy>(
@ -1833,7 +1836,7 @@ pub mod tests {
time_stamp: &[u8],
) -> Result<(), EcssTmtcError> {
self.reporter
.completion_success(self.id, &self.sender, token, time_stamp)
.completion_success(&self.sender, token, time_stamp)
}
fn completion_failure<TcState: WasAtLeastAccepted + Copy>(
@ -1842,7 +1845,7 @@ pub mod tests {
params: FailParams,
) -> Result<(), EcssTmtcError> {
self.reporter
.completion_failure(self.id, &self.sender, token, params)
.completion_failure(&self.sender, token, params)
}
fn completion_success_check(&mut self, incrementing_couters: bool) {
@ -1904,7 +1907,7 @@ pub mod tests {
impl VerificationReporterTestbench<DummyVerificationHook> {
fn new(id: ComponentId, tc: PusTcCreator) -> Self {
let reporter = base_reporter();
let reporter = base_reporter(id);
Self {
id,
sender: TestSender::default(),
@ -2336,7 +2339,7 @@ pub mod tests {
#[test]
fn test_complete_success_sequence() {
let mut testbench =
VerificationReporterTestbench::new(TEST_COMPONENT_ID.id(), create_generic_ping());
VerificationReporterTestbench::new(TEST_COMPONENT_ID_0.id(), create_generic_ping());
let token = testbench.init();
let accepted_token = testbench
.acceptance_success(token, &EMPTY_STAMP)
@ -2353,7 +2356,7 @@ pub mod tests {
#[test]
fn test_packet_manipulation() {
let mut testbench = VerificationReporterTestbench::new_with_hook(
TEST_COMPONENT_ID.id(),
TEST_COMPONENT_ID_0.id(),
create_generic_ping(),
SequenceCounterHook::default(),
);

View File

@ -2,12 +2,12 @@
pub mod crossbeam_test {
use hashbrown::HashMap;
use satrs::pool::{PoolProvider, PoolProviderWithGuards, StaticMemoryPool, StaticPoolConfig};
use satrs::pus::test_util::{TEST_APID, TEST_COMPONENT_ID_0};
use satrs::pus::verification::{
FailParams, RequestId, VerificationReporter, VerificationReporterCfg,
VerificationReportingProvider,
};
use satrs::pus::TmInSharedPoolSenderWithCrossbeam;
use satrs::request::UniqueApidTargetId;
use satrs::tmtc::tm_helper::SharedTmPool;
use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader};
use spacepackets::ecss::tm::PusTmReader;
@ -17,9 +17,6 @@ pub mod crossbeam_test {
use std::thread;
use std::time::Duration;
const TEST_APID: u16 = 0x03;
const TEST_ID: UniqueApidTargetId = UniqueApidTargetId::new(TEST_APID, 0x05);
const FIXED_STAMP: [u8; 7] = [0; 7];
const PACKETS_SENT: u8 = 8;
@ -45,7 +42,7 @@ pub mod crossbeam_test {
let (tx, rx) = crossbeam_channel::bounded(10);
let sender_0 = TmInSharedPoolSenderWithCrossbeam::new(shared_tm_pool.clone(), tx.clone());
let sender_1 = sender_0.clone();
let mut reporter_with_sender_0 = VerificationReporter::new(&cfg);
let mut reporter_with_sender_0 = VerificationReporter::new(TEST_COMPONENT_ID_0.id(), &cfg);
let mut reporter_with_sender_1 = reporter_with_sender_0.clone();
// For test purposes, we retrieve the request ID from the TCs and pass them to the receiver
// tread.
@ -92,36 +89,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(TEST_ID.raw(), &sender_0, token, &FIXED_STAMP)
.acceptance_success(&sender_0, token, &FIXED_STAMP)
.expect("Acceptance success failed");
// Do some start handling here
let started_token = reporter_with_sender_0
.start_success(TEST_ID.raw(), &sender_0, accepted_token, &FIXED_STAMP)
.start_success(&sender_0, accepted_token, &FIXED_STAMP)
.expect("Start success failed");
// Do some step handling here
reporter_with_sender_0
.step_success(
TEST_ID.raw(),
&sender_0,
&started_token,
&FIXED_STAMP,
EcssEnumU8::new(0),
)
.step_success(&sender_0, &started_token, &FIXED_STAMP, EcssEnumU8::new(0))
.expect("Start success failed");
// Finish up
reporter_with_sender_0
.step_success(
TEST_ID.raw(),
&sender_0,
&started_token,
&FIXED_STAMP,
EcssEnumU8::new(1),
)
.step_success(&sender_0, &started_token, &FIXED_STAMP, EcssEnumU8::new(1))
.expect("Start success failed");
reporter_with_sender_0
.completion_success(TEST_ID.raw(), &sender_0, started_token, &FIXED_STAMP)
.completion_success(&sender_0, started_token, &FIXED_STAMP)
.expect("Completion success failed");
});
@ -139,15 +124,15 @@ 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(TEST_ID.raw(), &sender_1, token, &FIXED_STAMP)
.acceptance_success(&sender_1, token, &FIXED_STAMP)
.expect("Acceptance success failed");
let started_token = reporter_with_sender_1
.start_success(TEST_ID.raw(), &sender_1, accepted_token, &FIXED_STAMP)
.start_success(&sender_1, accepted_token, &FIXED_STAMP)
.expect("Start success failed");
let fail_code = EcssEnumU16::new(2);
let params = FailParams::new_no_fail_data(&FIXED_STAMP, &fail_code);
reporter_with_sender_1
.completion_failure(TEST_ID.raw(), &sender_1, started_token, params)
.completion_failure(&sender_1, started_token, params)
.expect("Completion success failed");
});