invalid time code struct variant
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
ab65845573
commit
e78f196a42
@ -428,14 +428,17 @@ pub fn get_dyn_time_provider_from_bytes(
|
||||
) -> Result<Box<dyn DynCdsTimeProvider>, TimestampError> {
|
||||
let time_code = ccsds_time_code_from_p_field(buf[0]);
|
||||
if let Err(e) = time_code {
|
||||
return Err(TimestampError::InvalidTimeCode(CcsdsTimeCodes::Cds, e));
|
||||
return Err(TimestampError::InvalidTimeCode {
|
||||
expected: CcsdsTimeCodes::Cds,
|
||||
found: e,
|
||||
});
|
||||
}
|
||||
let time_code = time_code.unwrap();
|
||||
if time_code != CcsdsTimeCodes::Cds {
|
||||
return Err(TimestampError::InvalidTimeCode(
|
||||
CcsdsTimeCodes::Cds,
|
||||
time_code as u8,
|
||||
));
|
||||
return Err(TimestampError::InvalidTimeCode {
|
||||
expected: CcsdsTimeCodes::Cds,
|
||||
found: time_code as u8,
|
||||
});
|
||||
}
|
||||
if length_of_day_segment_from_pfield(buf[0]) == LengthOfDaySegment::Short16Bits {
|
||||
Ok(Box::new(TimeProvider::from_bytes_with_u16_days(buf)?))
|
||||
@ -523,17 +526,17 @@ impl<ProvidesDaysLen: ProvidesDaysLength> TimeProvider<ProvidesDaysLen> {
|
||||
Ok(cds_type) => match cds_type {
|
||||
CcsdsTimeCodes::Cds => (),
|
||||
_ => {
|
||||
return Err(TimestampError::InvalidTimeCode(
|
||||
CcsdsTimeCodes::Cds,
|
||||
cds_type as u8,
|
||||
))
|
||||
return Err(TimestampError::InvalidTimeCode {
|
||||
expected: CcsdsTimeCodes::Cds,
|
||||
found: cds_type as u8,
|
||||
})
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
return Err(TimestampError::InvalidTimeCode(
|
||||
CcsdsTimeCodes::Cds,
|
||||
pfield >> 4 & 0b111,
|
||||
))
|
||||
return Err(TimestampError::InvalidTimeCode {
|
||||
expected: CcsdsTimeCodes::Cds,
|
||||
found: pfield >> 4 & 0b111,
|
||||
});
|
||||
}
|
||||
};
|
||||
if ((pfield >> 3) & 0b1) == 1 {
|
||||
|
@ -463,17 +463,17 @@ impl TimeReader for TimeProviderCcsdsEpoch {
|
||||
match ccsds_time_code_from_p_field(buf[0]) {
|
||||
Ok(code) => {
|
||||
if code != CcsdsTimeCodes::CucCcsdsEpoch {
|
||||
return Err(TimestampError::InvalidTimeCode(
|
||||
CcsdsTimeCodes::CucCcsdsEpoch,
|
||||
code as u8,
|
||||
));
|
||||
return Err(TimestampError::InvalidTimeCode {
|
||||
expected: CcsdsTimeCodes::CucCcsdsEpoch,
|
||||
found: code as u8,
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(raw) => {
|
||||
return Err(TimestampError::InvalidTimeCode(
|
||||
CcsdsTimeCodes::CucCcsdsEpoch,
|
||||
raw,
|
||||
))
|
||||
return Err(TimestampError::InvalidTimeCode {
|
||||
expected: CcsdsTimeCodes::CucCcsdsEpoch,
|
||||
found: raw,
|
||||
});
|
||||
}
|
||||
}
|
||||
let (cntr_len, fractions_len, total_len) =
|
||||
|
@ -5,6 +5,7 @@ use core::cmp::Ordering;
|
||||
use core::fmt::{Display, Formatter};
|
||||
use core::ops::{Add, AddAssign};
|
||||
use core::time::Duration;
|
||||
use core::u8;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(not(feature = "std"))]
|
||||
@ -63,9 +64,7 @@ pub fn ccsds_time_code_from_p_field(pfield: u8) -> Result<CcsdsTimeCodes, u8> {
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[non_exhaustive]
|
||||
pub enum TimestampError {
|
||||
/// Contains tuple where first value is the expected time code and the second
|
||||
/// value is the found raw value
|
||||
InvalidTimeCode(CcsdsTimeCodes, u8),
|
||||
InvalidTimeCode { expected: CcsdsTimeCodes, found: u8 },
|
||||
ByteConversion(ByteConversionError),
|
||||
Cds(cds::CdsError),
|
||||
Cuc(cuc::CucError),
|
||||
@ -76,10 +75,10 @@ pub enum TimestampError {
|
||||
impl Display for TimestampError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
TimestampError::InvalidTimeCode(time_code, raw_val) => {
|
||||
TimestampError::InvalidTimeCode { expected, found } => {
|
||||
write!(
|
||||
f,
|
||||
"invalid raw time code value {raw_val} for time code {time_code:?}"
|
||||
"invalid raw time code value {found} for time code {expected:?}"
|
||||
)
|
||||
}
|
||||
TimestampError::Cds(e) => {
|
||||
|
Loading…
Reference in New Issue
Block a user