2023-07-04 15:17:43 +02:00
|
|
|
use crate::tmtc::MpscStoreAndSendError;
|
2023-07-08 13:20:08 +02:00
|
|
|
use log::warn;
|
2023-07-05 11:25:23 +02:00
|
|
|
use satrs_core::pool::StoreAddr;
|
|
|
|
use satrs_core::pus::verification::{FailParams, StdVerifReporterWithSender};
|
2023-07-10 00:29:31 +02:00
|
|
|
use satrs_core::pus::{PusPacketHandlerResult, TcAddrWithToken};
|
2023-07-10 01:27:37 +02:00
|
|
|
use satrs_core::spacepackets::ecss::tc::PusTc;
|
2023-07-05 11:25:23 +02:00
|
|
|
use satrs_core::spacepackets::ecss::PusServiceId;
|
|
|
|
use satrs_core::spacepackets::time::cds::TimeProvider;
|
|
|
|
use satrs_core::spacepackets::time::TimeWriter;
|
|
|
|
use satrs_example::{tmtc_err, CustomPusServiceId};
|
|
|
|
use std::sync::mpsc::Sender;
|
2022-08-29 01:33:32 +02:00
|
|
|
|
2023-07-05 21:08:04 +02:00
|
|
|
pub mod action;
|
2023-07-05 14:25:51 +02:00
|
|
|
pub mod event;
|
2023-07-05 21:10:45 +02:00
|
|
|
pub mod hk;
|
2023-07-04 18:51:54 +02:00
|
|
|
pub mod scheduler;
|
2023-07-03 18:22:08 +02:00
|
|
|
pub mod test;
|
|
|
|
|
2023-07-03 01:33:13 +02:00
|
|
|
pub struct PusTcMpscRouter {
|
2023-07-10 00:29:31 +02:00
|
|
|
pub test_service_receiver: Sender<TcAddrWithToken>,
|
|
|
|
pub event_service_receiver: Sender<TcAddrWithToken>,
|
|
|
|
pub sched_service_receiver: Sender<TcAddrWithToken>,
|
|
|
|
pub hk_service_receiver: Sender<TcAddrWithToken>,
|
|
|
|
pub action_service_receiver: Sender<TcAddrWithToken>,
|
2023-07-02 20:49:45 +02:00
|
|
|
}
|
2023-07-03 01:33:13 +02:00
|
|
|
|
2022-09-03 13:47:25 +02:00
|
|
|
pub struct PusReceiver {
|
2023-02-04 15:35:18 +01:00
|
|
|
pub verif_reporter: StdVerifReporterWithSender,
|
2023-07-03 01:33:13 +02:00
|
|
|
pub pus_router: PusTcMpscRouter,
|
2023-07-06 00:49:18 +02:00
|
|
|
stamp_helper: TimeStampHelper,
|
2023-02-04 15:35:18 +01:00
|
|
|
}
|
|
|
|
|
2023-02-15 02:12:00 +01:00
|
|
|
struct TimeStampHelper {
|
|
|
|
stamper: TimeProvider,
|
|
|
|
time_stamp: [u8; 7],
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TimeStampHelper {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
|
|
|
stamper: TimeProvider::new_with_u16_days(0, 0),
|
|
|
|
time_stamp: [0; 7],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn stamp(&self) -> &[u8] {
|
|
|
|
&self.time_stamp
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update_from_now(&mut self) {
|
|
|
|
self.stamper
|
|
|
|
.update_from_now()
|
|
|
|
.expect("Updating timestamp failed");
|
|
|
|
self.stamper
|
|
|
|
.write_to_bytes(&mut self.time_stamp)
|
|
|
|
.expect("Writing timestamp failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-03 13:47:25 +02:00
|
|
|
impl PusReceiver {
|
2023-07-06 00:49:18 +02:00
|
|
|
pub fn new(verif_reporter: StdVerifReporterWithSender, pus_router: PusTcMpscRouter) -> Self {
|
2022-09-03 13:47:25 +02:00
|
|
|
Self {
|
2023-07-06 00:49:18 +02:00
|
|
|
verif_reporter,
|
|
|
|
pus_router,
|
2023-02-15 02:12:00 +01:00
|
|
|
stamp_helper: TimeStampHelper::new(),
|
2022-09-03 13:47:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 18:22:08 +02:00
|
|
|
impl PusReceiver {
|
|
|
|
pub fn handle_tc_packet(
|
2022-09-03 13:47:25 +02:00
|
|
|
&mut self,
|
2023-07-03 18:22:08 +02:00
|
|
|
store_addr: StoreAddr,
|
2022-09-03 13:47:25 +02:00
|
|
|
service: u8,
|
|
|
|
pus_tc: &PusTc,
|
2023-07-08 13:20:08 +02:00
|
|
|
) -> Result<PusPacketHandlerResult, MpscStoreAndSendError> {
|
2023-07-06 00:49:18 +02:00
|
|
|
let init_token = self.verif_reporter.add_tc(pus_tc);
|
2023-02-15 02:12:00 +01:00
|
|
|
self.stamp_helper.update_from_now();
|
2023-02-15 11:19:23 +01:00
|
|
|
let accepted_token = self
|
2023-07-06 00:49:18 +02:00
|
|
|
.verif_reporter
|
2023-02-15 11:19:23 +01:00
|
|
|
.acceptance_success(init_token, Some(self.stamp_helper.stamp()))
|
2022-09-10 20:18:19 +02:00
|
|
|
.expect("Acceptance success failure");
|
2023-02-15 02:12:00 +01:00
|
|
|
let service = PusServiceId::try_from(service);
|
|
|
|
match service {
|
|
|
|
Ok(standard_service) => match standard_service {
|
2023-07-04 18:51:54 +02:00
|
|
|
PusServiceId::Test => {
|
2023-07-08 13:20:08 +02:00
|
|
|
self.pus_router
|
2023-07-04 18:51:54 +02:00
|
|
|
.test_service_receiver
|
2023-07-10 00:29:31 +02:00
|
|
|
.send((store_addr, accepted_token.into()))?;
|
2023-07-04 18:51:54 +02:00
|
|
|
}
|
2023-07-03 18:22:08 +02:00
|
|
|
PusServiceId::Housekeeping => self
|
|
|
|
.pus_router
|
|
|
|
.hk_service_receiver
|
2023-07-10 00:29:31 +02:00
|
|
|
.send((store_addr, accepted_token.into()))?,
|
2023-07-03 01:33:13 +02:00
|
|
|
PusServiceId::Event => self
|
|
|
|
.pus_router
|
|
|
|
.event_service_receiver
|
2023-07-10 00:29:31 +02:00
|
|
|
.send((store_addr, accepted_token.into()))?,
|
2023-07-03 01:33:13 +02:00
|
|
|
PusServiceId::Scheduling => self
|
|
|
|
.pus_router
|
|
|
|
.sched_service_receiver
|
2023-07-10 00:29:31 +02:00
|
|
|
.send((store_addr, accepted_token.into()))?,
|
2023-07-08 13:20:08 +02:00
|
|
|
_ => {
|
|
|
|
let result = self.verif_reporter.start_failure(
|
2023-02-15 02:12:00 +01:00
|
|
|
accepted_token,
|
|
|
|
FailParams::new(
|
2023-02-15 11:19:23 +01:00
|
|
|
Some(self.stamp_helper.stamp()),
|
2023-02-15 02:12:00 +01:00
|
|
|
&tmtc_err::PUS_SERVICE_NOT_IMPLEMENTED,
|
|
|
|
Some(&[standard_service as u8]),
|
|
|
|
),
|
2023-07-08 13:20:08 +02:00
|
|
|
);
|
|
|
|
if result.is_err() {
|
|
|
|
warn!("Sending verification failure failed");
|
|
|
|
}
|
|
|
|
}
|
2023-02-15 02:12:00 +01:00
|
|
|
},
|
|
|
|
Err(e) => {
|
|
|
|
if let Ok(custom_service) = CustomPusServiceId::try_from(e.number) {
|
|
|
|
match custom_service {
|
|
|
|
CustomPusServiceId::Mode => {
|
2023-07-03 18:22:08 +02:00
|
|
|
//self.handle_mode_service(pus_tc, accepted_token)
|
2023-02-15 02:12:00 +01:00
|
|
|
}
|
|
|
|
CustomPusServiceId::Health => {}
|
|
|
|
}
|
|
|
|
} else {
|
2023-07-06 00:49:18 +02:00
|
|
|
self.verif_reporter
|
2023-02-15 02:12:00 +01:00
|
|
|
.start_failure(
|
|
|
|
accepted_token,
|
|
|
|
FailParams::new(
|
|
|
|
Some(self.stamp_helper.stamp()),
|
|
|
|
&tmtc_err::INVALID_PUS_SUBSERVICE,
|
|
|
|
Some(&[e.number]),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.expect("Start failure verification failed")
|
|
|
|
}
|
|
|
|
}
|
2022-09-03 13:47:25 +02:00
|
|
|
}
|
2023-07-08 13:20:08 +02:00
|
|
|
Ok(PusPacketHandlerResult::RequestHandled)
|
2022-09-03 13:47:25 +02:00
|
|
|
}
|
|
|
|
}
|