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