fix compile error
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
41db3b86da
commit
300289608e
@ -323,6 +323,20 @@ impl ActiveRequestProvider for ActiveRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generic user hook method.
|
||||||
|
///
|
||||||
|
/// This hook method currently serves the following tasks:
|
||||||
|
///
|
||||||
|
/// 1. Pass specific information to the reply handlers which can not be kept inside the
|
||||||
|
/// framework. This includes information like the error codes used for packet verification.
|
||||||
|
/// 2. It exposes callback methods which can be useful to perform custom user operations like
|
||||||
|
/// logging.
|
||||||
|
pub trait ReplyHandlerHook<ActiveRequestType, ReplyType> {
|
||||||
|
fn handle_unexpected_reply(&mut self, reply: &ReplyType);
|
||||||
|
fn timeout_callback(&self, active_request: &ActiveRequestType);
|
||||||
|
fn timeout_error_code(&self) -> ResultU16;
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
mod alloc_mod {
|
mod alloc_mod {
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
@ -464,167 +478,153 @@ mod alloc_mod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Generic user hook method.
|
/// Generic reply handler structure which can be used to handle replies for a specific PUS service.
|
||||||
///
|
///
|
||||||
/// This hook method currently serves the following tasks:
|
/// This is done by keeping track of active requests using an internal map structure. An API
|
||||||
///
|
/// to register new active requests is exposed as well.
|
||||||
/// 1. Pass specific information to the reply handlers which can not be kept inside the
|
/// The reply handler performs boilerplate tasks like performing the verification handling and
|
||||||
/// framework. This includes information like the error codes used for packet verification.
|
/// timeout handling.
|
||||||
/// 2. It exposes callback methods which can be useful to perform custom user operations like
|
///
|
||||||
/// logging.
|
/// This object is not useful by itself but serves as a common building block for high-level
|
||||||
pub trait ReplyHandlerHook<ActiveRequestType, ReplyType> {
|
/// PUS reply handlers. Concrete PUS handlers should constrain the [ActiveRequestProvider] and
|
||||||
fn handle_unexpected_reply(&mut self, reply: &ReplyType);
|
/// the `ReplyType` generics to specific types tailored towards PUS services in addition to
|
||||||
fn timeout_callback(&self, active_request: &ActiveRequestType);
|
/// providing an API which can process received replies and convert them into verification
|
||||||
fn timeout_error_code(&self) -> ResultU16;
|
/// completions or other operation like user hook calls. The framework also provides some concrete
|
||||||
}
|
/// PUS handlers for common PUS services like the mode, action and housekeeping service.
|
||||||
|
///
|
||||||
/// Generic reply handler structure which can be used to handle replies for a specific PUS service.
|
/// This object does not automatically update its internal time information used to check for
|
||||||
///
|
/// timeouts. The user should call the [Self::update_time] and [Self::update_time_from_now] methods
|
||||||
/// This is done by keeping track of active requests using an internal map structure. An API
|
/// to do this.
|
||||||
/// to register new active requests is exposed as well.
|
pub struct PusServiceReplyHandler<
|
||||||
/// The reply handler performs boilerplate tasks like performing the verification handling and
|
|
||||||
/// timeout handling.
|
|
||||||
///
|
|
||||||
/// This object is not useful by itself but serves as a common building block for high-level
|
|
||||||
/// PUS reply handlers. Concrete PUS handlers should constrain the [ActiveRequestProvider] and
|
|
||||||
/// the `ReplyType` generics to specific types tailored towards PUS services in addition to
|
|
||||||
/// providing an API which can process received replies and convert them into verification
|
|
||||||
/// completions or other operation like user hook calls. The framework also provides some concrete
|
|
||||||
/// PUS handlers for common PUS services like the mode, action and housekeeping service.
|
|
||||||
///
|
|
||||||
/// This object does not automatically update its internal time information used to check for
|
|
||||||
/// timeouts. The user should call the [Self::update_time] and [Self::update_time_from_now] methods
|
|
||||||
/// to do this.
|
|
||||||
pub struct PusServiceReplyHandler<
|
|
||||||
VerificationReporter: VerificationReportingProvider,
|
|
||||||
ActiveRequestMap: ActiveRequestMapProvider<ActiveRequestType>,
|
|
||||||
UserHook: ReplyHandlerHook<ActiveRequestType, ReplyType>,
|
|
||||||
ActiveRequestType: ActiveRequestProvider,
|
|
||||||
ReplyType,
|
|
||||||
> {
|
|
||||||
active_request_map: ActiveRequestMap,
|
|
||||||
verification_reporter: VerificationReporter,
|
|
||||||
fail_data_buf: alloc::vec::Vec<u8>,
|
|
||||||
current_time: UnixTimestamp,
|
|
||||||
pub user_hook: UserHook,
|
|
||||||
phantom: PhantomData<(ActiveRequestType, ReplyType)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<
|
|
||||||
VerificationReporter: VerificationReportingProvider,
|
VerificationReporter: VerificationReportingProvider,
|
||||||
ActiveRequestMap: ActiveRequestMapProvider<ActiveRequestType>,
|
ActiveRequestMap: ActiveRequestMapProvider<ActiveRequestType>,
|
||||||
UserHook: ReplyHandlerHook<ActiveRequestType, ReplyType>,
|
UserHook: ReplyHandlerHook<ActiveRequestType, ReplyType>,
|
||||||
ActiveRequestType: ActiveRequestProvider,
|
ActiveRequestType: ActiveRequestProvider,
|
||||||
ReplyType,
|
ReplyType,
|
||||||
>
|
> {
|
||||||
PusServiceReplyHandler<
|
|
||||||
VerificationReporter,
|
|
||||||
ActiveRequestMap,
|
|
||||||
UserHook,
|
|
||||||
ActiveRequestType,
|
|
||||||
ReplyType,
|
|
||||||
>
|
|
||||||
{
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
|
||||||
pub fn new_from_now(
|
|
||||||
verification_reporter: VerificationReporter,
|
|
||||||
active_request_map: ActiveRequestMap,
|
active_request_map: ActiveRequestMap,
|
||||||
fail_data_buf_size: usize,
|
verification_reporter: VerificationReporter,
|
||||||
user_hook: UserHook,
|
fail_data_buf: alloc::vec::Vec<u8>,
|
||||||
) -> Result<Self, std::time::SystemTimeError> {
|
current_time: UnixTimestamp,
|
||||||
let current_time = UnixTimestamp::from_now()?;
|
pub user_hook: UserHook,
|
||||||
Ok(Self::new(
|
phantom: PhantomData<(ActiveRequestType, ReplyType)>,
|
||||||
verification_reporter,
|
|
||||||
active_request_map,
|
|
||||||
fail_data_buf_size,
|
|
||||||
user_hook,
|
|
||||||
current_time,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(
|
impl<
|
||||||
verification_reporter: VerificationReporter,
|
VerificationReporter: VerificationReportingProvider,
|
||||||
active_request_map: ActiveRequestMap,
|
ActiveRequestMap: ActiveRequestMapProvider<ActiveRequestType>,
|
||||||
fail_data_buf_size: usize,
|
UserHook: ReplyHandlerHook<ActiveRequestType, ReplyType>,
|
||||||
user_hook: UserHook,
|
ActiveRequestType: ActiveRequestProvider,
|
||||||
init_time: UnixTimestamp,
|
ReplyType,
|
||||||
) -> Self {
|
>
|
||||||
Self {
|
PusServiceReplyHandler<
|
||||||
active_request_map,
|
VerificationReporter,
|
||||||
verification_reporter,
|
ActiveRequestMap,
|
||||||
fail_data_buf: alloc::vec![0; fail_data_buf_size],
|
UserHook,
|
||||||
current_time: init_time,
|
ActiveRequestType,
|
||||||
user_hook,
|
ReplyType,
|
||||||
phantom: PhantomData,
|
>
|
||||||
|
{
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||||
|
pub fn new_from_now(
|
||||||
|
verification_reporter: VerificationReporter,
|
||||||
|
active_request_map: ActiveRequestMap,
|
||||||
|
fail_data_buf_size: usize,
|
||||||
|
user_hook: UserHook,
|
||||||
|
) -> Result<Self, std::time::SystemTimeError> {
|
||||||
|
let current_time = UnixTimestamp::from_now()?;
|
||||||
|
Ok(Self::new(
|
||||||
|
verification_reporter,
|
||||||
|
active_request_map,
|
||||||
|
fail_data_buf_size,
|
||||||
|
user_hook,
|
||||||
|
current_time,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_routed_request(
|
pub fn new(
|
||||||
&mut self,
|
verification_reporter: VerificationReporter,
|
||||||
request_id: verification::RequestId,
|
active_request_map: ActiveRequestMap,
|
||||||
active_request_type: ActiveRequestType,
|
fail_data_buf_size: usize,
|
||||||
) {
|
user_hook: UserHook,
|
||||||
self.active_request_map
|
init_time: UnixTimestamp,
|
||||||
.insert(&request_id.into(), active_request_type);
|
) -> Self {
|
||||||
}
|
Self {
|
||||||
|
active_request_map,
|
||||||
pub fn request_active(&self, request_id: RequestId) -> bool {
|
verification_reporter,
|
||||||
self.active_request_map.get(request_id).is_some()
|
fail_data_buf: alloc::vec![0; fail_data_buf_size],
|
||||||
}
|
current_time: init_time,
|
||||||
|
user_hook,
|
||||||
/// Check for timeouts across all active requests.
|
phantom: PhantomData,
|
||||||
///
|
|
||||||
/// It will call [Self::handle_timeout] for all active requests which have timed out.
|
|
||||||
pub fn check_for_timeouts(&mut self, time_stamp: &[u8]) -> Result<(), EcssTmtcError> {
|
|
||||||
let mut timed_out_commands = alloc::vec::Vec::new();
|
|
||||||
self.active_request_map.for_each(|request_id, active_req| {
|
|
||||||
let diff = self.current_time - active_req.start_time();
|
|
||||||
if diff.duration_absolute > active_req.timeout() {
|
|
||||||
self.handle_timeout(active_req, time_stamp);
|
|
||||||
}
|
}
|
||||||
timed_out_commands.push(*request_id);
|
|
||||||
});
|
|
||||||
for timed_out_command in timed_out_commands {
|
|
||||||
self.active_request_map.remove(timed_out_command);
|
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handle the timeout for a given active request.
|
pub fn add_routed_request(
|
||||||
///
|
&mut self,
|
||||||
/// This implementation will report a verification completion failure with a user-provided
|
request_id: verification::RequestId,
|
||||||
/// error code. It supplies the configured request timeout in milliseconds as a [u64]
|
active_request_type: ActiveRequestType,
|
||||||
/// serialized in big-endian format as the failure data.
|
) {
|
||||||
pub fn handle_timeout(&self, active_request: &ActiveRequestType, time_stamp: &[u8]) {
|
self.active_request_map
|
||||||
let timeout = active_request.timeout().as_millis() as u64;
|
.insert(&request_id.into(), active_request_type);
|
||||||
let timeout_raw = timeout.to_be_bytes();
|
}
|
||||||
self.verification_reporter
|
|
||||||
.completion_failure(
|
|
||||||
active_request.token(),
|
|
||||||
FailParams::new(
|
|
||||||
time_stamp,
|
|
||||||
&self.user_hook.timeout_error_code(),
|
|
||||||
&timeout_raw,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
self.user_hook.timeout_callback(active_request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Update the current time used for timeout checks based on the current OS time.
|
pub fn request_active(&self, request_id: RequestId) -> bool {
|
||||||
#[cfg(feature = "std")]
|
self.active_request_map.get(request_id).is_some()
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
}
|
||||||
pub fn update_time_from_now(&mut self) -> Result<(), std::time::SystemTimeError> {
|
|
||||||
self.current_time = UnixTimestamp::from_now()?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Update the current time used for timeout checks.
|
/// Check for timeouts across all active requests.
|
||||||
pub fn update_time(&mut self, time: UnixTimestamp) {
|
///
|
||||||
self.current_time = time;
|
/// It will call [Self::handle_timeout] for all active requests which have timed out.
|
||||||
|
pub fn check_for_timeouts(&mut self, time_stamp: &[u8]) -> Result<(), EcssTmtcError> {
|
||||||
|
let mut timed_out_commands = alloc::vec::Vec::new();
|
||||||
|
self.active_request_map.for_each(|request_id, active_req| {
|
||||||
|
let diff = self.current_time - active_req.start_time();
|
||||||
|
if diff.duration_absolute > active_req.timeout() {
|
||||||
|
self.handle_timeout(active_req, time_stamp);
|
||||||
|
}
|
||||||
|
timed_out_commands.push(*request_id);
|
||||||
|
});
|
||||||
|
for timed_out_command in timed_out_commands {
|
||||||
|
self.active_request_map.remove(timed_out_command);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Handle the timeout for a given active request.
|
||||||
|
///
|
||||||
|
/// This implementation will report a verification completion failure with a user-provided
|
||||||
|
/// error code. It supplies the configured request timeout in milliseconds as a [u64]
|
||||||
|
/// serialized in big-endian format as the failure data.
|
||||||
|
pub fn handle_timeout(&self, active_request: &ActiveRequestType, time_stamp: &[u8]) {
|
||||||
|
let timeout = active_request.timeout().as_millis() as u64;
|
||||||
|
let timeout_raw = timeout.to_be_bytes();
|
||||||
|
self.verification_reporter
|
||||||
|
.completion_failure(
|
||||||
|
active_request.token(),
|
||||||
|
FailParams::new(
|
||||||
|
time_stamp,
|
||||||
|
&self.user_hook.timeout_error_code(),
|
||||||
|
&timeout_raw,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
self.user_hook.timeout_callback(active_request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the current time used for timeout checks based on the current OS time.
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||||
|
pub fn update_time_from_now(&mut self) -> Result<(), std::time::SystemTimeError> {
|
||||||
|
self.current_time = UnixTimestamp::from_now()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the current time used for timeout checks.
|
||||||
|
pub fn update_time(&mut self, time: UnixTimestamp) {
|
||||||
|
self.current_time = time;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user