it compiles again
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit
This commit is contained in:
parent
9903194cfc
commit
83e0a50e2a
@ -3,7 +3,7 @@ use satrs::action::{ActionRequest, ActionRequestVariant};
|
|||||||
use satrs::params::WritableToBeBytes;
|
use satrs::params::WritableToBeBytes;
|
||||||
use satrs::pool::{SharedStaticMemoryPool, StoreAddr};
|
use satrs::pool::{SharedStaticMemoryPool, StoreAddr};
|
||||||
use satrs::pus::action::{
|
use satrs::pus::action::{
|
||||||
ActionReplyPus, ActionReplyPusWithActionId, ActionRequestWithId, ActivePusActionRequest,
|
ActionReplyPus, ActionReplyPusWithActionId, ActionRequestWithId, ActivePusActionRequestStd,
|
||||||
DefaultActiveActionRequestMap,
|
DefaultActiveActionRequestMap,
|
||||||
};
|
};
|
||||||
use satrs::pus::verification::{
|
use satrs::pus::verification::{
|
||||||
@ -21,7 +21,6 @@ use satrs::pus::{
|
|||||||
use satrs::request::{GenericMessage, TargetAndApidId};
|
use satrs::request::{GenericMessage, TargetAndApidId};
|
||||||
use satrs::spacepackets::ecss::tc::PusTcReader;
|
use satrs::spacepackets::ecss::tc::PusTcReader;
|
||||||
use satrs::spacepackets::ecss::{EcssEnumU16, PusPacket};
|
use satrs::spacepackets::ecss::{EcssEnumU16, PusPacket};
|
||||||
use satrs::spacepackets::time::UnixTimestamp;
|
|
||||||
use satrs::tmtc::tm_helper::SharedTmPool;
|
use satrs::tmtc::tm_helper::SharedTmPool;
|
||||||
use satrs::ChannelId;
|
use satrs::ChannelId;
|
||||||
use satrs_example::config::{tmtc_err, TcReceiverId, TmSenderId, PUS_APID};
|
use satrs_example::config::{tmtc_err, TcReceiverId, TmSenderId, PUS_APID};
|
||||||
@ -44,13 +43,13 @@ impl Default for ActionReplyHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for ActionReplyHandler {
|
impl PusReplyHandler<ActivePusActionRequestStd, ActionReplyPusWithActionId> for ActionReplyHandler {
|
||||||
type Error = EcssTmtcError;
|
type Error = EcssTmtcError;
|
||||||
|
|
||||||
fn handle_unexpected_reply(
|
fn handle_unexpected_reply(
|
||||||
&mut self,
|
&mut self,
|
||||||
reply: &GenericMessage<ActionReplyPusWithActionId>,
|
reply: &GenericMessage<ActionReplyPusWithActionId>,
|
||||||
tm_sender: &impl EcssTmSenderCore,
|
_tm_sender: &impl EcssTmSenderCore,
|
||||||
) {
|
) {
|
||||||
log::warn!("received unexpected reply for service 8: {reply:?}");
|
log::warn!("received unexpected reply for service 8: {reply:?}");
|
||||||
}
|
}
|
||||||
@ -58,12 +57,12 @@ impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for Act
|
|||||||
fn handle_reply(
|
fn handle_reply(
|
||||||
&mut self,
|
&mut self,
|
||||||
reply: &satrs::request::GenericMessage<ActionReplyPusWithActionId>,
|
reply: &satrs::request::GenericMessage<ActionReplyPusWithActionId>,
|
||||||
active_request: &ActivePusActionRequest,
|
active_request: &ActivePusActionRequestStd,
|
||||||
verification_handler: &impl VerificationReportingProvider,
|
verification_handler: &impl VerificationReportingProvider,
|
||||||
time_stamp: &[u8],
|
time_stamp: &[u8],
|
||||||
tm_sender: &impl EcssTmSenderCore,
|
_tm_sender: &impl EcssTmSenderCore,
|
||||||
) -> Result<bool, Self::Error> {
|
) -> Result<bool, Self::Error> {
|
||||||
let remove_entry = match reply.message.variant {
|
let remove_entry = match &reply.message.variant {
|
||||||
ActionReplyPus::CompletionFailed { error_code, params } => {
|
ActionReplyPus::CompletionFailed { error_code, params } => {
|
||||||
let fail_data_len = params.write_to_be_bytes(&mut self.fail_data_buf)?;
|
let fail_data_len = params.write_to_be_bytes(&mut self.fail_data_buf)?;
|
||||||
verification_handler
|
verification_handler
|
||||||
@ -71,7 +70,7 @@ impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for Act
|
|||||||
active_request.token(),
|
active_request.token(),
|
||||||
FailParams::new(
|
FailParams::new(
|
||||||
time_stamp,
|
time_stamp,
|
||||||
&error_code,
|
error_code,
|
||||||
&self.fail_data_buf[..fail_data_len],
|
&self.fail_data_buf[..fail_data_len],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -89,8 +88,8 @@ impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for Act
|
|||||||
active_request.token(),
|
active_request.token(),
|
||||||
FailParamsWithStep::new(
|
FailParamsWithStep::new(
|
||||||
time_stamp,
|
time_stamp,
|
||||||
&EcssEnumU16::new(step),
|
&EcssEnumU16::new(*step),
|
||||||
&error_code,
|
error_code,
|
||||||
&self.fail_data_buf[..fail_data_len],
|
&self.fail_data_buf[..fail_data_len],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -107,7 +106,7 @@ impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for Act
|
|||||||
verification_handler.step_success(
|
verification_handler.step_success(
|
||||||
&active_request.token(),
|
&active_request.token(),
|
||||||
time_stamp,
|
time_stamp,
|
||||||
EcssEnumU16::new(step),
|
EcssEnumU16::new(*step),
|
||||||
)?;
|
)?;
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@ -130,7 +129,7 @@ impl PusReplyHandler<ActivePusActionRequest, ActionReplyPusWithActionId> for Act
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ExampleActionRequestConverter {}
|
pub struct ExampleActionRequestConverter {}
|
||||||
|
|
||||||
impl PusTcToRequestConverter<ActivePusActionRequest, ActionRequestWithId>
|
impl PusTcToRequestConverter<ActivePusActionRequestStd, ActionRequestWithId>
|
||||||
for ExampleActionRequestConverter
|
for ExampleActionRequestConverter
|
||||||
{
|
{
|
||||||
type Error = PusPacketHandlingError;
|
type Error = PusPacketHandlingError;
|
||||||
@ -141,7 +140,7 @@ impl PusTcToRequestConverter<ActivePusActionRequest, ActionRequestWithId>
|
|||||||
tc: &PusTcReader,
|
tc: &PusTcReader,
|
||||||
time_stamp: &[u8],
|
time_stamp: &[u8],
|
||||||
verif_reporter: &impl VerificationReportingProvider,
|
verif_reporter: &impl VerificationReportingProvider,
|
||||||
) -> Result<(ActivePusActionRequest, ActionRequestWithId), Self::Error> {
|
) -> Result<(ActivePusActionRequestStd, ActionRequestWithId), Self::Error> {
|
||||||
let subservice = tc.subservice();
|
let subservice = tc.subservice();
|
||||||
let user_data = tc.user_data();
|
let user_data = tc.user_data();
|
||||||
if user_data.len() < 8 {
|
if user_data.len() < 8 {
|
||||||
@ -163,11 +162,10 @@ impl PusTcToRequestConverter<ActivePusActionRequest, ActionRequestWithId>
|
|||||||
.start_success(token, time_stamp)
|
.start_success(token, time_stamp)
|
||||||
.map_err(|e| e.0)?;
|
.map_err(|e| e.0)?;
|
||||||
Ok((
|
Ok((
|
||||||
ActivePusActionRequest::new(
|
ActivePusActionRequestStd::new(
|
||||||
action_id,
|
action_id,
|
||||||
target_id_and_apid.into(),
|
target_id_and_apid.into(),
|
||||||
token,
|
token,
|
||||||
UnixTimestamp::from_now().unwrap(),
|
|
||||||
Duration::from_secs(30),
|
Duration::from_secs(30),
|
||||||
),
|
),
|
||||||
ActionRequestWithId {
|
ActionRequestWithId {
|
||||||
@ -309,7 +307,7 @@ pub struct Pus8Wrapper<
|
|||||||
ExampleActionRequestConverter,
|
ExampleActionRequestConverter,
|
||||||
ActionReplyHandler,
|
ActionReplyHandler,
|
||||||
DefaultActiveActionRequestMap,
|
DefaultActiveActionRequestMap,
|
||||||
ActivePusActionRequest,
|
ActivePusActionRequestStd,
|
||||||
ActionRequestWithId,
|
ActionRequestWithId,
|
||||||
ActionReplyPusWithActionId,
|
ActionReplyPusWithActionId,
|
||||||
>,
|
>,
|
||||||
|
@ -6,7 +6,7 @@ use satrs::pus::verification::{
|
|||||||
VerificationReporterWithVecMpscSender, VerificationReportingProvider, VerificationToken,
|
VerificationReporterWithVecMpscSender, VerificationReportingProvider, VerificationToken,
|
||||||
};
|
};
|
||||||
use satrs::pus::{
|
use satrs::pus::{
|
||||||
ActivePusRequest, ActiveRequestProvider, DefaultActiveRequestMap, EcssTcAndToken,
|
ActivePusRequestStd, ActiveRequestProvider, DefaultActiveRequestMap, EcssTcAndToken,
|
||||||
EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTcReceiverCore,
|
EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTcReceiverCore,
|
||||||
EcssTmSenderCore, MpscTcReceiver, PusPacketHandlerResult, PusPacketHandlingError,
|
EcssTmSenderCore, MpscTcReceiver, PusPacketHandlerResult, PusPacketHandlingError,
|
||||||
PusReplyHandler, PusServiceHelper, PusTcToRequestConverter, TmAsVecSenderWithId,
|
PusReplyHandler, PusServiceHelper, PusTcToRequestConverter, TmAsVecSenderWithId,
|
||||||
@ -15,9 +15,8 @@ use satrs::pus::{
|
|||||||
use satrs::request::TargetAndApidId;
|
use satrs::request::TargetAndApidId;
|
||||||
use satrs::spacepackets::ecss::tc::PusTcReader;
|
use satrs::spacepackets::ecss::tc::PusTcReader;
|
||||||
use satrs::spacepackets::ecss::{hk, PusPacket};
|
use satrs::spacepackets::ecss::{hk, PusPacket};
|
||||||
use satrs::spacepackets::time::UnixTimestamp;
|
|
||||||
use satrs::tmtc::tm_helper::SharedTmPool;
|
use satrs::tmtc::tm_helper::SharedTmPool;
|
||||||
use satrs::{ChannelId, TargetId};
|
use satrs::ChannelId;
|
||||||
use satrs_example::config::{hk_err, tmtc_err, TcReceiverId, TmSenderId, PUS_APID};
|
use satrs_example::config::{hk_err, tmtc_err, TcReceiverId, TmSenderId, PUS_APID};
|
||||||
use std::sync::mpsc::{self};
|
use std::sync::mpsc::{self};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@ -31,25 +30,16 @@ pub enum HkReply {
|
|||||||
Ack,
|
Ack,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HkReplyHandler {
|
#[derive(Default)]
|
||||||
fail_data_buf: [u8; 128],
|
pub struct HkReplyHandler {}
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for HkReplyHandler {
|
impl PusReplyHandler<ActivePusRequestStd, HkReply> for HkReplyHandler {
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
fail_data_buf: [0; 128],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PusReplyHandler<ActivePusRequest, HkReply> for HkReplyHandler {
|
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
fn handle_unexpected_reply(
|
fn handle_unexpected_reply(
|
||||||
&mut self,
|
&mut self,
|
||||||
reply: &satrs::request::GenericMessage<HkReply>,
|
reply: &satrs::request::GenericMessage<HkReply>,
|
||||||
tm_sender: &impl EcssTmSenderCore,
|
_tm_sender: &impl EcssTmSenderCore,
|
||||||
) {
|
) {
|
||||||
log::warn!("received unexpected reply for service 3: {reply:?}");
|
log::warn!("received unexpected reply for service 3: {reply:?}");
|
||||||
}
|
}
|
||||||
@ -57,27 +47,35 @@ impl PusReplyHandler<ActivePusRequest, HkReply> for HkReplyHandler {
|
|||||||
fn handle_reply(
|
fn handle_reply(
|
||||||
&mut self,
|
&mut self,
|
||||||
reply: &satrs::request::GenericMessage<HkReply>,
|
reply: &satrs::request::GenericMessage<HkReply>,
|
||||||
active_request: &ActivePusRequest,
|
active_request: &ActivePusRequestStd,
|
||||||
verification_handler: &impl VerificationReportingProvider,
|
verification_handler: &impl VerificationReportingProvider,
|
||||||
time_stamp: &[u8],
|
time_stamp: &[u8],
|
||||||
tm_sender: &impl EcssTmSenderCore,
|
_tm_sender: &impl EcssTmSenderCore,
|
||||||
) -> Result<bool, Self::Error> {
|
) -> Result<bool, Self::Error> {
|
||||||
let remove_entry = match reply.message {
|
match reply.message {
|
||||||
HkReply::Ack => {
|
HkReply::Ack => {
|
||||||
verification_handler
|
verification_handler
|
||||||
.completion_success(active_request.token(), time_stamp)
|
.completion_success(active_request.token(), time_stamp)
|
||||||
.expect("Sending end success TM failed");
|
.expect("Sending end success TM failed");
|
||||||
true
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(remove_entry)
|
Ok(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
pub struct ExampleHkRequestConverter {
|
||||||
pub struct ExampleHkRequestConverter {}
|
timeout: Duration,
|
||||||
|
}
|
||||||
|
|
||||||
impl PusTcToRequestConverter<ActivePusRequest, HkRequest> for ExampleHkRequestConverter {
|
impl Default for ExampleHkRequestConverter {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
timeout: Duration::from_secs(60),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PusTcToRequestConverter<ActivePusRequestStd, HkRequest> for ExampleHkRequestConverter {
|
||||||
type Error = PusPacketHandlingError;
|
type Error = PusPacketHandlingError;
|
||||||
|
|
||||||
fn convert(
|
fn convert(
|
||||||
@ -86,7 +84,7 @@ impl PusTcToRequestConverter<ActivePusRequest, HkRequest> for ExampleHkRequestCo
|
|||||||
tc: &PusTcReader,
|
tc: &PusTcReader,
|
||||||
time_stamp: &[u8],
|
time_stamp: &[u8],
|
||||||
verif_reporter: &impl VerificationReportingProvider,
|
verif_reporter: &impl VerificationReportingProvider,
|
||||||
) -> Result<(ActivePusRequest, HkRequest), Self::Error> {
|
) -> Result<(ActivePusRequestStd, HkRequest), Self::Error> {
|
||||||
let user_data = tc.user_data();
|
let user_data = tc.user_data();
|
||||||
if user_data.is_empty() {
|
if user_data.is_empty() {
|
||||||
let user_data_len = user_data.len() as u32;
|
let user_data_len = user_data.len() as u32;
|
||||||
@ -188,13 +186,7 @@ impl PusTcToRequestConverter<ActivePusRequest, HkRequest> for ExampleHkRequestCo
|
|||||||
.start_success(token, time_stamp)
|
.start_success(token, time_stamp)
|
||||||
.map_err(|e| e.0)?;
|
.map_err(|e| e.0)?;
|
||||||
Ok((
|
Ok((
|
||||||
ActivePusRequest::new(
|
ActivePusRequestStd::new(target_id_and_apid.into(), token, self.timeout),
|
||||||
target_id_and_apid.into(),
|
|
||||||
token,
|
|
||||||
UnixTimestamp::from_now().unwrap(),
|
|
||||||
Duration::from_secs(60),
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
request,
|
request,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -284,8 +276,8 @@ pub struct Pus3Wrapper<
|
|||||||
VerificationReporter,
|
VerificationReporter,
|
||||||
ExampleHkRequestConverter,
|
ExampleHkRequestConverter,
|
||||||
HkReplyHandler,
|
HkReplyHandler,
|
||||||
DefaultActiveRequestMap<ActivePusRequest>,
|
DefaultActiveRequestMap<ActivePusRequestStd>,
|
||||||
ActivePusRequest,
|
ActivePusRequestStd,
|
||||||
HkRequest,
|
HkRequest,
|
||||||
HkReply,
|
HkReply,
|
||||||
>,
|
>,
|
||||||
|
@ -4,8 +4,9 @@ use log::warn;
|
|||||||
use satrs::pus::verification::{self, FailParams, VerificationReportingProvider};
|
use satrs::pus::verification::{self, FailParams, VerificationReportingProvider};
|
||||||
use satrs::pus::{
|
use satrs::pus::{
|
||||||
ActiveRequestMapProvider, ActiveRequestProvider, EcssTcAndToken, EcssTcInMemConverter,
|
ActiveRequestMapProvider, ActiveRequestProvider, EcssTcAndToken, EcssTcInMemConverter,
|
||||||
EcssTcReceiverCore, EcssTmSenderCore, PusPacketHandlerResult, PusPacketHandlingError,
|
EcssTcReceiverCore, EcssTmSenderCore, GenericRoutingError, PusPacketHandlerResult,
|
||||||
PusReplyHandler, PusRequestRouter, PusServiceHelper, PusTcToRequestConverter, TcInMemory,
|
PusPacketHandlingError, PusReplyHandler, PusRequestRouter, PusServiceHelper,
|
||||||
|
PusTcToRequestConverter, TcInMemory,
|
||||||
};
|
};
|
||||||
use satrs::request::GenericMessage;
|
use satrs::request::GenericMessage;
|
||||||
use satrs::spacepackets::ecss::tc::PusTcReader;
|
use satrs::spacepackets::ecss::tc::PusTcReader;
|
||||||
@ -120,6 +121,8 @@ impl<
|
|||||||
RequestType,
|
RequestType,
|
||||||
ReplyType,
|
ReplyType,
|
||||||
>
|
>
|
||||||
|
where
|
||||||
|
GenericRequestRouter: PusRequestRouter<RequestType, Error = GenericRoutingError>,
|
||||||
{
|
{
|
||||||
pub fn new(
|
pub fn new(
|
||||||
service_helper: PusServiceHelper<
|
service_helper: PusServiceHelper<
|
||||||
@ -156,27 +159,26 @@ impl<
|
|||||||
.service_helper
|
.service_helper
|
||||||
.tc_in_mem_converter
|
.tc_in_mem_converter
|
||||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?;
|
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?;
|
||||||
let mut partial_error = None;
|
let (request_info, request) = self.request_converter.convert(
|
||||||
let (active_request, action_request) = self.request_converter.convert(
|
|
||||||
ecss_tc_and_token.token,
|
ecss_tc_and_token.token,
|
||||||
&tc,
|
&tc,
|
||||||
&time_stamp,
|
time_stamp,
|
||||||
&self.service_helper.common.verification_handler,
|
&self.service_helper.common.verification_handler,
|
||||||
)?;
|
)?;
|
||||||
if let Err(e) = self.request_router.route(
|
let verif_request_id = verification::RequestId::new(&tc);
|
||||||
active_request.target_id(),
|
if let Err(e) =
|
||||||
action_request,
|
self.request_router
|
||||||
ecss_tc_and_token.token,
|
.route(request_info.target_id(), request, ecss_tc_and_token.token)
|
||||||
) {
|
{
|
||||||
let verif_request_id = verification::RequestId::new(&tc);
|
let target_id = request_info.target_id();
|
||||||
self.active_request_map
|
self.active_request_map
|
||||||
.insert(verif_request_id.into(), active_request);
|
.insert(&verif_request_id.into(), request_info);
|
||||||
self.request_router.handle_error(
|
self.request_router.handle_error(
|
||||||
active_request.target_id(),
|
target_id,
|
||||||
ecss_tc_and_token.token,
|
ecss_tc_and_token.token,
|
||||||
&tc,
|
&tc,
|
||||||
e.clone(),
|
e.clone(),
|
||||||
&time_stamp,
|
time_stamp,
|
||||||
&self.service_helper.common.verification_handler,
|
&self.service_helper.common.verification_handler,
|
||||||
);
|
);
|
||||||
return Err(e.into());
|
return Err(e.into());
|
||||||
@ -184,9 +186,7 @@ impl<
|
|||||||
Ok(PusPacketHandlerResult::RequestHandled)
|
Ok(PusPacketHandlerResult::RequestHandled)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_reply(&mut self, reply: &GenericMessage<ReplyType>) {
|
pub fn insert_reply(&mut self, reply: &GenericMessage<ReplyType>) {}
|
||||||
// self.reply_hook.insert_reply(reply, &self.active_request_map);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<VerificationReporter: VerificationReportingProvider> PusReceiver<VerificationReporter> {
|
impl<VerificationReporter: VerificationReportingProvider> PusReceiver<VerificationReporter> {
|
||||||
|
@ -68,8 +68,8 @@ impl<
|
|||||||
is_srv_finished(self.test_srv.handle_next_packet(&time_stamp));
|
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.schedule_srv.handle_next_packet(&time_stamp));
|
||||||
is_srv_finished(self.event_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());
|
is_srv_finished(self.action_srv.handle_next_packet(&time_stamp));
|
||||||
is_srv_finished(self.hk_srv.handle_next_packet());
|
is_srv_finished(self.hk_srv.handle_next_packet(&time_stamp));
|
||||||
if all_queues_empty {
|
if all_queues_empty {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ use std::sync::mpsc;
|
|||||||
|
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use satrs::action::ActionRequest;
|
|
||||||
use satrs::hk::HkRequest;
|
use satrs::hk::HkRequest;
|
||||||
use satrs::mode::ModeRequest;
|
use satrs::mode::ModeRequest;
|
||||||
|
use satrs::pus::action::ActionRequestWithId;
|
||||||
use satrs::pus::verification::{
|
use satrs::pus::verification::{
|
||||||
FailParams, TcStateAccepted, VerificationReportingProvider, VerificationToken,
|
FailParams, TcStateAccepted, VerificationReportingProvider, VerificationToken,
|
||||||
};
|
};
|
||||||
@ -17,21 +17,21 @@ use satrs::TargetId;
|
|||||||
use satrs_example::config::tmtc_err;
|
use satrs_example::config::tmtc_err;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Request {
|
pub enum Request {
|
||||||
Hk(HkRequest),
|
Hk(HkRequest),
|
||||||
Mode(ModeRequest),
|
Mode(ModeRequest),
|
||||||
Action(ActionRequest),
|
Action(ActionRequestWithId),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq, Debug, new)]
|
#[derive(Clone, Debug, new)]
|
||||||
pub struct TargetedRequest {
|
pub struct TargetedRequest {
|
||||||
pub(crate) target_id: TargetId,
|
pub(crate) target_id: TargetId,
|
||||||
pub(crate) request: Request,
|
pub(crate) request: Request,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct RequestWithToken {
|
pub struct RequestWithToken {
|
||||||
pub(crate) targeted_request: TargetedRequest,
|
pub(crate) targeted_request: TargetedRequest,
|
||||||
pub(crate) token: VerificationToken<TcStateAccepted>,
|
pub(crate) token: VerificationToken<TcStateAccepted>,
|
||||||
@ -138,13 +138,13 @@ impl PusRequestRouter<HkRequest> for GenericRequestRouter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PusRequestRouter<ActionRequest> for GenericRequestRouter {
|
impl PusRequestRouter<ActionRequestWithId> for GenericRequestRouter {
|
||||||
type Error = GenericRoutingError;
|
type Error = GenericRoutingError;
|
||||||
|
|
||||||
fn route(
|
fn route(
|
||||||
&self,
|
&self,
|
||||||
target_id: TargetId,
|
target_id: TargetId,
|
||||||
action_request: ActionRequest,
|
action_request: ActionRequestWithId,
|
||||||
token: VerificationToken<TcStateAccepted>,
|
token: VerificationToken<TcStateAccepted>,
|
||||||
) -> Result<(), Self::Error> {
|
) -> Result<(), Self::Error> {
|
||||||
if let Some(sender) = self.0.get(&target_id) {
|
if let Some(sender) = self.0.get(&target_id) {
|
||||||
|
@ -5,11 +5,10 @@ use crate::{
|
|||||||
ChannelId, TargetId,
|
ChannelId, TargetId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{verification::VerificationToken, ActivePusRequest, ActiveRequestProvider};
|
use super::{verification::VerificationToken, ActivePusRequestStd, ActiveRequestProvider};
|
||||||
|
|
||||||
use delegate::delegate;
|
use delegate::delegate;
|
||||||
use satrs_shared::res_code::ResultU16;
|
use satrs_shared::res_code::ResultU16;
|
||||||
use spacepackets::ecss::EcssEnumU16;
|
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||||
@ -74,38 +73,6 @@ impl GenericActionReplyPus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub struct ActivePusActionRequest {
|
|
||||||
pub action_id: ActionId,
|
|
||||||
common: ActivePusRequest,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveRequestProvider for ActivePusActionRequest {
|
|
||||||
delegate! {
|
|
||||||
to self.common {
|
|
||||||
fn target_id(&self) -> TargetId;
|
|
||||||
fn token(&self) -> VerificationToken<super::verification::TcStateStarted>;
|
|
||||||
fn start_time(&self) -> spacepackets::time::UnixTimestamp;
|
|
||||||
fn timeout(&self) -> core::time::Duration;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActivePusActionRequest {
|
|
||||||
pub fn new(
|
|
||||||
action_id: ActionId,
|
|
||||||
target_id: TargetId,
|
|
||||||
token: VerificationToken<super::verification::TcStateStarted>,
|
|
||||||
start_time: spacepackets::time::UnixTimestamp,
|
|
||||||
timeout: core::time::Duration,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
action_id,
|
|
||||||
common: ActivePusRequest::new(target_id, token, start_time, timeout),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||||
pub mod alloc_mod {}
|
pub mod alloc_mod {}
|
||||||
@ -113,192 +80,46 @@ pub mod alloc_mod {}
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||||
pub mod std_mod {
|
pub mod std_mod {
|
||||||
use crate::{
|
use crate::pus::{verification, DefaultActiveRequestMap};
|
||||||
params::WritableToBeBytes,
|
|
||||||
pus::{
|
|
||||||
verification::{
|
|
||||||
self, FailParams, FailParamsWithStep, TcStateStarted, VerificationReportingProvider,
|
|
||||||
},
|
|
||||||
ActiveRequestMapProvider, DefaultActiveRequestMap, EcssTmSenderCore, EcssTmtcError,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use core::time::Duration;
|
|
||||||
use spacepackets::time::UnixTimestamp;
|
|
||||||
use std::time::SystemTimeError;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub type DefaultActiveActionRequestMap = DefaultActiveRequestMap<ActivePusActionRequest>;
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct ActivePusActionRequestStd {
|
||||||
|
pub action_id: ActionId,
|
||||||
|
common: ActivePusRequestStd,
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
impl ActiveRequestProvider for ActivePusActionRequestStd {
|
||||||
/// Type definition for a PUS 8 action service reply handler which constrains the
|
delegate! {
|
||||||
/// [PusServiceReplyHandler] active request and reply generics to the [ActiveActionRequest] and
|
to self.common {
|
||||||
/// [ActionReplyPusWithIds] type.
|
fn target_id(&self) -> TargetId;
|
||||||
pub type PusService8ReplyHandler<VerificationReporter, ActiveRequestMap, UserHook, TmSender> =
|
fn token(&self) -> VerificationToken<verification::TcStateStarted>;
|
||||||
PusServiceReplyHandler<
|
fn has_timed_out(&self) -> bool;
|
||||||
VerificationReporter,
|
fn timeout(&self) -> core::time::Duration;
|
||||||
ActiveRequestMap,
|
}
|
||||||
UserHook,
|
}
|
||||||
TmSender,
|
}
|
||||||
ActiveActionRequest,
|
|
||||||
ActionReplyPusWithActionId,
|
|
||||||
>;
|
|
||||||
|
|
||||||
impl<
|
impl ActivePusActionRequestStd {
|
||||||
VerificationReporter: VerificationReportingProvider,
|
pub fn new(
|
||||||
ActiveRequestMap: ActiveRequestMapProvider<ActiveActionRequest>,
|
|
||||||
UserHook: ReplyHandlerHook<ActiveActionRequest, ActionReplyPusWithActionId>,
|
|
||||||
TmSender: EcssTmSenderCore,
|
|
||||||
> PusService8ReplyHandler<VerificationReporter, ActiveRequestMap, UserHook, TmSender>
|
|
||||||
{
|
|
||||||
/// Helper method to register a recently routed action request.
|
|
||||||
pub fn add_routed_action_request(
|
|
||||||
&mut self,
|
|
||||||
request_id: verification::RequestId,
|
|
||||||
target_id: TargetId,
|
|
||||||
action_id: ActionId,
|
action_id: ActionId,
|
||||||
token: VerificationToken<TcStateStarted>,
|
target_id: TargetId,
|
||||||
timeout: Duration,
|
token: VerificationToken<verification::TcStateStarted>,
|
||||||
) {
|
timeout: core::time::Duration,
|
||||||
self.active_request_map.insert(
|
|
||||||
&request_id.into(),
|
|
||||||
ActiveActionRequest {
|
|
||||||
action_id,
|
|
||||||
common: ActiveRequest {
|
|
||||||
target_id,
|
|
||||||
token,
|
|
||||||
start_time: self.current_time,
|
|
||||||
timeout,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Main handler function to handle all received action replies.
|
|
||||||
pub fn handle_action_reply(
|
|
||||||
&mut self,
|
|
||||||
action_reply_with_ids: GenericMessage<ActionReplyPusWithActionId>,
|
|
||||||
time_stamp: &[u8],
|
|
||||||
) -> Result<(), EcssTmtcError> {
|
|
||||||
let active_req = self
|
|
||||||
.active_request_map
|
|
||||||
.get(action_reply_with_ids.request_id);
|
|
||||||
if active_req.is_none() {
|
|
||||||
self.user_hook
|
|
||||||
.handle_unexpected_reply(&action_reply_with_ids);
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
let active_req = active_req.unwrap().clone();
|
|
||||||
let remove_entry = match action_reply_with_ids.message.variant {
|
|
||||||
ActionReplyPus::CompletionFailed { error_code, params } => {
|
|
||||||
let fail_data_len = params.write_to_be_bytes(&mut self.tm_buf)?;
|
|
||||||
self.verification_reporter
|
|
||||||
.completion_failure(
|
|
||||||
active_req.common.token,
|
|
||||||
FailParams::new(time_stamp, &error_code, &self.tm_buf[..fail_data_len]),
|
|
||||||
)
|
|
||||||
.map_err(|e| e.0)?;
|
|
||||||
true
|
|
||||||
}
|
|
||||||
ActionReplyPus::StepFailed {
|
|
||||||
error_code,
|
|
||||||
step,
|
|
||||||
params,
|
|
||||||
} => {
|
|
||||||
let fail_data_len = params.write_to_be_bytes(&mut self.tm_buf)?;
|
|
||||||
self.verification_reporter
|
|
||||||
.step_failure(
|
|
||||||
active_req.common.token,
|
|
||||||
FailParamsWithStep::new(
|
|
||||||
time_stamp,
|
|
||||||
&EcssEnumU16::new(step),
|
|
||||||
&error_code,
|
|
||||||
&self.tm_buf[..fail_data_len],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.map_err(|e| e.0)?;
|
|
||||||
true
|
|
||||||
}
|
|
||||||
ActionReplyPus::Completed => {
|
|
||||||
self.verification_reporter
|
|
||||||
.completion_success(active_req.common.token, time_stamp)
|
|
||||||
.map_err(|e| e.0)?;
|
|
||||||
true
|
|
||||||
}
|
|
||||||
ActionReplyPus::StepSuccess { step } => {
|
|
||||||
self.verification_reporter.step_success(
|
|
||||||
&active_req.common.token,
|
|
||||||
time_stamp,
|
|
||||||
EcssEnumU16::new(step),
|
|
||||||
)?;
|
|
||||||
false
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if remove_entry {
|
|
||||||
self.active_request_map
|
|
||||||
.remove(action_reply_with_ids.request_id);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<
|
|
||||||
VerificationReporter: VerificationReportingProvider,
|
|
||||||
UserHook: ReplyHandlerHook<ActiveActionRequest, ActionReplyPusWithActionId>,
|
|
||||||
TmSender: EcssTmSenderCore,
|
|
||||||
>
|
|
||||||
PusService8ReplyHandler<
|
|
||||||
VerificationReporter,
|
|
||||||
DefaultActiveActionRequestMap,
|
|
||||||
UserHook,
|
|
||||||
TmSender,
|
|
||||||
>
|
|
||||||
{
|
|
||||||
/// Create a new PUS Service 8 reply handler with the [ActiveRequestMap] generic
|
|
||||||
/// constrained to the [DefaultActiveActionRequestMap] object and with the current time
|
|
||||||
/// set to the OS time.
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
|
||||||
pub fn new_from_now_with_default_map(
|
|
||||||
verification_reporter: VerificationReporter,
|
|
||||||
fail_data_buf_size: usize,
|
|
||||||
user_hook: UserHook,
|
|
||||||
tm_sender: TmSender,
|
|
||||||
) -> Result<Self, SystemTimeError> {
|
|
||||||
let current_time = UnixTimestamp::from_now()?;
|
|
||||||
Ok(Self::new_with_default_map(
|
|
||||||
verification_reporter,
|
|
||||||
fail_data_buf_size,
|
|
||||||
user_hook,
|
|
||||||
tm_sender,
|
|
||||||
current_time,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new PUS Service 8 reply handler with the [ActiveRequestMap] generic
|
|
||||||
/// constrained to the [DefaultActiveActionRequestMap] object.
|
|
||||||
pub fn new_with_default_map(
|
|
||||||
verification_reporter: VerificationReporter,
|
|
||||||
fail_data_buf_size: usize,
|
|
||||||
user_hook: UserHook,
|
|
||||||
tm_sender: TmSender,
|
|
||||||
init_time: UnixTimestamp,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new(
|
Self {
|
||||||
verification_reporter,
|
action_id,
|
||||||
DefaultActiveActionRequestMap::default(),
|
common: ActivePusRequestStd::new(target_id, token, timeout),
|
||||||
fail_data_buf_size,
|
}
|
||||||
user_hook,
|
|
||||||
tm_sender,
|
|
||||||
init_time,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
pub type DefaultActiveActionRequestMap = DefaultActiveRequestMap<ActivePusActionRequestStd>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
/*
|
||||||
use core::{cell::RefCell, time::Duration};
|
use core::{cell::RefCell, time::Duration};
|
||||||
use std::{sync::mpsc, time::SystemTimeError};
|
use std::{sync::mpsc, time::SystemTimeError};
|
||||||
|
|
||||||
@ -337,7 +158,6 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/*
|
|
||||||
impl<Request> PusRequestRouter<Request> for TestRouter<Request> {
|
impl<Request> PusRequestRouter<Request> for TestRouter<Request> {
|
||||||
type Error = GenericRoutingError;
|
type Error = GenericRoutingError;
|
||||||
|
|
||||||
|
@ -8,14 +8,11 @@ use crate::queue::{GenericReceiveError, GenericSendError};
|
|||||||
use crate::request::{GenericMessage, RequestId};
|
use crate::request::{GenericMessage, RequestId};
|
||||||
use crate::{ChannelId, TargetId};
|
use crate::{ChannelId, TargetId};
|
||||||
use core::fmt::{Display, Formatter};
|
use core::fmt::{Display, Formatter};
|
||||||
use core::marker::PhantomData;
|
|
||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use downcast_rs::{impl_downcast, Downcast};
|
use downcast_rs::{impl_downcast, Downcast};
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use dyn_clone::DynClone;
|
use dyn_clone::DynClone;
|
||||||
use satrs_shared::res_code::ResultU16;
|
|
||||||
use spacepackets::time::UnixTimestamp;
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
@ -277,7 +274,7 @@ pub trait ReceivesEcssPusTc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait ActiveRequestMapProvider<V>: Sized {
|
pub trait ActiveRequestMapProvider<V>: Sized {
|
||||||
fn insert(&mut self, request_id: &RequestId, request: V);
|
fn insert(&mut self, request_id: &RequestId, request_info: V);
|
||||||
fn get(&self, request_id: RequestId) -> Option<&V>;
|
fn get(&self, request_id: RequestId) -> Option<&V>;
|
||||||
fn get_mut(&mut self, request_id: RequestId) -> Option<&mut V>;
|
fn get_mut(&mut self, request_id: RequestId) -> Option<&mut V>;
|
||||||
fn remove(&mut self, request_id: RequestId) -> bool;
|
fn remove(&mut self, request_id: RequestId) -> bool;
|
||||||
@ -292,52 +289,10 @@ pub trait ActiveRequestMapProvider<V>: Sized {
|
|||||||
pub trait ActiveRequestProvider {
|
pub trait ActiveRequestProvider {
|
||||||
fn target_id(&self) -> TargetId;
|
fn target_id(&self) -> TargetId;
|
||||||
fn token(&self) -> VerificationToken<TcStateStarted>;
|
fn token(&self) -> VerificationToken<TcStateStarted>;
|
||||||
fn start_time(&self) -> UnixTimestamp;
|
fn has_timed_out(&self) -> bool;
|
||||||
fn timeout(&self) -> Duration;
|
fn timeout(&self) -> Duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub struct ActivePusRequest {
|
|
||||||
target_id: TargetId,
|
|
||||||
token: VerificationToken<TcStateStarted>,
|
|
||||||
start_time: UnixTimestamp,
|
|
||||||
timeout: Duration,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActivePusRequest {
|
|
||||||
pub fn new(
|
|
||||||
target_id: TargetId,
|
|
||||||
token: VerificationToken<TcStateStarted>,
|
|
||||||
start_time: UnixTimestamp,
|
|
||||||
timeout: Duration,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
target_id,
|
|
||||||
token,
|
|
||||||
start_time,
|
|
||||||
timeout,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveRequestProvider for ActivePusRequest {
|
|
||||||
fn target_id(&self) -> TargetId {
|
|
||||||
self.target_id
|
|
||||||
}
|
|
||||||
|
|
||||||
fn token(&self) -> VerificationToken<TcStateStarted> {
|
|
||||||
self.token
|
|
||||||
}
|
|
||||||
|
|
||||||
fn start_time(&self) -> UnixTimestamp {
|
|
||||||
self.start_time
|
|
||||||
}
|
|
||||||
|
|
||||||
fn timeout(&self) -> Duration {
|
|
||||||
self.timeout
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This trait is an abstraction for the routing of PUS request to a dedicated
|
/// This trait is an abstraction for the routing of PUS request to a dedicated
|
||||||
/// recipient using the generic [TargetId].
|
/// recipient using the generic [TargetId].
|
||||||
pub trait PusRequestRouter<Request> {
|
pub trait PusRequestRouter<Request> {
|
||||||
@ -384,8 +339,6 @@ pub trait PusReplyHandler<ActiveRequestInfo: ActiveRequestProvider, ReplyType> {
|
|||||||
pub mod alloc_mod {
|
pub mod alloc_mod {
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
|
||||||
use crate::TargetId;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::pus::verification::VerificationReportingProvider;
|
use crate::pus::verification::VerificationReportingProvider;
|
||||||
@ -697,6 +650,7 @@ pub mod std_mod {
|
|||||||
use crate::tmtc::tm_helper::SharedTmPool;
|
use crate::tmtc::tm_helper::SharedTmPool;
|
||||||
use crate::{ChannelId, TargetId};
|
use crate::{ChannelId, TargetId};
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
use core::time::Duration;
|
||||||
use spacepackets::ecss::tc::PusTcReader;
|
use spacepackets::ecss::tc::PusTcReader;
|
||||||
use spacepackets::ecss::tm::PusTmCreator;
|
use spacepackets::ecss::tm::PusTmCreator;
|
||||||
use spacepackets::ecss::{PusError, WritablePusPacket};
|
use spacepackets::ecss::{PusError, WritablePusPacket};
|
||||||
@ -709,8 +663,8 @@ pub mod std_mod {
|
|||||||
#[cfg(feature = "crossbeam")]
|
#[cfg(feature = "crossbeam")]
|
||||||
pub use cb_mod::*;
|
pub use cb_mod::*;
|
||||||
|
|
||||||
use super::verification::VerificationReportingProvider;
|
use super::verification::{TcStateStarted, VerificationReportingProvider};
|
||||||
use super::{AcceptedEcssTcAndToken, TcInMemory};
|
use super::{AcceptedEcssTcAndToken, ActiveRequestProvider, TcInMemory};
|
||||||
|
|
||||||
impl From<mpsc::SendError<StoreAddr>> for EcssTmtcError {
|
impl From<mpsc::SendError<StoreAddr>> for EcssTmtcError {
|
||||||
fn from(_: mpsc::SendError<StoreAddr>) -> Self {
|
fn from(_: mpsc::SendError<StoreAddr>) -> Self {
|
||||||
@ -1094,6 +1048,47 @@ pub mod std_mod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct ActivePusRequestStd {
|
||||||
|
target_id: TargetId,
|
||||||
|
token: VerificationToken<TcStateStarted>,
|
||||||
|
start_time: std::time::Instant,
|
||||||
|
timeout: Duration,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActivePusRequestStd {
|
||||||
|
pub fn new(
|
||||||
|
target_id: TargetId,
|
||||||
|
token: VerificationToken<TcStateStarted>,
|
||||||
|
timeout: Duration,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
target_id,
|
||||||
|
token,
|
||||||
|
start_time: std::time::Instant::now(),
|
||||||
|
timeout,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveRequestProvider for ActivePusRequestStd {
|
||||||
|
fn target_id(&self) -> TargetId {
|
||||||
|
self.target_id
|
||||||
|
}
|
||||||
|
fn token(&self) -> VerificationToken<TcStateStarted> {
|
||||||
|
self.token
|
||||||
|
}
|
||||||
|
|
||||||
|
fn timeout(&self) -> Duration {
|
||||||
|
self.timeout
|
||||||
|
}
|
||||||
|
|
||||||
|
fn has_timed_out(&self) -> bool {
|
||||||
|
std::time::Instant::now() - self.start_time > self.timeout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: All these types could probably be no_std if we implemented error handling ourselves..
|
// TODO: All these types could probably be no_std if we implemented error handling ourselves..
|
||||||
// but thiserror is really nice, so keep it like this for simplicity for now. Maybe thiserror
|
// but thiserror is really nice, so keep it like this for simplicity for now. Maybe thiserror
|
||||||
// will be no_std soon, see https://github.com/rust-lang/rust/issues/103765 .
|
// will be no_std soon, see https://github.com/rust-lang/rust/issues/103765 .
|
||||||
|
@ -2,13 +2,12 @@ use num_enum::{IntoPrimitive, TryFromPrimitive};
|
|||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::mode::ModeReply;
|
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
pub use alloc_mod::*;
|
pub use alloc_mod::*;
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
#[allow(unused_imports)]
|
||||||
pub use std_mod::*;
|
pub use std_mod::*;
|
||||||
|
|
||||||
pub const MODE_SERVICE_ID: u8 = 200;
|
pub const MODE_SERVICE_ID: u8 = 200;
|
||||||
@ -33,25 +32,20 @@ pub mod alloc_mod {}
|
|||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||||
pub mod std_mod {
|
pub mod std_mod {
|
||||||
use core::time::Duration;
|
/*
|
||||||
|
|
||||||
use satrs_shared::res_code::ResultU16;
|
|
||||||
use spacepackets::{
|
use spacepackets::{
|
||||||
ecss::tm::{PusTmCreator, PusTmSecondaryHeader},
|
ecss::tm::{PusTmCreator, PusTmSecondaryHeader},
|
||||||
util::UnsignedEnum,
|
util::UnsignedEnum,
|
||||||
SpHeader,
|
SpHeader,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
pub trait ModeReplyHook: ReplyHandlerHook<ActivePusRequest, ModeReply> {
|
pub trait ModeReplyHook: ReplyHandlerHook<ActivePusRequest, ModeReply> {
|
||||||
fn wrong_mode_result_code(&self) -> ResultU16;
|
fn wrong_mode_result_code(&self) -> ResultU16;
|
||||||
fn can_not_reach_mode_result_code(&self) -> ResultU16;
|
fn can_not_reach_mode_result_code(&self) -> ResultU16;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
use super::{ModeReply, MODE_SERVICE_ID};
|
use super::{ModeReply, MODE_SERVICE_ID};
|
||||||
|
|
||||||
/*
|
|
||||||
/// Type definition for a PUS mode servicd reply handler which constrains the
|
/// Type definition for a PUS mode servicd reply handler which constrains the
|
||||||
/// [PusServiceReplyHandler] active request and reply generics to the [ActiveActionRequest] and
|
/// [PusServiceReplyHandler] active request and reply generics to the [ActiveActionRequest] and
|
||||||
/// [ActionReplyPusWithIds] type.
|
/// [ActionReplyPusWithIds] type.
|
||||||
|
@ -1,148 +0,0 @@
|
|||||||
use std::sync::mpsc;
|
|
||||||
|
|
||||||
use satrs::{
|
|
||||||
pus::{
|
|
||||||
verification::{
|
|
||||||
TcStateAccepted, VerificationReporterCfg, VerificationReporterWithVecMpscSender,
|
|
||||||
VerificationReportingProvider, VerificationToken,
|
|
||||||
},
|
|
||||||
ActivePusRequest, DefaultActiveRequestMap, EcssTcInVecConverter, PusRequestRouter,
|
|
||||||
PusServiceReplyHandler, PusTargetedRequestHandler, PusTcToRequestConverter,
|
|
||||||
ReplyHandlerHook, TmAsVecSenderWithId,
|
|
||||||
},
|
|
||||||
TargetId,
|
|
||||||
};
|
|
||||||
use spacepackets::{
|
|
||||||
ecss::{tc::PusTcReader, PusPacket},
|
|
||||||
CcsdsPacket,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
|
||||||
pub enum DummyRequest {
|
|
||||||
Ping,
|
|
||||||
WithParam(u32),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
|
||||||
pub enum DummyReply {
|
|
||||||
Pong,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DummyRequestConverter {}
|
|
||||||
|
|
||||||
impl PusTcToRequestConverter<DummyRequest> for DummyRequestRouter {
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
fn convert(
|
|
||||||
&mut self,
|
|
||||||
token: VerificationToken<TcStateAccepted>,
|
|
||||||
tc: &PusTcReader,
|
|
||||||
time_stamp: &[u8],
|
|
||||||
verif_reporter: &impl VerificationReportingProvider,
|
|
||||||
) -> Result<(TargetId, DummyRequest), Self::Error> {
|
|
||||||
if tc.service() == 205 && tc.subservice() == 1 {
|
|
||||||
return Ok((tc.apid().into(), DummyRequest::Ping));
|
|
||||||
}
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DummyRequestRouter {
|
|
||||||
dummy_1_sender: mpsc::Sender<DummyRequest>,
|
|
||||||
dummy_2_sender: mpsc::Sender<DummyRequest>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PusRequestRouter<DummyRequest> for DummyRequestRouter {
|
|
||||||
type Error = ();
|
|
||||||
fn route(
|
|
||||||
&self,
|
|
||||||
target_id: TargetId,
|
|
||||||
request: DummyRequest,
|
|
||||||
token: VerificationToken<TcStateAccepted>,
|
|
||||||
) -> Result<(), Self::Error> {
|
|
||||||
if target_id == DummyTargetId::Object1 as u64 {
|
|
||||||
self.dummy_1_sender.send(request).ok();
|
|
||||||
} else {
|
|
||||||
self.dummy_2_sender.send(request).ok();
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_error(
|
|
||||||
&self,
|
|
||||||
target_id: TargetId,
|
|
||||||
token: VerificationToken<TcStateAccepted>,
|
|
||||||
tc: &PusTcReader,
|
|
||||||
error: Self::Error,
|
|
||||||
time_stamp: &[u8],
|
|
||||||
verif_reporter: &impl VerificationReportingProvider,
|
|
||||||
) {
|
|
||||||
panic!("routing error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct DummyReplyUserHook {}
|
|
||||||
|
|
||||||
impl ReplyHandlerHook<ActivePusRequest, DummyReply> for DummyReplyUserHook {
|
|
||||||
fn handle_unexpected_reply(&mut self, reply: &satrs::request::GenericMessage<DummyReply>) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn timeout_callback(&self, active_request: &ActivePusRequest) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn timeout_error_code(&self) -> satrs_shared::res_code::ResultU16 {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type PusDummyRequestHandler = PusTargetedRequestHandler<
|
|
||||||
mpsc::Sender<Vec<u8>>,
|
|
||||||
mpsc::Sender<Vec<u8>>,
|
|
||||||
EcssTcInVecConverter,
|
|
||||||
VerificationReporterWithVecMpscSender,
|
|
||||||
DummyRequestConverter,
|
|
||||||
DummyRequestRouter,
|
|
||||||
DummyRequest,
|
|
||||||
>;
|
|
||||||
pub type PusDummyReplyHandler = PusServiceReplyHandler<
|
|
||||||
VerificationReporterWithVecMpscSender,
|
|
||||||
DefaultActiveRequestMap<ActivePusRequest>,
|
|
||||||
DummyReplyUserHook,
|
|
||||||
mpsc::Sender<Vec<u8>>,
|
|
||||||
ActivePusRequest,
|
|
||||||
DummyReply,
|
|
||||||
>;
|
|
||||||
const TEST_APID: u16 = 5;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
|
||||||
pub enum DummyTargetId {
|
|
||||||
Object1 = 1,
|
|
||||||
Object2 = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum DummyChannelId {
|
|
||||||
Router = 1,
|
|
||||||
Object1 = 2,
|
|
||||||
Object2 = 3,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let reporter_cfg = VerificationReporterCfg::new(TEST_APID, 2, 2, 256).unwrap();
|
|
||||||
let (tm_sender, tm_receiver) = mpsc::channel();
|
|
||||||
let tm_sender_with_wrapper =
|
|
||||||
TmAsVecSenderWithId::new(DummyChannelId::Router as u32, "ROUTER", tm_sender.clone());
|
|
||||||
let verification_handler =
|
|
||||||
VerificationReporterWithVecMpscSender::new(&reporter_cfg, tm_sender_with_wrapper);
|
|
||||||
|
|
||||||
// let dummy_request_handler = PusDummyRequestHandler::new()
|
|
||||||
let dummy_reply_handler = PusDummyReplyHandler::new_from_now(
|
|
||||||
verification_handler,
|
|
||||||
DefaultActiveRequestMap::default(),
|
|
||||||
256,
|
|
||||||
DummyReplyUserHook::default(),
|
|
||||||
tm_sender.clone(),
|
|
||||||
);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user