This commit is contained in:
parent
5702e83df5
commit
0db24d22df
@ -53,7 +53,7 @@ impl PusActionToRequestConverter for ExampleActionRequestConverter {
|
||||
if subservice == 128 {
|
||||
Ok((
|
||||
target_id.raw(),
|
||||
ActionRequest::ActionIdAndVecData {
|
||||
ActionRequest::UnsignedIdAndVecData {
|
||||
action_id,
|
||||
data: user_data[8..].to_vec(),
|
||||
},
|
||||
|
@ -2,20 +2,24 @@ use crate::{pool::StoreAddr, TargetId};
|
||||
|
||||
pub type ActionId = u32;
|
||||
|
||||
#[non_exhaustive]
|
||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||
pub enum ActionRequest {
|
||||
ActionIdAndStoreData {
|
||||
UnsignedIdAndStoreData {
|
||||
action_id: ActionId,
|
||||
data_addr: StoreAddr,
|
||||
},
|
||||
ActionIdAndVecData {
|
||||
#[cfg(feature = "alloc")]
|
||||
UnsignedIdAndVecData {
|
||||
action_id: ActionId,
|
||||
data: alloc::vec::Vec<u8>,
|
||||
},
|
||||
#[cfg(feature = "alloc")]
|
||||
StringIdAndVecData {
|
||||
action_id: alloc::string::String,
|
||||
data: alloc::vec::Vec<u8>,
|
||||
},
|
||||
#[cfg(feature = "alloc")]
|
||||
StringIdAndStoreData {
|
||||
action_id: alloc::string::String,
|
||||
data: StoreAddr,
|
||||
|
@ -22,8 +22,6 @@ extern crate downcast_rs;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
extern crate std;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub mod action;
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
pub mod cfdp;
|
||||
@ -36,10 +34,7 @@ pub mod events;
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub mod executable;
|
||||
pub mod hal;
|
||||
pub mod hk;
|
||||
pub mod mode;
|
||||
pub mod objects;
|
||||
pub mod params;
|
||||
pub mod pool;
|
||||
pub mod power;
|
||||
pub mod pus;
|
||||
@ -49,6 +44,11 @@ pub mod res_code;
|
||||
pub mod seq_count;
|
||||
pub mod tmtc;
|
||||
|
||||
pub mod action;
|
||||
pub mod hk;
|
||||
pub mod mode;
|
||||
pub mod params;
|
||||
|
||||
pub use spacepackets;
|
||||
|
||||
/// Generic channel ID type.
|
||||
|
@ -1,38 +1,14 @@
|
||||
use spacepackets::ecss::tc::PusTcReader;
|
||||
|
||||
use crate::{action::ActionRequest, TargetId};
|
||||
|
||||
use super::verification::{TcStateAccepted, VerificationReporterWithSender, VerificationToken};
|
||||
use super::verification::{TcStateAccepted, VerificationToken};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub use std_mod::*;
|
||||
|
||||
/// This trait is an abstraction for the conversion of a PUS service 8 action telecommand into
|
||||
/// an [ActionRequest].
|
||||
///
|
||||
/// Having a dedicated trait for this allows maximum flexiblity and tailoring of the standard.
|
||||
/// The only requirement is that a valid [TargetId] and an [ActionRequest] are returned by the
|
||||
/// core conversion function.
|
||||
///
|
||||
/// The user should take care of performing the error handling as well. Some of the following
|
||||
/// aspects might be relevant:
|
||||
///
|
||||
/// - Checking the validity of the APID, service ID, subservice ID.
|
||||
/// - Checking the validity of the user data.
|
||||
///
|
||||
/// A [VerificationReporterWithSender] instance is passed to the user to also allow handling
|
||||
/// of the verification process as part of the PUS standard requirements.
|
||||
pub trait PusActionToRequestConverter {
|
||||
type Error;
|
||||
fn convert(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
tc: &PusTcReader,
|
||||
time_stamp: &[u8],
|
||||
verif_reporter: &mut VerificationReporterWithSender,
|
||||
) -> Result<(TargetId, ActionRequest), Self::Error>;
|
||||
}
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
pub use alloc_mod::*;
|
||||
|
||||
/// This trait is an abstraction for the routing of PUS service 8 action requests to a dedicated
|
||||
/// recipient using the generic [TargetId].
|
||||
@ -46,6 +22,42 @@ pub trait PusActionRequestRouter {
|
||||
) -> Result<(), Self::Error>;
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
pub mod alloc_mod {
|
||||
use spacepackets::ecss::tc::PusTcReader;
|
||||
|
||||
use crate::pus::verification::VerificationReporterWithSender;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// This trait is an abstraction for the conversion of a PUS service 8 action telecommand into
|
||||
/// an [ActionRequest].
|
||||
///
|
||||
/// Having a dedicated trait for this allows maximum flexiblity and tailoring of the standard.
|
||||
/// The only requirement is that a valid [TargetId] and an [ActionRequest] are returned by the
|
||||
/// core conversion function.
|
||||
///
|
||||
/// The user should take care of performing the error handling as well. Some of the following
|
||||
/// aspects might be relevant:
|
||||
///
|
||||
/// - Checking the validity of the APID, service ID, subservice ID.
|
||||
/// - Checking the validity of the user data.
|
||||
///
|
||||
/// A [VerificationReporterWithSender] instance is passed to the user to also allow handling
|
||||
/// of the verification process as part of the PUS standard requirements.
|
||||
pub trait PusActionToRequestConverter {
|
||||
type Error;
|
||||
fn convert(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
tc: &PusTcReader,
|
||||
time_stamp: &[u8],
|
||||
verif_reporter: &mut VerificationReporterWithSender,
|
||||
) -> Result<(TargetId, ActionRequest), Self::Error>;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub mod std_mod {
|
||||
|
@ -1,28 +1,16 @@
|
||||
pub use spacepackets::ecss::hk::*;
|
||||
use spacepackets::ecss::tc::PusTcReader;
|
||||
|
||||
use crate::{hk::HkRequest, TargetId};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub use std_mod::*;
|
||||
|
||||
use super::{
|
||||
verification::{TcStateAccepted, VerificationReporterWithSender, VerificationToken},
|
||||
EcssTcInMemConverter, GenericRoutingError, PusPacketHandlerResult, PusPacketHandlingError,
|
||||
PusRoutingErrorHandler, PusServiceBase, PusServiceHelper,
|
||||
};
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
pub use alloc_mod::*;
|
||||
|
||||
pub trait PusHkToRequestConverter {
|
||||
type Error;
|
||||
fn convert(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
tc: &PusTcReader,
|
||||
time_stamp: &[u8],
|
||||
verif_reporter: &mut VerificationReporterWithSender,
|
||||
) -> Result<(TargetId, HkRequest), Self::Error>;
|
||||
}
|
||||
use crate::{hk::HkRequest, TargetId};
|
||||
|
||||
use super::verification::{TcStateAccepted, VerificationToken};
|
||||
|
||||
pub trait PusHkRequestRouter {
|
||||
type Error;
|
||||
@ -34,9 +22,35 @@ pub trait PusHkRequestRouter {
|
||||
) -> Result<(), Self::Error>;
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
pub mod alloc_mod {
|
||||
use spacepackets::ecss::tc::PusTcReader;
|
||||
|
||||
use crate::pus::verification::VerificationReporterWithSender;
|
||||
|
||||
use super::*;
|
||||
|
||||
pub trait PusHkToRequestConverter {
|
||||
type Error;
|
||||
fn convert(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
tc: &PusTcReader,
|
||||
time_stamp: &[u8],
|
||||
verif_reporter: &mut VerificationReporterWithSender,
|
||||
) -> Result<(TargetId, HkRequest), Self::Error>;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||
pub mod std_mod {
|
||||
use crate::pus::{
|
||||
EcssTcInMemConverter, GenericRoutingError, PusPacketHandlerResult, PusPacketHandlingError,
|
||||
PusRoutingErrorHandler, PusServiceBase, PusServiceHelper,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
pub struct PusService3HkHandler<
|
||||
|
@ -3,7 +3,7 @@
|
||||
//! This module contains structures to make working with the PUS C standard easier.
|
||||
//! The satrs-example application contains various usage examples of these components.
|
||||
use crate::queue::{GenericRecvError, GenericSendError};
|
||||
use crate::{ChannelId, TargetId};
|
||||
use crate::ChannelId;
|
||||
use core::fmt::{Display, Formatter};
|
||||
#[cfg(feature = "alloc")]
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
@ -39,8 +39,6 @@ use crate::pus::verification::{TcStateAccepted, TcStateToken, VerificationToken}
|
||||
#[cfg(feature = "std")]
|
||||
pub use std_mod::*;
|
||||
|
||||
use self::verification::VerificationReporterWithSender;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum PusTmWrapper<'tm> {
|
||||
InStore(StoreAddr),
|
||||
@ -262,6 +260,10 @@ pub trait ReceivesEcssPusTc {
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
mod alloc_mod {
|
||||
use crate::TargetId;
|
||||
|
||||
use self::verification::VerificationReporterWithSender;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Extension trait for [EcssTmSenderCore].
|
||||
|
@ -1704,11 +1704,9 @@ mod tests {
|
||||
.helper
|
||||
.acceptance_success(tok, Some(&EMPTY_STAMP))
|
||||
.expect("Sending acceptance success failed");
|
||||
let empty = b
|
||||
.helper
|
||||
b.helper
|
||||
.start_failure(accepted_token, fail_params)
|
||||
.expect("Start failure failure");
|
||||
assert_eq!(empty, ());
|
||||
let sender: &mut TestSender = b.helper.sender.downcast_mut().unwrap();
|
||||
start_fail_check(sender, tok.req_id, fail_data_raw);
|
||||
}
|
||||
|
@ -1,24 +1,49 @@
|
||||
use core::fmt;
|
||||
#[cfg(feature = "std")]
|
||||
use std::error::Error;
|
||||
|
||||
use spacepackets::{
|
||||
ecss::{tc::IsPusTelecommand, PusPacket},
|
||||
ByteConversionError, CcsdsPacket,
|
||||
};
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::TargetId;
|
||||
|
||||
pub type Apid = u16;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum TargetIdCreationError {
|
||||
#[error("byte conversion")]
|
||||
ByteConversion(#[from] ByteConversionError),
|
||||
#[error("not enough app data to generate target ID")]
|
||||
ByteConversion(ByteConversionError),
|
||||
NotEnoughAppData(usize),
|
||||
}
|
||||
|
||||
impl From<ByteConversionError> for TargetIdCreationError {
|
||||
fn from(e: ByteConversionError) -> Self {
|
||||
Self::ByteConversion(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for TargetIdCreationError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Self::ByteConversion(e) => write!(f, "target ID creation: {}", e),
|
||||
Self::NotEnoughAppData(len) => {
|
||||
write!(f, "not enough app data to generate target ID: {}", len)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Error for TargetIdCreationError {
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
if let Self::ByteConversion(e) = self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct TargetAndApidId {
|
||||
pub apid: Apid,
|
||||
|
Loading…
x
Reference in New Issue
Block a user