introduce simplification for backing traits
This commit is contained in:
parent
6152c834d4
commit
9759818d94
@ -48,7 +48,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService5EventHandler<TcInMemConv
|
||||
let tc = self
|
||||
.psb
|
||||
.tc_in_mem_converter
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token)?;
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?;
|
||||
let subservice = tc.subservice();
|
||||
let srv = Subservice::try_from(subservice);
|
||||
if srv.is_err() {
|
||||
|
@ -689,36 +689,39 @@ pub mod std_mod {
|
||||
}
|
||||
|
||||
pub trait EcssTcInMemConverter {
|
||||
fn cache_ecss_tc_in_memory<'a>(
|
||||
&'a mut self,
|
||||
possible_packet: &'a AcceptedEcssTcAndToken,
|
||||
fn cache_ecss_tc_in_memory(
|
||||
&mut self,
|
||||
possible_packet: &TcInMemory,
|
||||
) -> Result<(), PusPacketHandlingError>;
|
||||
|
||||
fn tc_slice_raw(&self) -> &[u8];
|
||||
|
||||
fn convert_ecss_tc_in_memory_to_reader<'a>(
|
||||
&'a mut self,
|
||||
possible_packet: &'a AcceptedEcssTcAndToken,
|
||||
) -> Result<PusTcReader<'a>, PusPacketHandlingError> {
|
||||
fn convert_ecss_tc_in_memory_to_reader(
|
||||
&mut self,
|
||||
possible_packet: &TcInMemory,
|
||||
) -> Result<PusTcReader<'_>, PusPacketHandlingError> {
|
||||
self.cache_ecss_tc_in_memory(possible_packet)?;
|
||||
Ok(PusTcReader::new(self.tc_slice_raw())?.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Converter structure for PUS telecommands which are stored inside a [Vec<u8>] structure.
|
||||
/// Please note that this structure is not able to convert TCs which are stored inside a
|
||||
/// [SharedPool].
|
||||
pub struct EcssTcInVecConverter {
|
||||
pub pus_tc_raw: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl EcssTcInMemConverter for EcssTcInVecConverter {
|
||||
fn cache_ecss_tc_in_memory<'a>(
|
||||
&'a mut self,
|
||||
possible_packet: &'a AcceptedEcssTcAndToken,
|
||||
fn cache_ecss_tc_in_memory(
|
||||
&mut self,
|
||||
tc_in_memory: &TcInMemory,
|
||||
) -> Result<(), PusPacketHandlingError> {
|
||||
self.pus_tc_raw = None;
|
||||
match &possible_packet.tc_in_memory {
|
||||
match tc_in_memory {
|
||||
super::TcInMemory::StoreAddr(_) => {
|
||||
return Err(PusPacketHandlingError::InvalidTcInMemoryFormat(
|
||||
possible_packet.tc_in_memory.clone(),
|
||||
tc_in_memory.clone(),
|
||||
));
|
||||
}
|
||||
super::TcInMemory::Vec(vec) => {
|
||||
@ -736,9 +739,12 @@ pub mod std_mod {
|
||||
}
|
||||
}
|
||||
|
||||
/// Converter structure for PUS telecommands which are stored inside a [SharedPool] structure.
|
||||
/// This is useful if run-time allocation for these packets should be avoided. Please note
|
||||
/// that this structure is not able to convert TCs which are stored as a `Vec<u8>`.
|
||||
pub struct EcssTcInStoreConverter {
|
||||
pub shared_tc_store: SharedPool,
|
||||
pub pus_buf: Vec<u8>,
|
||||
shared_tc_store: SharedPool,
|
||||
pus_buf: Vec<u8>,
|
||||
}
|
||||
|
||||
impl EcssTcInStoreConverter {
|
||||
@ -766,17 +772,17 @@ pub mod std_mod {
|
||||
}
|
||||
|
||||
impl EcssTcInMemConverter for EcssTcInStoreConverter {
|
||||
fn cache_ecss_tc_in_memory<'a>(
|
||||
&'a mut self,
|
||||
possible_packet: &'a AcceptedEcssTcAndToken,
|
||||
fn cache_ecss_tc_in_memory(
|
||||
&mut self,
|
||||
tc_in_memory: &TcInMemory,
|
||||
) -> Result<(), PusPacketHandlingError> {
|
||||
match &possible_packet.tc_in_memory {
|
||||
match tc_in_memory {
|
||||
super::TcInMemory::StoreAddr(addr) => {
|
||||
self.copy_tc_to_buf(*addr)?;
|
||||
}
|
||||
super::TcInMemory::Vec(_) => {
|
||||
return Err(PusPacketHandlingError::InvalidTcInMemoryFormat(
|
||||
possible_packet.tc_in_memory.clone(),
|
||||
tc_in_memory.clone(),
|
||||
));
|
||||
}
|
||||
};
|
||||
|
@ -62,7 +62,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
|
||||
let tc = self
|
||||
.psb
|
||||
.tc_in_mem_converter
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token)?;
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?;
|
||||
let subservice = tc.subservice();
|
||||
let std_service = scheduling::Subservice::try_from(subservice);
|
||||
if std_service.is_err() {
|
||||
|
@ -44,7 +44,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService17TestHandler<TcInMemConv
|
||||
let tc = self
|
||||
.psb
|
||||
.tc_in_mem_converter
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token)?;
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?;
|
||||
if tc.service() != 17 {
|
||||
return Err(PusPacketHandlingError::WrongService(tc.service()));
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService8ActionHandler<TcInMemCon
|
||||
let ecss_tc_and_token = possible_packet.unwrap();
|
||||
self.psb
|
||||
.tc_in_mem_converter
|
||||
.cache_ecss_tc_in_memory(&ecss_tc_and_token)?;
|
||||
.cache_ecss_tc_in_memory(&ecss_tc_and_token.tc_in_memory)?;
|
||||
let tc = PusTcReader::new(self.psb.tc_in_mem_converter.tc_slice_raw())?.0;
|
||||
let subservice = tc.subservice();
|
||||
let mut partial_error = None;
|
||||
|
@ -46,7 +46,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService3HkHandler<TcInMemConvert
|
||||
let tc = self
|
||||
.psb
|
||||
.tc_in_mem_converter
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token)?;
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?;
|
||||
let subservice = tc.subservice();
|
||||
let mut partial_error = None;
|
||||
let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error);
|
||||
|
Loading…
Reference in New Issue
Block a user