Tricky PUS handler changes #95
@ -1,38 +1,38 @@
|
||||
use crate::events::EventU32;
|
||||
use crate::pool::SharedPool;
|
||||
use crate::pus::event_man::{EventRequest, EventRequestWithToken};
|
||||
use crate::pus::verification::{StdVerifReporterWithSender, TcStateToken};
|
||||
use crate::pus::{
|
||||
EcssTcReceiver, EcssTmSender, PartialPusHandlingError, PusPacketHandlerResult,
|
||||
PusPacketHandlingError, PusServiceBaseWithStore,
|
||||
PusPacketHandlingError,
|
||||
};
|
||||
use alloc::boxed::Box;
|
||||
use spacepackets::ecss::event::Subservice;
|
||||
use spacepackets::ecss::tc::PusTcReader;
|
||||
use spacepackets::ecss::PusPacket;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
pub struct PusService5EventHandler {
|
||||
psb: PusServiceBaseWithStore,
|
||||
use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHandler};
|
||||
|
||||
pub struct PusService5EventHandler<TcInMemConverter: EcssTcInMemConverter> {
|
||||
pub psb: PusServiceHandler<TcInMemConverter>,
|
||||
event_request_tx: Sender<EventRequestWithToken>,
|
||||
}
|
||||
|
||||
impl PusService5EventHandler {
|
||||
impl<TcInMemConverter: EcssTcInMemConverter> PusService5EventHandler<TcInMemConverter> {
|
||||
pub fn new(
|
||||
tc_receiver: Box<dyn EcssTcReceiver>,
|
||||
shared_tc_store: SharedPool,
|
||||
tm_sender: Box<dyn EcssTmSender>,
|
||||
tm_apid: u16,
|
||||
verification_handler: StdVerifReporterWithSender,
|
||||
event_request_tx: Sender<EventRequestWithToken>,
|
||||
tc_in_mem_converter: TcInMemConverter,
|
||||
) -> Self {
|
||||
Self {
|
||||
psb: PusServiceBaseWithStore::new(
|
||||
psb: PusServiceHandler::new(
|
||||
tc_receiver,
|
||||
shared_tc_store,
|
||||
tm_sender,
|
||||
tm_apid,
|
||||
verification_handler,
|
||||
tc_in_mem_converter,
|
||||
),
|
||||
event_request_tx,
|
||||
}
|
||||
@ -44,9 +44,10 @@ impl PusService5EventHandler {
|
||||
return Ok(PusPacketHandlerResult::Empty);
|
||||
}
|
||||
let ecss_tc_and_token = possible_packet.unwrap();
|
||||
self.psb
|
||||
.convert_possible_packet_to_tc_buf(&ecss_tc_and_token)?;
|
||||
let (tc, _) = PusTcReader::new(&self.psb.pus_buf)?;
|
||||
let tc = self
|
||||
.psb
|
||||
.tc_in_mem_converter
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token)?;
|
||||
let subservice = tc.subservice();
|
||||
let srv = Subservice::try_from(subservice);
|
||||
if srv.is_err() {
|
||||
@ -65,6 +66,7 @@ impl PusService5EventHandler {
|
||||
let event_u32 = EventU32::from(u32::from_be_bytes(user_data[0..4].try_into().unwrap()));
|
||||
let start_token = self
|
||||
.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.borrow_mut()
|
||||
.start_success(ecss_tc_and_token.token, Some(&stamp))
|
||||
@ -98,7 +100,7 @@ impl PusService5EventHandler {
|
||||
Ok(PusPacketHandlerResult::RequestHandled)
|
||||
};
|
||||
let mut partial_error = None;
|
||||
let time_stamp = self.psb.get_current_timestamp(&mut partial_error);
|
||||
let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error);
|
||||
match srv.unwrap() {
|
||||
Subservice::TmInfoReport
|
||||
| Subservice::TmLowSeverityReport
|
||||
|
@ -202,12 +202,34 @@ pub enum TcInMemory {
|
||||
Vec(alloc::vec::Vec<u8>),
|
||||
}
|
||||
|
||||
impl From<StoreAddr> for TcInMemory {
|
||||
fn from(value: StoreAddr) -> Self {
|
||||
Self::StoreAddr(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl From<alloc::vec::Vec<u8>> for TcInMemory {
|
||||
fn from(value: alloc::vec::Vec<u8>) -> Self {
|
||||
Self::Vec(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct EcssTcAndToken {
|
||||
pub tc_in_memory: TcInMemory,
|
||||
pub token: Option<TcStateToken>,
|
||||
}
|
||||
|
||||
impl EcssTcAndToken {
|
||||
pub fn new(tc_in_memory: impl Into<TcInMemory>, token: impl Into<TcStateToken>) -> Self {
|
||||
Self {
|
||||
tc_in_memory: tc_in_memory.into(),
|
||||
token: Some(token.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Generic abstraction for a telecommand being sent around after is has been accepted.
|
||||
pub struct AcceptedEcssTcAndToken {
|
||||
pub tc_in_memory: TcInMemory,
|
||||
@ -356,6 +378,7 @@ pub mod std_mod {
|
||||
use alloc::boxed::Box;
|
||||
use alloc::vec::Vec;
|
||||
use crossbeam_channel as cb;
|
||||
use spacepackets::ecss::tc::PusTcReader;
|
||||
use spacepackets::ecss::tm::PusTmCreator;
|
||||
use spacepackets::ecss::PusError;
|
||||
use spacepackets::time::cds::TimeProvider;
|
||||
@ -367,7 +390,8 @@ pub mod std_mod {
|
||||
use std::sync::mpsc::TryRecvError;
|
||||
use thiserror::Error;
|
||||
|
||||
use super::AcceptedEcssTcAndToken;
|
||||
use super::verification::VerificationReporterWithSender;
|
||||
use super::{AcceptedEcssTcAndToken, TcInMemory};
|
||||
|
||||
impl From<mpsc::SendError<StoreAddr>> for EcssTmtcError {
|
||||
fn from(_: mpsc::SendError<StoreAddr>) -> Self {
|
||||
@ -624,6 +648,8 @@ pub mod std_mod {
|
||||
NotEnoughAppData(String),
|
||||
#[error("invalid application data")]
|
||||
InvalidAppData(String),
|
||||
#[error("invalid format of TC in memory: {0:?}")]
|
||||
InvalidTcInMemoryFormat(TcInMemory),
|
||||
#[error("generic ECSS tmtc error: {0}")]
|
||||
EcssTmtc(#[from] EcssTmtcError),
|
||||
#[error("invalid verification token")]
|
||||
@ -660,42 +686,107 @@ pub mod std_mod {
|
||||
}
|
||||
}
|
||||
|
||||
/// Base class for handlers which can handle PUS TC packets. Right now, the verification
|
||||
/// reporter is constrained to the [StdVerifReporterWithSender] and the service handler
|
||||
/// relies on TMTC packets being exchanged via a [SharedPool].
|
||||
pub struct PusServiceBaseWithStore {
|
||||
pub tc_receiver: Box<dyn EcssTcReceiver>,
|
||||
pub trait EcssTcInMemConverter {
|
||||
fn convert_ecss_tc_in_memory_to_reader<'a>(
|
||||
&'a mut self,
|
||||
possible_packet: &'a AcceptedEcssTcAndToken,
|
||||
) -> Result<PusTcReader<'a>, PusPacketHandlingError>;
|
||||
|
||||
fn tc_slice_raw(&self) -> &[u8];
|
||||
}
|
||||
|
||||
pub struct EcssTcInVecConverter {
|
||||
pub pus_tc_raw: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl EcssTcInMemConverter for EcssTcInVecConverter {
|
||||
fn convert_ecss_tc_in_memory_to_reader<'a>(
|
||||
&'a mut self,
|
||||
possible_packet: &'a AcceptedEcssTcAndToken,
|
||||
) -> Result<PusTcReader<'a>, PusPacketHandlingError> {
|
||||
match &possible_packet.tc_in_memory {
|
||||
super::TcInMemory::StoreAddr(_) => {
|
||||
return Err(PusPacketHandlingError::InvalidTcInMemoryFormat(
|
||||
possible_packet.tc_in_memory.clone(),
|
||||
));
|
||||
}
|
||||
super::TcInMemory::Vec(vec) => {
|
||||
self.pus_tc_raw = Some(vec.clone());
|
||||
}
|
||||
};
|
||||
let (tc, _) = PusTcReader::new(self.pus_tc_raw.as_ref().unwrap())?;
|
||||
Ok(tc)
|
||||
}
|
||||
|
||||
fn tc_slice_raw(&self) -> &[u8] {
|
||||
if self.pus_tc_raw.is_none() {
|
||||
return &[];
|
||||
}
|
||||
self.pus_tc_raw.as_ref().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EcssTcInStoreConverter {
|
||||
pub shared_tc_store: SharedPool,
|
||||
pub pus_buf: [u8; 2048],
|
||||
}
|
||||
|
||||
impl EcssTcInStoreConverter {
|
||||
pub fn new(shared_tc_store: SharedPool) -> Self {
|
||||
Self {
|
||||
shared_tc_store,
|
||||
pus_buf: [0; 2048],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn copy_tc_to_buf(&mut self, addr: StoreAddr) -> Result<(), PusPacketHandlingError> {
|
||||
// Keep locked section as short as possible.
|
||||
let mut tc_pool = self
|
||||
.shared_tc_store
|
||||
.write()
|
||||
.map_err(|_| PusPacketHandlingError::EcssTmtc(EcssTmtcError::StoreLock))?;
|
||||
let tc_guard = tc_pool.read_with_guard(addr);
|
||||
let tc_raw = tc_guard.read().unwrap();
|
||||
self.pus_buf[0..tc_raw.len()].copy_from_slice(tc_raw);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl EcssTcInMemConverter for EcssTcInStoreConverter {
|
||||
fn convert_ecss_tc_in_memory_to_reader<'a>(
|
||||
&'a mut self,
|
||||
possible_packet: &'a AcceptedEcssTcAndToken,
|
||||
) -> Result<PusTcReader<'a>, PusPacketHandlingError> {
|
||||
Ok(match &possible_packet.tc_in_memory {
|
||||
super::TcInMemory::StoreAddr(addr) => {
|
||||
self.copy_tc_to_buf(*addr)?;
|
||||
PusTcReader::new(&self.pus_buf)?.0
|
||||
}
|
||||
super::TcInMemory::Vec(_) => {
|
||||
return Err(PusPacketHandlingError::InvalidTcInMemoryFormat(
|
||||
possible_packet.tc_in_memory.clone(),
|
||||
));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn tc_slice_raw(&self) -> &[u8] {
|
||||
self.pus_buf.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PusServiceBase {
|
||||
pub tc_receiver: Box<dyn EcssTcReceiver>,
|
||||
pub tm_sender: Box<dyn EcssTmSender>,
|
||||
pub tm_apid: u16,
|
||||
/// The verification handler is wrapped in a [RefCell] to allow the interior mutability
|
||||
/// pattern. This makes writing methods which are not mutable a lot easier.
|
||||
pub verification_handler: RefCell<StdVerifReporterWithSender>,
|
||||
pub pus_buf: [u8; 2048],
|
||||
pub pus_size: usize,
|
||||
}
|
||||
|
||||
impl PusServiceBaseWithStore {
|
||||
pub fn new(
|
||||
tc_receiver: Box<dyn EcssTcReceiver>,
|
||||
shared_tc_store: SharedPool,
|
||||
tm_sender: Box<dyn EcssTmSender>,
|
||||
tm_apid: u16,
|
||||
verification_handler: StdVerifReporterWithSender,
|
||||
) -> Self {
|
||||
Self {
|
||||
tc_receiver,
|
||||
shared_tc_store,
|
||||
tm_apid,
|
||||
tm_sender,
|
||||
verification_handler: RefCell::new(verification_handler),
|
||||
pus_buf: [0; 2048],
|
||||
pus_size: 0,
|
||||
}
|
||||
}
|
||||
|
||||
impl PusServiceBase {
|
||||
#[cfg(feature = "std")]
|
||||
pub fn get_current_timestamp(
|
||||
&self,
|
||||
partial_error: &mut Option<PartialPusHandlingError>,
|
||||
) -> [u8; 7] {
|
||||
let mut time_stamp: [u8; 7] = [0; 7];
|
||||
@ -710,42 +801,47 @@ pub mod std_mod {
|
||||
time_stamp
|
||||
}
|
||||
|
||||
pub fn get_current_timestamp_ignore_error(&self) -> [u8; 7] {
|
||||
#[cfg(feature = "std")]
|
||||
pub fn get_current_timestamp_ignore_error() -> [u8; 7] {
|
||||
let mut dummy = None;
|
||||
self.get_current_timestamp(&mut dummy)
|
||||
Self::get_current_timestamp(&mut dummy)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn copy_tc_to_buf(&mut self, addr: StoreAddr) -> Result<(), PusPacketHandlingError> {
|
||||
// Keep locked section as short as possible.
|
||||
let mut tc_pool = self
|
||||
.shared_tc_store
|
||||
.write()
|
||||
.map_err(|_| PusPacketHandlingError::EcssTmtc(EcssTmtcError::StoreLock))?;
|
||||
let tc_guard = tc_pool.read_with_guard(addr);
|
||||
let tc_raw = tc_guard.read().unwrap();
|
||||
self.pus_buf[0..tc_raw.len()].copy_from_slice(tc_raw);
|
||||
Ok(())
|
||||
/// Base class for handlers which can handle PUS TC packets. Right now, the verification
|
||||
/// reporter is constrained to the [StdVerifReporterWithSender] and the service handler
|
||||
/// relies on TMTC packets being exchanged via a [SharedPool]. Please note that this variant
|
||||
/// of the PUS service base is not optimized for handling packets sent as a `Vec<u8>` and
|
||||
/// might perform additional copies to the internal buffer as well. The class should
|
||||
/// still behave correctly.
|
||||
pub struct PusServiceHandler<TcInMemConverter: EcssTcInMemConverter> {
|
||||
pub common: PusServiceBase,
|
||||
pub tc_in_mem_converter: TcInMemConverter,
|
||||
}
|
||||
|
||||
pub fn convert_possible_packet_to_tc_buf(
|
||||
&mut self,
|
||||
possible_packet: &AcceptedEcssTcAndToken,
|
||||
) -> Result<(), PusPacketHandlingError> {
|
||||
match &possible_packet.tc_in_memory {
|
||||
super::TcInMemory::StoreAddr(addr) => {
|
||||
self.copy_tc_to_buf(*addr)?;
|
||||
impl<TcInMemConverter: EcssTcInMemConverter> PusServiceHandler<TcInMemConverter> {
|
||||
pub fn new(
|
||||
tc_receiver: Box<dyn EcssTcReceiver>,
|
||||
tm_sender: Box<dyn EcssTmSender>,
|
||||
tm_apid: u16,
|
||||
verification_handler: VerificationReporterWithSender,
|
||||
tc_in_mem_converter: TcInMemConverter,
|
||||
) -> Self {
|
||||
Self {
|
||||
common: PusServiceBase {
|
||||
tc_receiver,
|
||||
tm_sender,
|
||||
tm_apid,
|
||||
verification_handler: RefCell::new(verification_handler),
|
||||
},
|
||||
tc_in_mem_converter,
|
||||
}
|
||||
super::TcInMemory::Vec(vec) => {
|
||||
self.pus_buf.copy_from_slice(vec);
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn retrieve_and_accept_next_packet(
|
||||
&mut self,
|
||||
) -> Result<Option<AcceptedEcssTcAndToken>, PusPacketHandlingError> {
|
||||
match self.tc_receiver.recv_tc() {
|
||||
match self.common.tc_receiver.recv_tc() {
|
||||
Ok(EcssTcAndToken {
|
||||
tc_in_memory,
|
||||
token,
|
||||
|
@ -1,15 +1,13 @@
|
||||
use crate::pool::SharedPool;
|
||||
use crate::pus::scheduler::PusScheduler;
|
||||
use crate::pus::verification::StdVerifReporterWithSender;
|
||||
use crate::pus::{
|
||||
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError,
|
||||
PusServiceBaseWithStore,
|
||||
};
|
||||
use spacepackets::ecss::tc::PusTcReader;
|
||||
use crate::pus::{EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError};
|
||||
use spacepackets::ecss::{scheduling, PusPacket};
|
||||
use spacepackets::time::cds::TimeProvider;
|
||||
use std::boxed::Box;
|
||||
|
||||
use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHandler};
|
||||
|
||||
/// This is a helper class for [std] environments to handle generic PUS 11 (scheduling service)
|
||||
/// packets. This handler is constrained to using the [PusScheduler], but is able to process
|
||||
/// the most important PUS requests for a scheduling service.
|
||||
@ -18,28 +16,31 @@ use std::boxed::Box;
|
||||
/// telecommands inside the scheduler. The user can retrieve the wrapped scheduler via the
|
||||
/// [Self::scheduler] and [Self::scheduler_mut] function and then use the scheduler API to release
|
||||
/// telecommands when applicable.
|
||||
pub struct PusService11SchedHandler {
|
||||
psb: PusServiceBaseWithStore,
|
||||
pub struct PusService11SchedHandler<TcInMemConverter: EcssTcInMemConverter> {
|
||||
pub psb: PusServiceHandler<TcInMemConverter>,
|
||||
shared_tc_store: SharedPool,
|
||||
scheduler: PusScheduler,
|
||||
}
|
||||
|
||||
impl PusService11SchedHandler {
|
||||
impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemConverter> {
|
||||
pub fn new(
|
||||
tc_receiver: Box<dyn EcssTcReceiver>,
|
||||
shared_tc_store: SharedPool,
|
||||
tm_sender: Box<dyn EcssTmSender>,
|
||||
tm_apid: u16,
|
||||
verification_handler: StdVerifReporterWithSender,
|
||||
tc_in_mem_converter: TcInMemConverter,
|
||||
shared_tc_store: SharedPool,
|
||||
scheduler: PusScheduler,
|
||||
) -> Self {
|
||||
Self {
|
||||
psb: PusServiceBaseWithStore::new(
|
||||
psb: PusServiceHandler::new(
|
||||
tc_receiver,
|
||||
shared_tc_store,
|
||||
tm_sender,
|
||||
tm_apid,
|
||||
verification_handler,
|
||||
tc_in_mem_converter,
|
||||
),
|
||||
shared_tc_store,
|
||||
scheduler,
|
||||
}
|
||||
}
|
||||
@ -58,7 +59,10 @@ impl PusService11SchedHandler {
|
||||
return Ok(PusPacketHandlerResult::Empty);
|
||||
}
|
||||
let ecss_tc_and_token = possible_packet.unwrap();
|
||||
let (tc, _) = PusTcReader::new(&self.psb.pus_buf)?;
|
||||
let tc = self
|
||||
.psb
|
||||
.tc_in_mem_converter
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token)?;
|
||||
let subservice = tc.subservice();
|
||||
let std_service = scheduling::Subservice::try_from(subservice);
|
||||
if std_service.is_err() {
|
||||
@ -68,11 +72,12 @@ impl PusService11SchedHandler {
|
||||
));
|
||||
}
|
||||
let mut partial_error = None;
|
||||
let time_stamp = self.psb.get_current_timestamp(&mut partial_error);
|
||||
let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error);
|
||||
match std_service.unwrap() {
|
||||
scheduling::Subservice::TcEnableScheduling => {
|
||||
let start_token = self
|
||||
.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.start_success(ecss_tc_and_token.token, Some(&time_stamp))
|
||||
@ -81,6 +86,7 @@ impl PusService11SchedHandler {
|
||||
self.scheduler.enable();
|
||||
if self.scheduler.is_enabled() {
|
||||
self.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.completion_success(start_token, Some(&time_stamp))
|
||||
@ -92,6 +98,7 @@ impl PusService11SchedHandler {
|
||||
scheduling::Subservice::TcDisableScheduling => {
|
||||
let start_token = self
|
||||
.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.start_success(ecss_tc_and_token.token, Some(&time_stamp))
|
||||
@ -100,6 +107,7 @@ impl PusService11SchedHandler {
|
||||
self.scheduler.disable();
|
||||
if !self.scheduler.is_enabled() {
|
||||
self.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.completion_success(start_token, Some(&time_stamp))
|
||||
@ -111,22 +119,20 @@ impl PusService11SchedHandler {
|
||||
scheduling::Subservice::TcResetScheduling => {
|
||||
let start_token = self
|
||||
.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.start_success(ecss_tc_and_token.token, Some(&time_stamp))
|
||||
.expect("Error sending start success");
|
||||
|
||||
let mut pool = self
|
||||
.psb
|
||||
.shared_tc_store
|
||||
.write()
|
||||
.expect("Locking pool failed");
|
||||
let mut pool = self.shared_tc_store.write().expect("Locking pool failed");
|
||||
|
||||
self.scheduler
|
||||
.reset(pool.as_mut())
|
||||
.expect("Error resetting TC Pool");
|
||||
|
||||
self.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.completion_success(start_token, Some(&time_stamp))
|
||||
@ -135,21 +141,19 @@ impl PusService11SchedHandler {
|
||||
scheduling::Subservice::TcInsertActivity => {
|
||||
let start_token = self
|
||||
.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.start_success(ecss_tc_and_token.token, Some(&time_stamp))
|
||||
.expect("error sending start success");
|
||||
|
||||
let mut pool = self
|
||||
.psb
|
||||
.shared_tc_store
|
||||
.write()
|
||||
.expect("locking pool failed");
|
||||
let mut pool = self.shared_tc_store.write().expect("locking pool failed");
|
||||
self.scheduler
|
||||
.insert_wrapped_tc::<TimeProvider>(&tc, pool.as_mut())
|
||||
.expect("insertion of activity into pool failed");
|
||||
|
||||
self.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.completion_success(start_token, Some(&time_stamp))
|
||||
@ -159,7 +163,7 @@ impl PusService11SchedHandler {
|
||||
// Treat unhandled standard subservices as custom subservices for now.
|
||||
return Ok(PusPacketHandlerResult::CustomSubservice(
|
||||
tc.subservice(),
|
||||
ecss_tc_and_token.token.into(),
|
||||
ecss_tc_and_token.token,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,36 @@
|
||||
use crate::pool::SharedPool;
|
||||
use crate::pus::verification::StdVerifReporterWithSender;
|
||||
use crate::pus::{
|
||||
EcssTcReceiver, EcssTmSender, PartialPusHandlingError, PusPacketHandlerResult,
|
||||
PusPacketHandlingError, PusServiceBaseWithStore, PusTmWrapper,
|
||||
PusPacketHandlingError, PusTmWrapper,
|
||||
};
|
||||
use spacepackets::ecss::tc::PusTcReader;
|
||||
use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
|
||||
use spacepackets::ecss::PusPacket;
|
||||
use spacepackets::SpHeader;
|
||||
use std::boxed::Box;
|
||||
|
||||
use super::verification::VerificationReporterWithSender;
|
||||
use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHandler};
|
||||
|
||||
/// This is a helper class for [std] environments to handle generic PUS 17 (test service) packets.
|
||||
/// This handler only processes ping requests and generates a ping reply for them accordingly.
|
||||
pub struct PusService17TestHandler {
|
||||
pub psb: PusServiceBaseWithStore,
|
||||
pub struct PusService17TestHandler<TcInMemConverter: EcssTcInMemConverter> {
|
||||
pub psb: PusServiceHandler<TcInMemConverter>,
|
||||
}
|
||||
|
||||
impl PusService17TestHandler {
|
||||
impl<TcInMemConverter: EcssTcInMemConverter> PusService17TestHandler<TcInMemConverter> {
|
||||
pub fn new(
|
||||
tc_receiver: Box<dyn EcssTcReceiver>,
|
||||
shared_tc_store: SharedPool,
|
||||
tm_sender: Box<dyn EcssTmSender>,
|
||||
tm_apid: u16,
|
||||
verification_handler: StdVerifReporterWithSender,
|
||||
verification_handler: VerificationReporterWithSender,
|
||||
tc_in_mem_converter: TcInMemConverter,
|
||||
) -> Self {
|
||||
Self {
|
||||
psb: PusServiceBaseWithStore::new(
|
||||
psb: PusServiceHandler::new(
|
||||
tc_receiver,
|
||||
shared_tc_store,
|
||||
tm_sender,
|
||||
tm_apid,
|
||||
verification_handler,
|
||||
tc_in_mem_converter,
|
||||
),
|
||||
}
|
||||
}
|
||||
@ -41,17 +41,19 @@ impl PusService17TestHandler {
|
||||
return Ok(PusPacketHandlerResult::Empty);
|
||||
}
|
||||
let ecss_tc_and_token = possible_packet.unwrap();
|
||||
self.psb
|
||||
.convert_possible_packet_to_tc_buf(&ecss_tc_and_token)?;
|
||||
let (tc, _) = PusTcReader::new(&self.psb.pus_buf)?;
|
||||
let tc = self
|
||||
.psb
|
||||
.tc_in_mem_converter
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token)?;
|
||||
if tc.service() != 17 {
|
||||
return Err(PusPacketHandlingError::WrongService(tc.service()));
|
||||
}
|
||||
if tc.subservice() == 1 {
|
||||
let mut partial_error = None;
|
||||
let time_stamp = self.psb.get_current_timestamp(&mut partial_error);
|
||||
let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error);
|
||||
let result = self
|
||||
.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.start_success(ecss_tc_and_token.token, Some(&time_stamp))
|
||||
@ -63,11 +65,12 @@ impl PusService17TestHandler {
|
||||
None
|
||||
};
|
||||
// Sequence count will be handled centrally in TM funnel.
|
||||
let mut reply_header = SpHeader::tm_unseg(self.psb.tm_apid, 0, 0).unwrap();
|
||||
let mut reply_header = SpHeader::tm_unseg(self.psb.common.tm_apid, 0, 0).unwrap();
|
||||
let tc_header = PusTmSecondaryHeader::new_simple(17, 2, &time_stamp);
|
||||
let ping_reply = PusTmCreator::new(&mut reply_header, tc_header, &[], true);
|
||||
let result = self
|
||||
.psb
|
||||
.common
|
||||
.tm_sender
|
||||
.send_tm(PusTmWrapper::Direct(ping_reply))
|
||||
.map_err(PartialPusHandlingError::TmSend);
|
||||
@ -78,6 +81,7 @@ impl PusService17TestHandler {
|
||||
if let Some(start_token) = start_token {
|
||||
if self
|
||||
.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.completion_success(start_token, Some(&time_stamp))
|
||||
@ -94,7 +98,7 @@ impl PusService17TestHandler {
|
||||
} else {
|
||||
return Ok(PusPacketHandlerResult::CustomSubservice(
|
||||
tc.subservice(),
|
||||
ecss_tc_and_token.token.into(),
|
||||
ecss_tc_and_token.token,
|
||||
));
|
||||
}
|
||||
Ok(PusPacketHandlerResult::RequestHandled)
|
||||
@ -106,9 +110,11 @@ mod tests {
|
||||
use crate::pool::{LocalPool, PoolCfg, SharedPool};
|
||||
use crate::pus::test::PusService17TestHandler;
|
||||
use crate::pus::verification::{
|
||||
RequestId, StdVerifReporterWithSender, VerificationReporterCfg,
|
||||
RequestId, VerificationReporterCfg, VerificationReporterWithSender,
|
||||
};
|
||||
use crate::pus::{
|
||||
EcssTcAndToken, EcssTcInStoreConverter, MpscTcInStoreReceiver, MpscTmInStoreSender,
|
||||
};
|
||||
use crate::pus::{MpscTcInStoreReceiver, MpscTmInStoreSender};
|
||||
use crate::tmtc::tm_helper::SharedTmStore;
|
||||
use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader};
|
||||
use spacepackets::ecss::tm::PusTmReader;
|
||||
@ -135,15 +141,16 @@ mod tests {
|
||||
MpscTmInStoreSender::new(0, "verif_sender", shared_tm_store.clone(), tm_tx.clone());
|
||||
let verif_cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
|
||||
let mut verification_handler =
|
||||
StdVerifReporterWithSender::new(&verif_cfg, Box::new(verif_sender));
|
||||
VerificationReporterWithSender::new(&verif_cfg, Box::new(verif_sender));
|
||||
let test_srv_tm_sender = MpscTmInStoreSender::new(0, "TEST_SENDER", shared_tm_store, tm_tx);
|
||||
let test_srv_tc_receiver = MpscTcInStoreReceiver::new(0, "TEST_RECEIVER", test_srv_tc_rx);
|
||||
let in_store_converter = EcssTcInStoreConverter::new(tc_pool_shared.clone());
|
||||
let mut pus_17_handler = PusService17TestHandler::new(
|
||||
Box::new(test_srv_tc_receiver),
|
||||
tc_pool_shared.clone(),
|
||||
Box::new(test_srv_tm_sender),
|
||||
TEST_APID,
|
||||
verification_handler.clone(),
|
||||
in_store_converter,
|
||||
);
|
||||
// Create a ping TC, verify acceptance.
|
||||
let mut sp_header = SpHeader::tc(TEST_APID, SequenceFlags::Unsegmented, 0, 0).unwrap();
|
||||
@ -158,7 +165,9 @@ mod tests {
|
||||
let addr = tc_pool.add(&pus_buf[..tc_size]).unwrap();
|
||||
drop(tc_pool);
|
||||
// Send accepted TC to test service handler.
|
||||
test_srv_tc_tx.send((addr, token.into())).unwrap();
|
||||
test_srv_tc_tx
|
||||
.send(EcssTcAndToken::new(addr, token))
|
||||
.unwrap();
|
||||
let result = pus_17_handler.handle_one_tc();
|
||||
assert!(result.is_ok());
|
||||
// We should see 4 replies in the TM queue now: Acceptance TM, Start TM, ping reply and
|
||||
|
@ -5,8 +5,7 @@ use satrs_core::pus::verification::{
|
||||
FailParams, StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
|
||||
};
|
||||
use satrs_core::pus::{
|
||||
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError,
|
||||
PusServiceBaseWithStore,
|
||||
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceHandler,
|
||||
};
|
||||
use satrs_core::spacepackets::ecss::tc::PusTcReader;
|
||||
use satrs_core::spacepackets::ecss::PusPacket;
|
||||
@ -16,7 +15,7 @@ use std::collections::HashMap;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
pub struct PusService8ActionHandler {
|
||||
psb: PusServiceBaseWithStore,
|
||||
psb: PusServiceHandler,
|
||||
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
|
||||
}
|
||||
|
||||
@ -26,11 +25,11 @@ impl PusService8ActionHandler {
|
||||
shared_tc_pool: SharedPool,
|
||||
tm_sender: Box<dyn EcssTmSender>,
|
||||
tm_apid: u16,
|
||||
verification_handler: StdVerifReporterWithSender,
|
||||
verification_handler: VerificationReporterWithSender,
|
||||
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
psb: PusServiceBaseWithStore::new(
|
||||
psb: PusServiceHandler::new(
|
||||
tc_receiver,
|
||||
shared_tc_pool,
|
||||
tm_sender,
|
||||
|
@ -4,8 +4,7 @@ use satrs_core::hk::{CollectionIntervalFactor, HkRequest};
|
||||
use satrs_core::pool::SharedPool;
|
||||
use satrs_core::pus::verification::{FailParams, StdVerifReporterWithSender};
|
||||
use satrs_core::pus::{
|
||||
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError,
|
||||
PusServiceBaseWithStore,
|
||||
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceHandler,
|
||||
};
|
||||
use satrs_core::spacepackets::ecss::tc::PusTcReader;
|
||||
use satrs_core::spacepackets::ecss::{hk, PusPacket};
|
||||
@ -15,7 +14,7 @@ use std::collections::HashMap;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
pub struct PusService3HkHandler {
|
||||
psb: PusServiceBaseWithStore,
|
||||
psb: PusServiceHandler,
|
||||
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
|
||||
}
|
||||
|
||||
@ -29,7 +28,7 @@ impl PusService3HkHandler {
|
||||
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
psb: PusServiceBaseWithStore::new(
|
||||
psb: PusServiceHandler::new(
|
||||
tc_receiver,
|
||||
shared_tc_pool,
|
||||
tm_sender,
|
||||
|
Loading…
Reference in New Issue
Block a user