this might finally work..
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
2024-03-21 13:06:46 +01:00
parent 6873a8f2a7
commit 309d0101a0
19 changed files with 453 additions and 664 deletions

View File

@ -88,12 +88,8 @@ impl<VerificationReporter: VerificationReportingProvider> AcsTask<VerificationRe
warn!("action request handling not implemented yet")
}
}
let started_token = self
.verif_reporter
.start_success(request.token, &self.timestamp)
.expect("Sending start success failed");
self.verif_reporter
.completion_success(started_token, &self.timestamp)
.completion_success(request.token, &self.timestamp)
.expect("Sending completion success failed");
true
}

View File

@ -170,7 +170,7 @@ fn static_tmtc_pool_main() {
shared_tc_pool.pool.clone(),
pus_hk_rx,
request_map,
pus_hk_reply_rx
pus_hk_reply_rx,
);
let mut pus_stack = PusStack::new(
pus_hk_service,
@ -390,7 +390,7 @@ fn dyn_tmtc_pool_main() {
verif_reporter.clone(),
pus_hk_rx,
request_map,
pus_hk_reply_rx
pus_hk_reply_rx,
);
let mut pus_stack = PusStack::new(
pus_hk_service,

View File

@ -13,9 +13,9 @@ use satrs::pus::verification::{
};
use satrs::pus::{
ActiveRequestProvider, EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter,
EcssTcInVecConverter, EcssTcReceiverCore, EcssTmSenderCore, EcssTmtcError, MpscTcReceiver,
PusPacketHandlerResult, PusPacketHandlingError, PusReplyHandler, PusServiceHelper,
PusTcToRequestConverter, TmAsVecSenderWithId, TmAsVecSenderWithMpsc,
EcssTcInVecConverter, EcssTcReceiverCore, EcssTmSenderCore, EcssTmtcError,
GenericConversionError, MpscTcReceiver, PusPacketHandlerResult, PusReplyHandler,
PusServiceHelper, PusTcToRequestConverter, TmAsVecSenderWithId, TmAsVecSenderWithMpsc,
TmInSharedPoolSenderWithBoundedMpsc, TmInSharedPoolSenderWithId,
};
use satrs::request::{GenericMessage, TargetAndApidId};
@ -138,7 +138,7 @@ pub struct ExampleActionRequestConverter {}
impl PusTcToRequestConverter<ActivePusActionRequestStd, ActionRequestWithId>
for ExampleActionRequestConverter
{
type Error = PusPacketHandlingError;
type Error = GenericConversionError;
fn convert(
&mut self,
@ -156,7 +156,7 @@ impl PusTcToRequestConverter<ActivePusActionRequestStd, ActionRequestWithId>
FailParams::new_no_fail_data(time_stamp, &tmtc_err::NOT_ENOUGH_APP_DATA),
)
.expect("Sending start failure failed");
return Err(PusPacketHandlingError::NotEnoughAppData {
return Err(GenericConversionError::NotEnoughAppData {
expected: 8,
found: user_data.len(),
});
@ -166,7 +166,7 @@ impl PusTcToRequestConverter<ActivePusActionRequestStd, ActionRequestWithId>
if subservice == 128 {
let token = verif_reporter
.start_success(token, time_stamp)
.map_err(|e| e.0)?;
.expect("sending start success verification failed");
Ok((
ActivePusActionRequestStd::new(
action_id,
@ -189,7 +189,7 @@ impl PusTcToRequestConverter<ActivePusActionRequestStd, ActionRequestWithId>
FailParams::new_no_fail_data(time_stamp, &tmtc_err::INVALID_PUS_SUBSERVICE),
)
.expect("Sending start failure failed");
Err(PusPacketHandlingError::InvalidSubservice(subservice))
Err(GenericConversionError::InvalidSubservice(subservice))
}
}
}
@ -236,7 +236,7 @@ pub fn create_action_service_static(
reply_receiver,
);
Pus8Wrapper {
action_request_handler,
service: action_request_handler,
}
}
@ -277,7 +277,7 @@ pub fn create_action_service_dynamic(
reply_receiver,
);
Pus8Wrapper {
action_request_handler,
service: action_request_handler,
}
}
@ -287,7 +287,7 @@ pub struct Pus8Wrapper<
TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
> {
pub(crate) action_request_handler: PusTargetedRequestService<
pub(crate) service: PusTargetedRequestService<
TcReceiver,
TmSender,
TcInMemConverter,
@ -308,8 +308,8 @@ impl<
VerificationReporter: VerificationReportingProvider,
> Pus8Wrapper<TcReceiver, TmSender, TcInMemConverter, VerificationReporter>
{
pub fn handle_next_packet(&mut self, time_stamp: &[u8]) -> bool {
match self.action_request_handler.handle_one_tc(time_stamp) {
pub fn poll_and_handle_next_tc(&mut self, time_stamp: &[u8]) -> bool {
match self.service.poll_and_handle_next_tc(time_stamp) {
Ok(result) => match result {
PusPacketHandlerResult::RequestHandled => {}
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {
@ -331,4 +331,14 @@ impl<
}
false
}
pub fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> bool {
match self.service.poll_and_check_next_reply(time_stamp) {
Ok(packet_handled) => packet_handled,
Err(e) => {
log::warn!("PUS 8: Handling reply failed with error {e:?}");
false
}
}
}
}

View File

@ -8,12 +8,12 @@ use satrs::pus::verification::{
use satrs::pus::{
ActivePusRequestStd, ActiveRequestProvider, DefaultActiveRequestMap, EcssTcAndToken,
EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTcReceiverCore,
EcssTmSenderCore, EcssTmtcError, MpscTcReceiver, PusPacketHandlerResult,
PusPacketHandlingError, PusReplyHandler, PusServiceHelper, PusTcToRequestConverter,
EcssTmSenderCore, EcssTmtcError, GenericConversionError, MpscTcReceiver,
PusPacketHandlerResult, PusReplyHandler, PusServiceHelper, PusTcToRequestConverter,
TmAsVecSenderWithId, TmAsVecSenderWithMpsc, TmInSharedPoolSenderWithBoundedMpsc,
TmInSharedPoolSenderWithId,
};
use satrs::request::{TargetAndApidId, GenericMessage};
use satrs::request::{GenericMessage, TargetAndApidId};
use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::{hk, PusPacket};
use satrs::tmtc::tm_helper::SharedTmPool;
@ -59,7 +59,7 @@ impl PusReplyHandler<ActivePusRequestStd, HkReply> for HkReplyHandler {
HkReply::Ack => {
verification_handler
.completion_success(active_request.token(), time_stamp)
.expect("Sending end success TM failed");
.expect("sending completio success verification failed");
}
};
Ok(true)
@ -72,7 +72,13 @@ impl PusReplyHandler<ActivePusRequestStd, HkReply> for HkReplyHandler {
time_stamp: &[u8],
_tm_sender: &impl EcssTmSenderCore,
) -> Result<(), Self::Error> {
generic_pus_request_timeout_handler(active_request, verification_handler, time_stamp, "HK")
generic_pus_request_timeout_handler(
active_request,
verification_handler,
time_stamp,
"HK",
)?;
Ok(())
}
}
@ -89,7 +95,7 @@ impl Default for ExampleHkRequestConverter {
}
impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for ExampleHkRequestConverter {
type Error = PusPacketHandlingError;
type Error = GenericConversionError;
fn convert(
&mut self,
@ -112,7 +118,7 @@ impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for ExampleHkReques
),
)
.expect("Sending start failure TM failed");
return Err(PusPacketHandlingError::NotEnoughAppData {
return Err(GenericConversionError::NotEnoughAppData {
expected: 4,
found: 0,
});
@ -128,7 +134,7 @@ impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for ExampleHkReques
verif_reporter
.start_failure(token, FailParams::new(time_stamp, err, &user_data_len_raw))
.expect("Sending start failure TM failed");
return Err(PusPacketHandlingError::NotEnoughAppData {
return Err(GenericConversionError::NotEnoughAppData {
expected: 8,
found: 4,
});
@ -145,7 +151,7 @@ impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for ExampleHkReques
FailParams::new(time_stamp, &tmtc_err::INVALID_PUS_SUBSERVICE, &[subservice]),
)
.expect("Sending start failure TM failed");
return Err(PusPacketHandlingError::InvalidSubservice(subservice));
return Err(GenericConversionError::InvalidSubservice(subservice));
}
let request = match standard_subservice.unwrap() {
hk::Subservice::TcEnableHkGeneration | hk::Subservice::TcEnableDiagGeneration => {
@ -171,7 +177,7 @@ impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for ExampleHkReques
),
)
.expect("Sending start failure TM failed");
return Err(PusPacketHandlingError::NotEnoughAppData {
return Err(GenericConversionError::NotEnoughAppData {
expected: 12,
found: user_data.len(),
});
@ -192,12 +198,13 @@ impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for ExampleHkReques
),
)
.expect("Sending start failure TM failed");
return Err(PusPacketHandlingError::InvalidSubservice(subservice));
return Err(GenericConversionError::InvalidSubservice(subservice));
}
};
let token = verif_reporter
.start_success(token, time_stamp)
.map_err(|e| e.0)?;
.expect("Sending start success verification failed");
Ok((
ActivePusRequestStd::new(target_id_and_apid.into(), token, self.timeout),
request,
@ -239,9 +246,11 @@ pub fn create_hk_service_static(
DefaultActiveRequestMap::default(),
HkReplyHandler::default(),
request_router,
reply_receiver
reply_receiver,
);
Pus3Wrapper { pus_3_handler }
Pus3Wrapper {
service: pus_3_handler,
}
}
pub fn create_hk_service_dynamic(
@ -275,9 +284,11 @@ pub fn create_hk_service_dynamic(
DefaultActiveRequestMap::default(),
HkReplyHandler::default(),
request_router,
reply_receiver
reply_receiver,
);
Pus3Wrapper { pus_3_handler }
Pus3Wrapper {
service: pus_3_handler,
}
}
pub struct Pus3Wrapper<
@ -286,7 +297,7 @@ pub struct Pus3Wrapper<
TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
> {
pub(crate) pus_3_handler: PusTargetedRequestService<
pub(crate) service: PusTargetedRequestService<
TcReceiver,
TmSender,
TcInMemConverter,
@ -307,8 +318,8 @@ impl<
VerificationReporter: VerificationReportingProvider,
> Pus3Wrapper<TcReceiver, TmSender, TcInMemConverter, VerificationReporter>
{
pub fn handle_next_packet(&mut self, time_stamp: &[u8]) -> bool {
match self.pus_3_handler.handle_one_tc(time_stamp) {
pub fn poll_and_handle_next_tc(&mut self, time_stamp: &[u8]) -> bool {
match self.service.poll_and_handle_next_tc(time_stamp) {
Ok(result) => match result {
PusPacketHandlerResult::RequestHandled => {}
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {
@ -330,4 +341,14 @@ impl<
}
false
}
pub fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> bool {
match self.service.poll_and_check_next_reply(time_stamp) {
Ok(packet_handled) => packet_handled,
Err(e) => {
log::warn!("PUS 3: Handling reply failed with error {e:?}");
false
}
}
}
}

View File

@ -1,16 +1,17 @@
use crate::requests::GenericRequestRouter;
use crate::tmtc::MpscStoreAndSendError;
use log::warn;
use satrs::pus::action::ActivePusActionRequestStd;
use satrs::pus::verification::{self, FailParams, VerificationReportingProvider};
use satrs::pus::verification::{
self, FailParams, TcStateAccepted, VerificationReportingProvider, VerificationToken,
};
use satrs::pus::{
ActiveRequestMapProvider, ActiveRequestProvider, EcssTcAndToken, EcssTcInMemConverter,
EcssTcReceiverCore, EcssTmSenderCore, EcssTmtcError, GenericRoutingError,
PusPacketHandlerResult, PusPacketHandlingError, PusReplyHandler, PusRequestRouter,
PusServiceHelper, PusTcToRequestConverter, TcInMemory,
EcssTcReceiverCore, EcssTmSenderCore, EcssTmtcError, GenericConversionError,
GenericRoutingError, PusPacketHandlerResult, PusPacketHandlingError, PusReplyHandler,
PusRequestRouter, PusServiceHelper, PusTcToRequestConverter, TcInMemory,
};
use satrs::queue::GenericReceiveError;
use satrs::request::{GenericMessage, MessageReceiver, MessageSender, MessageSenderAndReceiver};
use satrs::request::GenericMessage;
use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::PusServiceId;
use satrs::spacepackets::time::cds::TimeProvider;
@ -79,12 +80,32 @@ impl<VerificationReporter: VerificationReportingProvider> PusReceiver<Verificati
}
}
/// This is a generic handler class for all PUS services where a PUS telecommand is converted
/// to a targeted request.
///
/// The generic steps for this process are the following
///
/// 1. Poll for TC packets
/// 2. Convert the raw packets to a [PusTcReader].
/// 3. Convert the PUS TC to a typed request using the [PusTcToRequestConverter].
/// 4. Route the requests using the [GenericRequestRouter].
/// 5. Add the request to the active request map using the [ActiveRequestMapProvider] abstraction.
/// 6. Check for replies which complete the forwarded request. The handler takes care of
/// the verification process.
/// 7. Check for timeouts of active requests. Generally, the timeout on the service level should
/// be highest expected timeout for the given target.
///
/// The handler exposes the following API:
///
/// 1. [Self::handle_one_tc] which tries to poll and handle one TC packet, covering steps 1-5.
/// 2. [Self::check_one_reply] which tries to poll and handle one reply, covering step 6.
/// 3. [Self::check_for_request_timeouts] which checks for request timeouts, covering step 7.
pub struct PusTargetedRequestService<
TcReceiver: EcssTcReceiverCore,
TmSender: EcssTmSenderCore,
TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
RequestConverter: PusTcToRequestConverter<ActiveRequestInfo, RequestType, Error = PusPacketHandlingError>,
RequestConverter: PusTcToRequestConverter<ActiveRequestInfo, RequestType, Error = GenericConversionError>,
ReplyHandler: PusReplyHandler<ActiveRequestInfo, ReplyType, Error = EcssTmtcError>,
ActiveRequestMap: ActiveRequestMapProvider<ActiveRequestInfo>,
ActiveRequestInfo: ActiveRequestProvider,
@ -106,7 +127,7 @@ impl<
TmSender: EcssTmSenderCore,
TcInMemConverter: EcssTcInMemConverter,
VerificationReporter: VerificationReportingProvider,
RequestConverter: PusTcToRequestConverter<ActiveRequestInfo, RequestType, Error = PusPacketHandlingError>,
RequestConverter: PusTcToRequestConverter<ActiveRequestInfo, RequestType, Error = GenericConversionError>,
ReplyHandler: PusReplyHandler<ActiveRequestInfo, ReplyType, Error = EcssTmtcError>,
ActiveRequestMap: ActiveRequestMapProvider<ActiveRequestInfo>,
ActiveRequestInfo: ActiveRequestProvider,
@ -152,7 +173,7 @@ where
}
}
pub fn handle_one_tc(
pub fn poll_and_handle_next_tc(
&mut self,
time_stamp: &[u8],
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
@ -161,52 +182,103 @@ where
return Ok(PusPacketHandlerResult::Empty);
}
let ecss_tc_and_token = possible_packet.unwrap();
let tc = self
.service_helper
.tc_in_mem_converter
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?;
let (request_info, request) = self.request_converter.convert(
self.service_helper
.tc_in_mem_converter_mut()
.cache(&ecss_tc_and_token.tc_in_memory)?;
let tc = self.service_helper.tc_in_mem_converter().convert()?;
let (request_info, request) = match self.request_converter.convert(
ecss_tc_and_token.token,
&tc,
time_stamp,
&self.service_helper.common.verification_handler,
)?;
&self.service_helper.common.verif_reporter,
) {
Ok((info, req)) => (info, req),
Err(e) => {
self.handle_conversion_to_request_error(&e, ecss_tc_and_token.token, time_stamp);
return Err(e.into());
}
};
let verif_request_id = verification::RequestId::new(&tc);
if let Err(e) =
self.request_router
.route(request_info.target_id(), request, request_info.token())
//if let Err(e) =
match self
.request_router
.route(request_info.target_id(), request, request_info.token())
{
let target_id = request_info.target_id();
self.active_request_map
.insert(&verif_request_id.into(), request_info);
self.request_router.handle_error(
target_id,
request_info.token(),
&tc,
e.clone(),
time_stamp,
&self.service_helper.common.verification_handler,
);
return Err(e.into());
Ok(()) => {
self.active_request_map
.insert(&verif_request_id.into(), request_info);
}
Err(e) => {
self.request_router.handle_error_generic(
&request_info,
&tc,
e,
time_stamp,
self.service_helper.verif_reporter(),
);
}
}
Ok(PusPacketHandlerResult::RequestHandled)
}
pub fn check_one_reply(&mut self, time_stamp: &[u8]) -> Result<bool, EcssTmtcError> {
fn handle_conversion_to_request_error(
&mut self,
error: &GenericConversionError,
token: VerificationToken<TcStateAccepted>,
time_stamp: &[u8],
) {
match error {
GenericConversionError::WrongService(service) => {
let service_slice: [u8; 1] = [*service];
self.service_helper
.verif_reporter()
.completion_failure(
token,
FailParams::new(time_stamp, &tmtc_err::INVALID_PUS_SERVICE, &service_slice),
)
.expect("Sending completion failure failed");
}
GenericConversionError::InvalidSubservice(subservice) => {
let subservice_slice: [u8; 1] = [*subservice];
self.service_helper
.verif_reporter()
.completion_failure(
token,
FailParams::new(
time_stamp,
&tmtc_err::INVALID_PUS_SUBSERVICE,
&subservice_slice,
),
)
.expect("Sending completion failure failed");
}
GenericConversionError::NotEnoughAppData { expected, found } => {
let mut context_info = (*found as u32).to_be_bytes().to_vec();
context_info.extend_from_slice(&(*expected as u32).to_be_bytes());
self.service_helper
.verif_reporter()
.completion_failure(
token,
FailParams::new(time_stamp, &tmtc_err::NOT_ENOUGH_APP_DATA, &context_info),
)
.expect("Sending completion failure failed");
}
// Do nothing.. this is service-level and can not be handled generically here.
GenericConversionError::InvalidAppData(_) => (),
}
}
pub fn poll_and_check_next_reply(&mut self, time_stamp: &[u8]) -> Result<bool, EcssTmtcError> {
match self.reply_receiver.try_recv() {
Ok(reply) => {
self.handle_reply(&reply, time_stamp)?;
Ok(true)
}
Err(e) => match e {
mpsc::TryRecvError::Empty => {
return Ok(false);
}
mpsc::TryRecvError::Disconnected => {
return Err(EcssTmtcError::Receive(GenericReceiveError::TxDisconnected(
None,
)));
}
mpsc::TryRecvError::Empty => Ok(false),
mpsc::TryRecvError::Disconnected => Err(EcssTmtcError::Receive(
GenericReceiveError::TxDisconnected(None),
)),
},
}
}
@ -220,6 +292,7 @@ where
if active_req_opt.is_none() {
self.reply_handler
.handle_unexpected_reply(reply, &self.service_helper.common.tm_sender)?;
return Ok(());
}
let active_request = active_req_opt.unwrap();
let request_finished = self
@ -227,7 +300,7 @@ where
.handle_reply(
reply,
active_request,
&self.service_helper.common.verification_handler,
&self.service_helper.common.verif_reporter,
time_stamp,
&self.service_helper.common.tm_sender,
)
@ -270,7 +343,8 @@ pub fn generic_pus_request_timeout_handler(
&[],
),
)
.map_err(|e| e.0)
.map_err(|e| e.0)?;
Ok(())
}
impl<VerificationReporter: VerificationReportingProvider> PusReceiver<VerificationReporter> {

View File

@ -18,8 +18,8 @@ pub struct PusStack<
VerificationReporter: VerificationReportingProvider,
> {
event_srv: Pus5Wrapper<TcReceiver, TmSender, TcInMemConverter, VerificationReporter>,
hk_srv: Pus3Wrapper<TcReceiver, TmSender, TcInMemConverter, VerificationReporter>,
action_srv: Pus8Wrapper<TcReceiver, TmSender, TcInMemConverter, VerificationReporter>,
hk_srv_wrapper: Pus3Wrapper<TcReceiver, TmSender, TcInMemConverter, VerificationReporter>,
action_srv_wrapper: Pus8Wrapper<TcReceiver, TmSender, TcInMemConverter, VerificationReporter>,
schedule_srv: Pus11Wrapper<TcReceiver, TmSender, TcInMemConverter, VerificationReporter>,
test_srv: Service17CustomWrapper<TcReceiver, TmSender, TcInMemConverter, VerificationReporter>,
}
@ -45,10 +45,10 @@ impl<
) -> Self {
Self {
event_srv,
action_srv,
action_srv_wrapper: action_srv,
schedule_srv,
test_srv,
hk_srv,
hk_srv_wrapper: hk_srv,
}
}
@ -59,18 +59,33 @@ impl<
.to_vec()
.unwrap();
loop {
let mut all_queues_empty = true;
let mut is_srv_finished = |srv_handler_finished: bool| {
if !srv_handler_finished {
all_queues_empty = false;
}
};
is_srv_finished(self.test_srv.handle_next_packet(&time_stamp));
is_srv_finished(self.schedule_srv.handle_next_packet(&time_stamp));
is_srv_finished(self.event_srv.handle_next_packet(&time_stamp));
is_srv_finished(self.action_srv.handle_next_packet(&time_stamp));
is_srv_finished(self.hk_srv.handle_next_packet(&time_stamp));
if all_queues_empty {
let mut nothing_to_do = true;
let mut is_srv_finished =
|tc_handling_done: bool, reply_handling_done: Option<bool>| {
if !tc_handling_done
|| (reply_handling_done.is_some() && !reply_handling_done.unwrap())
{
nothing_to_do = false;
}
};
is_srv_finished(self.test_srv.handle_next_packet(&time_stamp), None);
is_srv_finished(self.schedule_srv.handle_next_packet(&time_stamp), None);
is_srv_finished(self.event_srv.handle_next_packet(&time_stamp), None);
is_srv_finished(
self.action_srv_wrapper.poll_and_handle_next_tc(&time_stamp),
Some(
self.action_srv_wrapper
.poll_and_handle_next_reply(&time_stamp),
),
);
is_srv_finished(
self.hk_srv_wrapper.poll_and_handle_next_tc(&time_stamp),
Some(self.hk_srv_wrapper.poll_and_handle_next_reply(&time_stamp)),
);
if nothing_to_do {
// Timeout checking is only done once.
self.action_srv_wrapper.service.check_for_request_timeouts();
self.hk_srv_wrapper.service.check_for_request_timeouts();
break;
}
}

View File

@ -150,22 +150,19 @@ impl<
let start_token = self
.pus17_handler
.service_helper
.common
.verification_handler
.verif_reporter()
.start_success(token, &stamp_buf)
.expect("Error sending start success");
self.pus17_handler
.service_helper
.common
.verification_handler
.verif_reporter()
.completion_success(start_token, &stamp_buf)
.expect("Error sending completion success");
} else {
let fail_data = [tc.subservice()];
self.pus17_handler
.service_helper
.common
.verification_handler
.verif_reporter()
.start_failure(
token,
FailParams::new(

View File

@ -7,13 +7,13 @@ use satrs::hk::HkRequest;
use satrs::mode::ModeRequest;
use satrs::pus::action::ActionRequestWithId;
use satrs::pus::verification::{
FailParams, TcStateAccepted, VerificationReportingProvider, VerificationToken,
FailParams, TcStateStarted, VerificationReportingProvider, VerificationToken,
};
use satrs::pus::{GenericRoutingError, PusRequestRouter};
use satrs::pus::{ActiveRequestProvider, GenericRoutingError, PusRequestRouter};
use satrs::queue::GenericSendError;
use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::PusPacket;
use satrs::TargetId;
use satrs::ComponentId;
use satrs_example::config::tmtc_err;
#[allow(dead_code)]
@ -27,21 +27,21 @@ pub enum Request {
#[derive(Clone, Debug, new)]
pub struct TargetedRequest {
pub(crate) target_id: TargetId,
pub(crate) target_id: ComponentId,
pub(crate) request: Request,
}
#[derive(Clone, Debug)]
pub struct RequestWithToken {
pub(crate) targeted_request: TargetedRequest,
pub(crate) token: VerificationToken<TcStateAccepted>,
pub(crate) token: VerificationToken<TcStateStarted>,
}
impl RequestWithToken {
pub fn new(
target_id: TargetId,
target_id: ComponentId,
request: Request,
token: VerificationToken<TcStateAccepted>,
token: VerificationToken<TcStateStarted>,
) -> Self {
Self {
targeted_request: TargetedRequest::new(target_id, request),
@ -51,15 +51,12 @@ impl RequestWithToken {
}
#[derive(Default, Clone)]
pub struct GenericRequestRouter(pub HashMap<TargetId, mpsc::Sender<RequestWithToken>>);
pub struct GenericRequestRouter(pub HashMap<ComponentId, mpsc::Sender<RequestWithToken>>);
impl GenericRequestRouter {
fn handle_error_generic(
pub(crate) fn handle_error_generic(
&self,
target_id: satrs::TargetId,
token: satrs::pus::verification::VerificationToken<
satrs::pus::verification::TcStateAccepted,
>,
active_request: &impl ActiveRequestProvider,
tc: &PusTcReader,
error: GenericRoutingError,
time_stamp: &[u8],
@ -74,32 +71,22 @@ impl GenericRequestRouter {
let mut fail_data: [u8; 8] = [0; 8];
fail_data.copy_from_slice(&id.to_be_bytes());
verif_reporter
.start_failure(
token,
.completion_failure(
active_request.token(),
FailParams::new(time_stamp, &tmtc_err::UNKNOWN_TARGET_ID, &fail_data),
)
.expect("Sending start failure failed");
}
GenericRoutingError::SendError(_) => {
GenericRoutingError::Send(_) => {
let mut fail_data: [u8; 8] = [0; 8];
fail_data.copy_from_slice(&target_id.to_be_bytes());
fail_data.copy_from_slice(&active_request.target_id().to_be_bytes());
verif_reporter
.start_failure(
token,
.completion_failure(
active_request.token(),
FailParams::new(time_stamp, &tmtc_err::ROUTING_ERROR, &fail_data),
)
.expect("Sending start failure failed");
}
GenericRoutingError::NotEnoughAppData { expected, found } => {
let mut context_info = (found as u32).to_be_bytes().to_vec();
context_info.extend_from_slice(&(expected as u32).to_be_bytes());
verif_reporter
.start_failure(
token,
FailParams::new(time_stamp, &tmtc_err::NOT_ENOUGH_APP_DATA, &context_info),
)
.expect("Sending start failure failed");
}
}
}
}
@ -108,9 +95,9 @@ impl PusRequestRouter<HkRequest> for GenericRequestRouter {
fn route(
&self,
target_id: TargetId,
target_id: ComponentId,
hk_request: HkRequest,
token: VerificationToken<TcStateAccepted>,
token: VerificationToken<TcStateStarted>,
) -> Result<(), Self::Error> {
if let Some(sender) = self.0.get(&target_id) {
sender
@ -119,23 +106,10 @@ impl PusRequestRouter<HkRequest> for GenericRequestRouter {
Request::Hk(hk_request),
token,
))
.map_err(|_| GenericRoutingError::SendError(GenericSendError::RxDisconnected))?;
.map_err(|_| GenericRoutingError::Send(GenericSendError::RxDisconnected))?;
}
Ok(())
}
fn handle_error(
&self,
target_id: satrs::TargetId,
token: satrs::pus::verification::VerificationToken<
satrs::pus::verification::TcStateAccepted,
>,
tc: &PusTcReader,
error: GenericRoutingError,
time_stamp: &[u8],
verif_reporter: &impl VerificationReportingProvider,
) {
self.handle_error_generic(target_id, token, tc, error, time_stamp, verif_reporter)
}
}
impl PusRequestRouter<ActionRequestWithId> for GenericRequestRouter {
@ -143,9 +117,9 @@ impl PusRequestRouter<ActionRequestWithId> for GenericRequestRouter {
fn route(
&self,
target_id: TargetId,
target_id: ComponentId,
action_request: ActionRequestWithId,
token: VerificationToken<TcStateAccepted>,
token: VerificationToken<TcStateStarted>,
) -> Result<(), Self::Error> {
if let Some(sender) = self.0.get(&target_id) {
sender
@ -154,21 +128,8 @@ impl PusRequestRouter<ActionRequestWithId> for GenericRequestRouter {
Request::Action(action_request),
token,
))
.map_err(|_| GenericRoutingError::SendError(GenericSendError::RxDisconnected))?;
.map_err(|_| GenericRoutingError::Send(GenericSendError::RxDisconnected))?;
}
Ok(())
}
fn handle_error(
&self,
target_id: satrs::TargetId,
token: satrs::pus::verification::VerificationToken<
satrs::pus::verification::TcStateAccepted,
>,
tc: &PusTcReader,
error: GenericRoutingError,
time_stamp: &[u8],
verif_reporter: &impl VerificationReportingProvider,
) {
self.handle_error_generic(target_id, token, tc, error, time_stamp, verif_reporter)
}
}