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