Compare commits
7 Commits
38b789ca6d
...
v0.3.0
Author | SHA1 | Date | |
---|---|---|---|
85bfcad111 | |||
03d112cbef | |||
1ec21c1bff | |||
c750f94fba | |||
1d6cf3a75d | |||
f8199ca87a | |||
4c1101f65f |
12
CHANGELOG.md
12
CHANGELOG.md
@ -8,6 +8,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
# [unreleased]
|
||||
|
||||
# [v0.3.0] 01.12.2022
|
||||
|
||||
## Added
|
||||
|
||||
- `EcssEnumerationExt` trait which implements `Debug`, `Copy`, `Clone`,
|
||||
`PartialEq` and `Eq` in addition to `EcssEnumeration`
|
||||
|
||||
## Changed
|
||||
|
||||
- `EcssEnumeration` trait: Rename `write_to_bytes`
|
||||
to `write_to_be_bytes`
|
||||
|
||||
# [v0.2.0] 13.09.2022
|
||||
|
||||
## Added
|
||||
|
14
Cargo.toml
14
Cargo.toml
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "spacepackets"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
edition = "2021"
|
||||
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
|
||||
description = "Generic implementations for various CCSDS and ECSS packet standards"
|
||||
@ -12,17 +12,17 @@ categories = ["aerospace", "aerospace::space-protocols", "no-std", "hardware-sup
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
zerocopy = "0.6.1"
|
||||
crc = "3.0.0"
|
||||
delegate = "0.7.0"
|
||||
zerocopy = "0.6"
|
||||
crc = "3.0"
|
||||
delegate = "0.8"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0.142"
|
||||
version = "1.0"
|
||||
default-features = false
|
||||
features = ["derive"]
|
||||
|
||||
[dependencies.chrono]
|
||||
version = "0.4.20"
|
||||
version = "0.4"
|
||||
default-features = false
|
||||
|
||||
[dependencies.num-traits]
|
||||
@ -30,7 +30,7 @@ version = "0.2"
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies.postcard]
|
||||
version = "1.0.1"
|
||||
version = "1.0"
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
|
14
src/ecss.rs
14
src/ecss.rs
@ -169,7 +169,7 @@ pub trait EcssEnumeration {
|
||||
fn byte_width(&self) -> usize {
|
||||
(self.pfc() / 8) as usize
|
||||
}
|
||||
fn write_to_bytes(&self, buf: &mut [u8]) -> Result<(), ByteConversionError>;
|
||||
fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<(), ByteConversionError>;
|
||||
}
|
||||
|
||||
pub trait EcssEnumerationExt: EcssEnumeration + Debug + Copy + Clone + PartialEq + Eq {}
|
||||
@ -231,7 +231,7 @@ impl<TYPE: ToBeBytes> EcssEnumeration for GenericEcssEnumWrapper<TYPE> {
|
||||
size_of::<TYPE>() as u8 * 8_u8
|
||||
}
|
||||
|
||||
fn write_to_bytes(&self, buf: &mut [u8]) -> Result<(), ByteConversionError> {
|
||||
fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<(), ByteConversionError> {
|
||||
if buf.len() < self.byte_width() as usize {
|
||||
return Err(ByteConversionError::ToSliceTooSmall(SizeMissmatch {
|
||||
found: buf.len(),
|
||||
@ -263,7 +263,7 @@ mod tests {
|
||||
let mut buf = [0, 0, 0];
|
||||
let my_enum = EcssEnumU8::new(1);
|
||||
my_enum
|
||||
.write_to_bytes(&mut buf[1..2])
|
||||
.write_to_be_bytes(&mut buf[1..2])
|
||||
.expect("To byte conversion of u8 failed");
|
||||
assert_eq!(buf[1], 1);
|
||||
}
|
||||
@ -273,7 +273,7 @@ mod tests {
|
||||
let mut buf = [0, 0, 0];
|
||||
let my_enum = EcssEnumU16::new(0x1f2f);
|
||||
my_enum
|
||||
.write_to_bytes(&mut buf[1..3])
|
||||
.write_to_be_bytes(&mut buf[1..3])
|
||||
.expect("To byte conversion of u8 failed");
|
||||
assert_eq!(buf[1], 0x1f);
|
||||
assert_eq!(buf[2], 0x2f);
|
||||
@ -283,7 +283,7 @@ mod tests {
|
||||
fn test_slice_u16_too_small() {
|
||||
let mut buf = [0];
|
||||
let my_enum = EcssEnumU16::new(0x1f2f);
|
||||
let res = my_enum.write_to_bytes(&mut buf[0..1]);
|
||||
let res = my_enum.write_to_be_bytes(&mut buf[0..1]);
|
||||
assert!(res.is_err());
|
||||
let error = res.unwrap_err();
|
||||
match error {
|
||||
@ -302,7 +302,7 @@ mod tests {
|
||||
let mut buf = [0, 0, 0, 0, 0];
|
||||
let my_enum = EcssEnumU32::new(0x1f2f3f4f);
|
||||
my_enum
|
||||
.write_to_bytes(&mut buf[1..5])
|
||||
.write_to_be_bytes(&mut buf[1..5])
|
||||
.expect("To byte conversion of u8 failed");
|
||||
assert_eq!(buf[1], 0x1f);
|
||||
assert_eq!(buf[2], 0x2f);
|
||||
@ -314,7 +314,7 @@ mod tests {
|
||||
fn test_slice_u32_too_small() {
|
||||
let mut buf = [0, 0, 0, 0, 0];
|
||||
let my_enum = EcssEnumU32::new(0x1f2f3f4f);
|
||||
let res = my_enum.write_to_bytes(&mut buf[0..3]);
|
||||
let res = my_enum.write_to_be_bytes(&mut buf[0..3]);
|
||||
assert!(res.is_err());
|
||||
let error = res.unwrap_err();
|
||||
match error {
|
||||
|
@ -68,9 +68,9 @@ pub struct SizeMissmatch {
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum ByteConversionError {
|
||||
/// The passed slice is too small. Returns the found and expected minimum size
|
||||
/// The passed slice is too small. Returns the passed slice length and expected minimum size
|
||||
ToSliceTooSmall(SizeMissmatch),
|
||||
/// The provider buffer it soo small. Returns the found and expected minimum size
|
||||
/// The provider buffer is too small. Returns the passed slice length and expected minimum size
|
||||
FromSliceTooSmall(SizeMissmatch),
|
||||
/// The [zerocopy] library failed to write to bytes
|
||||
ZeroCopyToError,
|
||||
|
17
src/time.rs
17
src/time.rs
@ -1,6 +1,6 @@
|
||||
//! CCSDS Time Code Formats according to [CCSDS 301.0-B-4](https://public.ccsds.org/Pubs/301x0b4e1.pdf)
|
||||
use crate::{ByteConversionError, SizeMissmatch};
|
||||
use chrono::{DateTime, TimeZone, Utc};
|
||||
use chrono::{DateTime, LocalResult, TimeZone, Utc};
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(not(feature = "std"))]
|
||||
@ -23,6 +23,8 @@ pub enum CcsdsTimeCodes {
|
||||
Ccs = 0b101,
|
||||
}
|
||||
|
||||
const CDS_SHORT_P_FIELD: u8 = (CcsdsTimeCodes::Cds as u8) << 4;
|
||||
|
||||
impl TryFrom<u8> for CcsdsTimeCodes {
|
||||
type Error = ();
|
||||
|
||||
@ -112,7 +114,6 @@ pub trait CcsdsTimeProvider {
|
||||
/// ```
|
||||
#[derive(Debug, Copy, Clone, Default)]
|
||||
pub struct CdsShortTimeProvider {
|
||||
pfield: u8,
|
||||
ccsds_days: u16,
|
||||
ms_of_day: u32,
|
||||
unix_seconds: i64,
|
||||
@ -122,7 +123,6 @@ pub struct CdsShortTimeProvider {
|
||||
impl CdsShortTimeProvider {
|
||||
pub fn new(ccsds_days: u16, ms_of_day: u32) -> Self {
|
||||
let provider = Self {
|
||||
pfield: (Cds as u8) << 4,
|
||||
ccsds_days,
|
||||
ms_of_day,
|
||||
unix_seconds: 0,
|
||||
@ -142,7 +142,6 @@ impl CdsShortTimeProvider {
|
||||
let unix_days_seconds = epoch - secs_of_day;
|
||||
let ms_of_day = secs_of_day * 1000 + now.subsec_millis() as u64;
|
||||
let provider = Self {
|
||||
pfield: (Cds as u8) << 4,
|
||||
ccsds_days: unix_to_ccsds_days((unix_days_seconds / SECONDS_PER_DAY as u64) as i32)
|
||||
as u16,
|
||||
ms_of_day: ms_of_day as u32,
|
||||
@ -197,7 +196,11 @@ impl CdsShortTimeProvider {
|
||||
fn calc_date_time(&mut self, ms_since_last_second: u32) {
|
||||
assert!(ms_since_last_second < 1000, "Invalid MS since last second");
|
||||
let ns_since_last_sec = ms_since_last_second * 1e6 as u32;
|
||||
self.date_time = Some(Utc.timestamp(self.unix_seconds, ns_since_last_sec));
|
||||
if let LocalResult::Single(val) = Utc.timestamp_opt(self.unix_seconds, ns_since_last_sec) {
|
||||
self.date_time = Some(val);
|
||||
} else {
|
||||
self.date_time = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,7 +210,7 @@ impl CcsdsTimeProvider for CdsShortTimeProvider {
|
||||
}
|
||||
|
||||
fn p_field(&self) -> (usize, [u8; 2]) {
|
||||
(1, [self.pfield, 0])
|
||||
(1, [CDS_SHORT_P_FIELD, 0])
|
||||
}
|
||||
|
||||
fn ccdsd_time_code(&self) -> CcsdsTimeCodes {
|
||||
@ -233,7 +236,7 @@ impl TimeWriter for CdsShortTimeProvider {
|
||||
}),
|
||||
));
|
||||
}
|
||||
buf[0] = self.pfield;
|
||||
buf[0] = CDS_SHORT_P_FIELD;
|
||||
buf[1..3].copy_from_slice(self.ccsds_days.to_be_bytes().as_slice());
|
||||
buf[3..7].copy_from_slice(self.ms_of_day.to_be_bytes().as_slice());
|
||||
Ok(())
|
||||
|
Reference in New Issue
Block a user