introduce simplification for backing traits
All checks were successful
Rust/sat-rs/pipeline/head This commit looks good
Rust/sat-rs/pipeline/pr-main This commit looks good

This commit is contained in:
Robin Müller 2024-01-31 14:45:42 +01:00
parent 6152c834d4
commit 9759818d94
Signed by: muellerr
GPG Key ID: A649FB78196E3849
6 changed files with 30 additions and 24 deletions

View File

@ -48,7 +48,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService5EventHandler<TcInMemConv
let tc = self let tc = self
.psb .psb
.tc_in_mem_converter .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 subservice = tc.subservice();
let srv = Subservice::try_from(subservice); let srv = Subservice::try_from(subservice);
if srv.is_err() { if srv.is_err() {

View File

@ -689,36 +689,39 @@ pub mod std_mod {
} }
pub trait EcssTcInMemConverter { pub trait EcssTcInMemConverter {
fn cache_ecss_tc_in_memory<'a>( fn cache_ecss_tc_in_memory(
&'a mut self, &mut self,
possible_packet: &'a AcceptedEcssTcAndToken, possible_packet: &TcInMemory,
) -> Result<(), PusPacketHandlingError>; ) -> Result<(), PusPacketHandlingError>;
fn tc_slice_raw(&self) -> &[u8]; fn tc_slice_raw(&self) -> &[u8];
fn convert_ecss_tc_in_memory_to_reader<'a>( fn convert_ecss_tc_in_memory_to_reader(
&'a mut self, &mut self,
possible_packet: &'a AcceptedEcssTcAndToken, possible_packet: &TcInMemory,
) -> Result<PusTcReader<'a>, PusPacketHandlingError> { ) -> Result<PusTcReader<'_>, PusPacketHandlingError> {
self.cache_ecss_tc_in_memory(possible_packet)?; self.cache_ecss_tc_in_memory(possible_packet)?;
Ok(PusTcReader::new(self.tc_slice_raw())?.0) 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 struct EcssTcInVecConverter {
pub pus_tc_raw: Option<Vec<u8>>, pub pus_tc_raw: Option<Vec<u8>>,
} }
impl EcssTcInMemConverter for EcssTcInVecConverter { impl EcssTcInMemConverter for EcssTcInVecConverter {
fn cache_ecss_tc_in_memory<'a>( fn cache_ecss_tc_in_memory(
&'a mut self, &mut self,
possible_packet: &'a AcceptedEcssTcAndToken, tc_in_memory: &TcInMemory,
) -> Result<(), PusPacketHandlingError> { ) -> Result<(), PusPacketHandlingError> {
self.pus_tc_raw = None; self.pus_tc_raw = None;
match &possible_packet.tc_in_memory { match tc_in_memory {
super::TcInMemory::StoreAddr(_) => { super::TcInMemory::StoreAddr(_) => {
return Err(PusPacketHandlingError::InvalidTcInMemoryFormat( return Err(PusPacketHandlingError::InvalidTcInMemoryFormat(
possible_packet.tc_in_memory.clone(), tc_in_memory.clone(),
)); ));
} }
super::TcInMemory::Vec(vec) => { 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 struct EcssTcInStoreConverter {
pub shared_tc_store: SharedPool, shared_tc_store: SharedPool,
pub pus_buf: Vec<u8>, pus_buf: Vec<u8>,
} }
impl EcssTcInStoreConverter { impl EcssTcInStoreConverter {
@ -766,17 +772,17 @@ pub mod std_mod {
} }
impl EcssTcInMemConverter for EcssTcInStoreConverter { impl EcssTcInMemConverter for EcssTcInStoreConverter {
fn cache_ecss_tc_in_memory<'a>( fn cache_ecss_tc_in_memory(
&'a mut self, &mut self,
possible_packet: &'a AcceptedEcssTcAndToken, tc_in_memory: &TcInMemory,
) -> Result<(), PusPacketHandlingError> { ) -> Result<(), PusPacketHandlingError> {
match &possible_packet.tc_in_memory { match tc_in_memory {
super::TcInMemory::StoreAddr(addr) => { super::TcInMemory::StoreAddr(addr) => {
self.copy_tc_to_buf(*addr)?; self.copy_tc_to_buf(*addr)?;
} }
super::TcInMemory::Vec(_) => { super::TcInMemory::Vec(_) => {
return Err(PusPacketHandlingError::InvalidTcInMemoryFormat( return Err(PusPacketHandlingError::InvalidTcInMemoryFormat(
possible_packet.tc_in_memory.clone(), tc_in_memory.clone(),
)); ));
} }
}; };

View File

@ -62,7 +62,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
let tc = self let tc = self
.psb .psb
.tc_in_mem_converter .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 subservice = tc.subservice();
let std_service = scheduling::Subservice::try_from(subservice); let std_service = scheduling::Subservice::try_from(subservice);
if std_service.is_err() { if std_service.is_err() {

View File

@ -44,7 +44,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService17TestHandler<TcInMemConv
let tc = self let tc = self
.psb .psb
.tc_in_mem_converter .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 { if tc.service() != 17 {
return Err(PusPacketHandlingError::WrongService(tc.service())); return Err(PusPacketHandlingError::WrongService(tc.service()));
} }

View File

@ -105,7 +105,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService8ActionHandler<TcInMemCon
let ecss_tc_and_token = possible_packet.unwrap(); let ecss_tc_and_token = possible_packet.unwrap();
self.psb self.psb
.tc_in_mem_converter .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 tc = PusTcReader::new(self.psb.tc_in_mem_converter.tc_slice_raw())?.0;
let subservice = tc.subservice(); let subservice = tc.subservice();
let mut partial_error = None; let mut partial_error = None;

View File

@ -46,7 +46,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService3HkHandler<TcInMemConvert
let tc = self let tc = self
.psb .psb
.tc_in_mem_converter .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 subservice = tc.subservice();
let mut partial_error = None; let mut partial_error = None;
let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error); let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error);