2024-04-04 15:18:53 +02:00
|
|
|
use crate::pus::mode::ModeServiceWrapper;
|
|
|
|
use derive_new::new;
|
|
|
|
use satrs::{
|
|
|
|
pus::{EcssTcInMemConverter, EcssTmSenderCore},
|
|
|
|
spacepackets::time::{cds, TimeWriter},
|
2024-02-26 15:18:15 +01:00
|
|
|
};
|
2024-02-07 18:10:47 +01:00
|
|
|
|
|
|
|
use super::{
|
2024-04-04 15:18:53 +02:00
|
|
|
action::ActionServiceWrapper, event::EventServiceWrapper, hk::HkServiceWrapper,
|
|
|
|
scheduler::SchedulingServiceWrapper, test::TestCustomServiceWrapper, HandlingStatus,
|
|
|
|
TargetedPusService,
|
2024-02-07 18:10:47 +01:00
|
|
|
};
|
|
|
|
|
2024-04-04 15:18:53 +02:00
|
|
|
#[derive(new)]
|
|
|
|
pub struct PusStack<TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter> {
|
|
|
|
test_srv: TestCustomServiceWrapper<TmSender, TcInMemConverter>,
|
|
|
|
hk_srv_wrapper: HkServiceWrapper<TmSender, TcInMemConverter>,
|
|
|
|
event_srv: EventServiceWrapper<TmSender, TcInMemConverter>,
|
|
|
|
action_srv_wrapper: ActionServiceWrapper<TmSender, TcInMemConverter>,
|
|
|
|
schedule_srv: SchedulingServiceWrapper<TmSender, TcInMemConverter>,
|
|
|
|
mode_srv: ModeServiceWrapper<TmSender, TcInMemConverter>,
|
2024-02-07 18:10:47 +01:00
|
|
|
}
|
|
|
|
|
2024-04-04 15:18:53 +02:00
|
|
|
impl<TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter>
|
|
|
|
PusStack<TmSender, TcInMemConverter>
|
2024-02-26 11:41:42 +01:00
|
|
|
{
|
2024-02-07 18:10:47 +01:00
|
|
|
pub fn periodic_operation(&mut self) {
|
2024-04-04 15:18:53 +02:00
|
|
|
// Release all telecommands which reached their release time before calling the service
|
|
|
|
// handlers.
|
2024-02-07 18:10:47 +01:00
|
|
|
self.schedule_srv.release_tcs();
|
2024-04-04 15:18:53 +02:00
|
|
|
let time_stamp = cds::CdsTime::now_with_u16_days()
|
|
|
|
.expect("time stamp generation error")
|
|
|
|
.to_vec()
|
|
|
|
.unwrap();
|
2024-02-07 18:10:47 +01:00
|
|
|
loop {
|
2024-04-04 15:18:53 +02:00
|
|
|
let mut nothing_to_do = true;
|
|
|
|
let mut is_srv_finished =
|
|
|
|
|tc_handling_done: bool, reply_handling_done: Option<HandlingStatus>| {
|
|
|
|
if !tc_handling_done
|
|
|
|
|| (reply_handling_done.is_some()
|
|
|
|
&& reply_handling_done.unwrap() == HandlingStatus::Empty)
|
|
|
|
{
|
|
|
|
nothing_to_do = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
is_srv_finished(self.test_srv.poll_and_handle_next_packet(&time_stamp), None);
|
|
|
|
is_srv_finished(self.schedule_srv.poll_and_handle_next_tc(&time_stamp), None);
|
|
|
|
is_srv_finished(self.event_srv.poll_and_handle_next_tc(&time_stamp), None);
|
|
|
|
is_srv_finished(
|
|
|
|
self.action_srv_wrapper.poll_and_handle_next_tc(&time_stamp),
|
|
|
|
Some(
|
|
|
|
self.action_srv_wrapper
|
|
|
|
.poll_and_handle_next_reply(&time_stamp),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
is_srv_finished(
|
|
|
|
self.hk_srv_wrapper.poll_and_handle_next_tc(&time_stamp),
|
|
|
|
Some(self.hk_srv_wrapper.poll_and_handle_next_reply(&time_stamp)),
|
|
|
|
);
|
|
|
|
is_srv_finished(
|
|
|
|
self.mode_srv.poll_and_handle_next_tc(&time_stamp),
|
|
|
|
Some(self.mode_srv.poll_and_handle_next_reply(&time_stamp)),
|
|
|
|
);
|
|
|
|
if nothing_to_do {
|
|
|
|
// Timeout checking is only done once.
|
|
|
|
self.action_srv_wrapper.check_for_request_timeouts();
|
|
|
|
self.hk_srv_wrapper.check_for_request_timeouts();
|
|
|
|
self.mode_srv.check_for_request_timeouts();
|
2024-02-07 18:10:47 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|