invalid time code struct variant #26
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
variants now. `SizeMissmatch` was removed appropriately.
|
variants now. `SizeMissmatch` was removed appropriately.
|
||||||
- `UnsignedByteFieldError` error variants `ValueTooLargeForWidth` and `InvalidWidth` are struct
|
- `UnsignedByteFieldError` error variants `ValueTooLargeForWidth` and `InvalidWidth` are struct
|
||||||
variants now.
|
variants now.
|
||||||
|
- `TimestampError` error variant `InvalidTimeCode` is struct variant now.
|
||||||
|
|
||||||
## Added
|
## Added
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
@ -1490,9 +1493,9 @@ mod tests {
|
|||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
let err = res.unwrap_err();
|
let err = res.unwrap_err();
|
||||||
match err {
|
match err {
|
||||||
InvalidTimeCode(code, raw) => {
|
InvalidTimeCode { expected, found } => {
|
||||||
assert_eq!(code, CcsdsTimeCodes::Cds);
|
assert_eq!(expected, CcsdsTimeCodes::Cds);
|
||||||
assert_eq!(raw, 0);
|
assert_eq!(found, 0);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -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) =
|
||||||
@ -909,9 +909,9 @@ mod tests {
|
|||||||
let res = TimeProviderCcsdsEpoch::from_bytes(&buf);
|
let res = TimeProviderCcsdsEpoch::from_bytes(&buf);
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
let err = res.unwrap_err();
|
let err = res.unwrap_err();
|
||||||
if let TimestampError::InvalidTimeCode(code, raw) = err {
|
if let TimestampError::InvalidTimeCode { expected, found } = err {
|
||||||
assert_eq!(code, CcsdsTimeCodes::CucCcsdsEpoch);
|
assert_eq!(expected, CcsdsTimeCodes::CucCcsdsEpoch);
|
||||||
assert_eq!(raw, CcsdsTimeCodes::CucAgencyEpoch as u8);
|
assert_eq!(found, CcsdsTimeCodes::CucAgencyEpoch as u8);
|
||||||
} else {
|
} else {
|
||||||
panic!("unexpected error: {}", err);
|
panic!("unexpected error: {}", err);
|
||||||
}
|
}
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user