move additional function to trait
Some checks failed
Rust/spacepackets/pipeline/head There was a failure building this commit
Some checks failed
Rust/spacepackets/pipeline/head There was a failure building this commit
This commit is contained in:
parent
ef4244c8cb
commit
28cd8c02ac
@ -350,6 +350,7 @@ pub type EcssEnumU32 = GenericEcssEnumWrapper<u32>;
|
||||
pub type EcssEnumU64 = GenericEcssEnumWrapper<u64>;
|
||||
|
||||
pub trait SerializablePusPacket {
|
||||
fn len_packed(&self) -> usize;
|
||||
fn write_to_bytes(&self, slice: &mut [u8]) -> Result<usize, PusError>;
|
||||
}
|
||||
|
||||
|
16
src/tc.rs
16
src/tc.rs
@ -290,14 +290,6 @@ impl<'raw_data> PusTc<'raw_data> {
|
||||
&self.sp_header
|
||||
}
|
||||
|
||||
pub fn len_packed(&self) -> usize {
|
||||
let mut length = PUS_TC_MIN_LEN_WITHOUT_APP_DATA;
|
||||
if let Some(app_data) = self.app_data {
|
||||
length += app_data.len();
|
||||
}
|
||||
length
|
||||
}
|
||||
|
||||
pub fn set_ack_field(&mut self, ack: u8) -> bool {
|
||||
if ack > 0b1111 {
|
||||
return false;
|
||||
@ -419,6 +411,14 @@ impl<'raw_data> PusTc<'raw_data> {
|
||||
}
|
||||
|
||||
impl SerializablePusPacket for PusTc<'_> {
|
||||
fn len_packed(&self) -> usize {
|
||||
let mut length = PUS_TC_MIN_LEN_WITHOUT_APP_DATA;
|
||||
if let Some(app_data) = self.app_data {
|
||||
length += app_data.len();
|
||||
}
|
||||
length
|
||||
}
|
||||
|
||||
/// Write the raw PUS byte representation to a provided buffer.
|
||||
fn write_to_bytes(&self, slice: &mut [u8]) -> Result<usize, PusError> {
|
||||
let mut curr_idx = 0;
|
||||
|
21
src/tm.rs
21
src/tm.rs
@ -253,17 +253,6 @@ impl<'raw_data> PusTm<'raw_data> {
|
||||
pus_tm
|
||||
}
|
||||
|
||||
pub fn len_packed(&self) -> usize {
|
||||
let mut length = PUS_TM_MIN_LEN_WITHOUT_SOURCE_DATA;
|
||||
if let Some(timestamp) = self.sec_header.timestamp {
|
||||
length += timestamp.len();
|
||||
}
|
||||
if let Some(src_data) = self.source_data {
|
||||
length += src_data.len();
|
||||
}
|
||||
length
|
||||
}
|
||||
|
||||
pub fn timestamp(&self) -> Option<&'raw_data [u8]> {
|
||||
self.sec_header.timestamp
|
||||
}
|
||||
@ -411,6 +400,16 @@ impl<'raw_data> PusTm<'raw_data> {
|
||||
}
|
||||
|
||||
impl SerializablePusPacket for PusTm<'_> {
|
||||
fn len_packed(&self) -> usize {
|
||||
let mut length = PUS_TM_MIN_LEN_WITHOUT_SOURCE_DATA;
|
||||
if let Some(timestamp) = self.sec_header.timestamp {
|
||||
length += timestamp.len();
|
||||
}
|
||||
if let Some(src_data) = self.source_data {
|
||||
length += src_data.len();
|
||||
}
|
||||
length
|
||||
}
|
||||
/// Write the raw PUS byte representation to a provided buffer.
|
||||
fn write_to_bytes(&self, slice: &mut [u8]) -> Result<usize, PusError> {
|
||||
let mut curr_idx = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user