fix example
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
85b13918e6
commit
e7bf8e699d
@ -24,8 +24,8 @@ derive-new = "0.5"
|
|||||||
path = "../satrs"
|
path = "../satrs"
|
||||||
|
|
||||||
[dependencies.satrs-mib]
|
[dependencies.satrs-mib]
|
||||||
version = "0.1.1"
|
# version = "0.1.1"
|
||||||
# path = "../satrs-mib"
|
path = "../satrs-mib"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
dyn_tmtc = []
|
dyn_tmtc = []
|
||||||
|
@ -114,6 +114,7 @@ pub mod std_mod {
|
|||||||
},
|
},
|
||||||
request::RequestId,
|
request::RequestId,
|
||||||
};
|
};
|
||||||
|
use core::time::Duration;
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use spacepackets::time::UnixTimestamp;
|
use spacepackets::time::UnixTimestamp;
|
||||||
use std::time::SystemTimeError;
|
use std::time::SystemTimeError;
|
||||||
@ -228,34 +229,60 @@ pub mod std_mod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ActiveRequest {
|
pub struct ActiveActionRequest {
|
||||||
|
action_id: ActionId,
|
||||||
token: VerificationToken<TcStateStarted>,
|
token: VerificationToken<TcStateStarted>,
|
||||||
start_time: UnixTimestamp,
|
start_time: UnixTimestamp,
|
||||||
timeout_seconds: u32,
|
timeout: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PusService8ReplyHandler<VerificationReporter: VerificationReportingProvider> {
|
pub trait ActionReplyHandlerHook {
|
||||||
active_requests: HashMap<RequestId, ActiveRequest>,
|
fn handle_unexpected_reply(&mut self, reply: &ActionReplyPusWithIds);
|
||||||
|
fn timeout_callback(&self, active_request: &ActiveActionRequest);
|
||||||
|
fn timeout_error_code(&self) -> ResultU16;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PusService8ReplyHandler<
|
||||||
|
VerificationReporter: VerificationReportingProvider,
|
||||||
|
UserHook: ActionReplyHandlerHook,
|
||||||
|
> {
|
||||||
|
active_requests: HashMap<RequestId, ActiveActionRequest>,
|
||||||
verification_reporter: VerificationReporter,
|
verification_reporter: VerificationReporter,
|
||||||
fail_data_buf: alloc::vec::Vec<u8>,
|
fail_data_buf: alloc::vec::Vec<u8>,
|
||||||
current_time: UnixTimestamp,
|
current_time: UnixTimestamp,
|
||||||
|
user_hook: UserHook,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<VerificationReporter: VerificationReportingProvider>
|
impl<VerificationReporter: VerificationReportingProvider, UserHook: ActionReplyHandlerHook>
|
||||||
PusService8ReplyHandler<VerificationReporter>
|
PusService8ReplyHandler<VerificationReporter, UserHook>
|
||||||
{
|
{
|
||||||
|
pub fn new(
|
||||||
|
verification_reporter: VerificationReporter,
|
||||||
|
fail_data_buf_size: usize,
|
||||||
|
user_hook: UserHook,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
active_requests: HashMap::new(),
|
||||||
|
verification_reporter,
|
||||||
|
fail_data_buf: alloc::vec![0; fail_data_buf_size],
|
||||||
|
current_time: UnixTimestamp::from_now().unwrap(),
|
||||||
|
user_hook,
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn add_routed_request(
|
pub fn add_routed_request(
|
||||||
&mut self,
|
&mut self,
|
||||||
request_id: verification::RequestId,
|
request_id: verification::RequestId,
|
||||||
|
action_id: ActionId,
|
||||||
token: VerificationToken<TcStateStarted>,
|
token: VerificationToken<TcStateStarted>,
|
||||||
timeout_seconds: u32,
|
timeout: Duration,
|
||||||
) {
|
) {
|
||||||
self.active_requests.insert(
|
self.active_requests.insert(
|
||||||
request_id.into(),
|
request_id.into(),
|
||||||
ActiveRequest {
|
ActiveActionRequest {
|
||||||
|
action_id,
|
||||||
token,
|
token,
|
||||||
start_time: self.current_time,
|
start_time: self.current_time,
|
||||||
timeout_seconds,
|
timeout,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -268,29 +295,23 @@ pub mod std_mod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_for_timeouts(&mut self, time_stamp: &[u8]) -> Result<(), EcssTmtcError> {
|
pub fn check_for_timeouts(&mut self, time_stamp: &[u8]) -> Result<(), EcssTmtcError> {
|
||||||
for (_req_id, active_req) in self.active_requests.iter() {
|
for active_req in self.active_requests.values() {
|
||||||
// TODO: Simplified until spacepackets update.
|
let diff = self.current_time - active_req.start_time;
|
||||||
let diff =
|
if diff.duration_absolute > active_req.timeout {
|
||||||
(self.current_time.unix_seconds - active_req.start_time.unix_seconds) as u32;
|
|
||||||
if diff > active_req.timeout_seconds {
|
|
||||||
self.handle_timeout(active_req, time_stamp);
|
self.handle_timeout(active_req, time_stamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_timeout(&self, active_request: &ActiveRequest, time_stamp: &[u8]) {
|
pub fn handle_timeout(&self, active_request: &ActiveActionRequest, time_stamp: &[u8]) {
|
||||||
self.verification_reporter
|
self.verification_reporter
|
||||||
.completion_failure(
|
.completion_failure(
|
||||||
active_request.token,
|
active_request.token,
|
||||||
FailParams::new(
|
FailParams::new(time_stamp, &self.user_hook.timeout_error_code(), &[]),
|
||||||
time_stamp,
|
|
||||||
// WTF, what failure code?
|
|
||||||
&ResultU16::new(0, 0),
|
|
||||||
&[],
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
self.user_hook.timeout_callback(active_request);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_action_reply(
|
pub fn handle_action_reply(
|
||||||
@ -300,7 +321,8 @@ pub mod std_mod {
|
|||||||
) -> Result<(), EcssTmtcError> {
|
) -> Result<(), EcssTmtcError> {
|
||||||
let active_req = self.active_requests.get(&action_reply_with_ids.request_id);
|
let active_req = self.active_requests.get(&action_reply_with_ids.request_id);
|
||||||
if active_req.is_none() {
|
if active_req.is_none() {
|
||||||
// TODO: This is an unexpected reply. We need to deal with this somehow.
|
self.user_hook
|
||||||
|
.handle_unexpected_reply(&action_reply_with_ids);
|
||||||
}
|
}
|
||||||
let active_req = active_req.unwrap();
|
let active_req = active_req.unwrap();
|
||||||
match action_reply_with_ids.reply {
|
match action_reply_with_ids.reply {
|
||||||
|
Loading…
Reference in New Issue
Block a user