use crate::{ action::{ActionId, ActionRequest}, params::Params, request::{GenericMessage, MessageMetadata, RequestId}, }; use satrs_shared::res_code::ResultU16; #[cfg(feature = "std")] #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] pub use std_mod::*; #[cfg(feature = "alloc")] #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] #[allow(unused_imports)] pub use alloc_mod::*; #[derive(Clone, Debug)] pub struct ActionRequestWithId { pub request_id: RequestId, pub request: ActionRequest, } /// A reply to an action request, but tailored to the PUS standard verification process. #[non_exhaustive] #[derive(Clone, PartialEq, Debug)] pub enum ActionReplyVariant { Completed, StepSuccess { step: u16, }, CompletionFailed { error_code: ResultU16, params: Option, }, StepFailed { error_code: ResultU16, step: u16, params: Option, }, } #[derive(Debug, PartialEq, Clone)] pub struct ActionReplyPus { pub action_id: ActionId, pub variant: ActionReplyVariant, } impl ActionReplyPus { pub fn new(action_id: ActionId, variant: ActionReplyVariant) -> Self { Self { action_id, variant } } } pub type GenericActionReplyPus = GenericMessage; impl GenericActionReplyPus { pub fn new_action_reply( requestor_info: MessageMetadata, action_id: ActionId, reply: ActionReplyVariant, ) -> Self { Self::new(requestor_info, ActionReplyPus::new(action_id, reply)) } } #[cfg(feature = "alloc")] #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] pub mod alloc_mod { use crate::{ action::ActionRequest, queue::GenericTargetedMessagingError, request::{ GenericMessage, MessageReceiver, MessageSender, MessageSenderAndReceiver, RequestId, }, ComponentId, }; use super::ActionReplyPus; /// Helper type definition for a mode handler which can handle mode requests. pub type ActionRequestHandlerInterface = MessageSenderAndReceiver; impl, R: MessageReceiver> ActionRequestHandlerInterface { pub fn try_recv_action_request( &self, ) -> Result>, GenericTargetedMessagingError> { self.try_recv_message() } pub fn send_action_reply( &self, request_id: RequestId, target_id: ComponentId, reply: ActionReplyPus, ) -> Result<(), GenericTargetedMessagingError> { self.send_message(request_id, target_id, reply) } } /// Helper type defintion for a mode handler object which can send mode requests and receive /// mode replies. pub type ActionRequestorInterface = MessageSenderAndReceiver; impl, R: MessageReceiver> ActionRequestorInterface { pub fn try_recv_action_reply( &self, ) -> Result>, GenericTargetedMessagingError> { self.try_recv_message() } pub fn send_action_request( &self, request_id: RequestId, target_id: ComponentId, request: ActionRequest, ) -> Result<(), GenericTargetedMessagingError> { self.send_message(request_id, target_id, request) } } } #[cfg(feature = "std")] #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] pub mod std_mod { use std::sync::mpsc; use crate::{ pus::{ verification::{self, TcStateToken}, ActivePusRequestStd, ActiveRequestProvider, DefaultActiveRequestMap, }, ComponentId, }; use super::*; #[derive(Debug, Clone, PartialEq, Eq)] pub struct ActivePusActionRequestStd { pub action_id: ActionId, common: ActivePusRequestStd, } impl ActiveRequestProvider for ActivePusActionRequestStd { delegate::delegate! { to self.common { fn target_id(&self) -> ComponentId; fn token(&self) -> verification::TcStateToken; fn set_token(&mut self, token: verification::TcStateToken); fn has_timed_out(&self) -> bool; fn timeout(&self) -> core::time::Duration; } } } impl ActivePusActionRequestStd { pub fn new_from_common_req(action_id: ActionId, common: ActivePusRequestStd) -> Self { Self { action_id, common } } pub fn new( action_id: ActionId, target_id: ComponentId, token: TcStateToken, timeout: core::time::Duration, ) -> Self { Self { action_id, common: ActivePusRequestStd::new(target_id, token, timeout), } } } pub type DefaultActiveActionRequestMap = DefaultActiveRequestMap; pub type ActionRequestHandlerMpsc = ActionRequestHandlerInterface< mpsc::Sender>, mpsc::Receiver>, >; pub type ActionRequestHandlerMpscBounded = ActionRequestHandlerInterface< mpsc::SyncSender>, mpsc::Receiver>, >; pub type ActionRequestorMpsc = ActionRequestorInterface< mpsc::Sender>, mpsc::Receiver>, >; pub type ActionRequestorBoundedMpsc = ActionRequestorInterface< mpsc::SyncSender>, mpsc::Receiver>, >; } #[cfg(test)] mod tests {}