From 46e2af41d2cfec0d131b0aca9cfd0fc7ec57f0a9 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 18 Dec 2022 16:21:20 +0100 Subject: [PATCH 1/7] PTC and PFC extensions - Add Ptc typedefinition for PacketTypeCode enum - Add `UnsignedPfc` and `RealPfc` PFC enumerations --- src/ecss.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/ecss.rs b/src/ecss.rs index f06b4c7..579c04e 100644 --- a/src/ecss.rs +++ b/src/ecss.rs @@ -55,6 +55,36 @@ pub enum PacketTypeCodes { Packet = 12, } +pub type Ptc = PacketTypeCodes; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum UnsignedPfc { + OneByte = 4, + TwelveBits = 8, + TwoBytes = 12, + ThreeBytes = 13, + FourBytes = 14, + SixBytes = 15, + EightBytes = 16, + OneBit = 17, + TwoBits = 18, + ThreeBits = 19, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum RealPfc { + /// 4 octets simple precision format (IEEE) + Float = 1, + /// 8 octets simple precision format (IEEE) + Double = 2, + /// 4 octets simple precision format (MIL-STD) + FloatMilStd = 3, + /// 8 octets simple precision format (MIL-STD) + DoubleMilStd = 4, +} + #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum PusError { From f964342556f3050e5c8d66442eae161f65736512 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 18 Dec 2022 23:54:13 +0100 Subject: [PATCH 2/7] removed unnecessary casts --- src/ecss.rs | 6 +++--- src/time.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ecss.rs b/src/ecss.rs index 579c04e..93009ce 100644 --- a/src/ecss.rs +++ b/src/ecss.rs @@ -308,13 +308,13 @@ impl EcssEnumeration for GenericEcssEnumWrapper { } fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<(), ByteConversionError> { - if buf.len() < self.byte_width() as usize { + if buf.len() < self.byte_width() { return Err(ByteConversionError::ToSliceTooSmall(SizeMissmatch { found: buf.len(), - expected: self.byte_width() as usize, + expected: self.byte_width(), })); } - buf[0..self.byte_width() as usize].copy_from_slice(self.val.to_be_bytes().as_ref()); + buf[0..self.byte_width()].copy_from_slice(self.val.to_be_bytes().as_ref()); Ok(()) } } diff --git a/src/time.rs b/src/time.rs index 45277bc..907f9c3 100644 --- a/src/time.rs +++ b/src/time.rs @@ -134,7 +134,7 @@ impl CdsShortTimeProvider { }; let unix_days_seconds = ccsds_to_unix_days(ccsds_days as i32) as i64 * SECONDS_PER_DAY as i64; - provider.setup(unix_days_seconds as i64, ms_of_day.into()) + provider.setup(unix_days_seconds, ms_of_day.into()) } #[cfg(feature = "std")] @@ -223,7 +223,7 @@ impl CcsdsTimeProvider for CdsShortTimeProvider { } fn date_time(&self) -> Option> { - self.calc_date_time((self.ms_of_day % 1000) as u32) + self.calc_date_time(self.ms_of_day % 1000) } } From fbeea41e8f814fef9505a7e1a5b4035e68100ea5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Dec 2022 11:00:45 +0100 Subject: [PATCH 3/7] fix in Cargo.toml file --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 22eabe0..0004f8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,9 +35,9 @@ default-features = false version = "1.0" [features] -default = ["std", "dep:serde"] +default = ["std"] std = ["chrono/std", "chrono/clock", "alloc"] -serde = ["chrono/serde"] +serde = ["dep:serde", "chrono/serde"] alloc = ["postcard/alloc", "chrono/alloc"] [package.metadata.docs.rs] From 976fe9c49b101459ae305dbeb95a8108746b9a05 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Dec 2022 11:02:36 +0100 Subject: [PATCH 4/7] README updates --- README.md | 5 ++++- src/lib.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ed4e7e4..1545bf0 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,15 @@ It also offers optional support for [`serde`](https://serde.rs/). This allows se deserializing them with an appropriate `serde` provider like [`postcard`](https://github.com/jamesmunns/postcard). -Default features: +## Default features - [`std`](https://doc.rust-lang.org/std/): Enables functionality relying on the standard library. - [`alloc`](https://doc.rust-lang.org/alloc/): Enables features which operate on containers like [`alloc::vec::Vec`](https://doc.rust-lang.org/beta/alloc/vec/struct.Vec.html). Enabled by the `std` feature. + +## Optional Features + - [`serde`](https://serde.rs/): Adds `serde` support for most types by adding `Serialize` and `Deserialize` `derive`s # Examples diff --git a/src/lib.rs b/src/lib.rs index 6faec44..e26d481 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,12 +22,15 @@ //! deserializing them with an appropriate `serde` provider like //! [`postcard`](https://github.com/jamesmunns/postcard). //! -//! Default features: +//! ### Default features //! //! - [`std`](https://doc.rust-lang.org/std/): Enables functionality relying on the standard library. //! - [`alloc`](https://doc.rust-lang.org/alloc/): Enables features which operate on containers //! like [`alloc::vec::Vec`](https://doc.rust-lang.org/beta/alloc/vec/struct.Vec.html). //! Enabled by the `std` feature. +//! +//! ### Optional features +//! //! - [`serde`](https://serde.rs/): Adds `serde` support for most types by adding `Serialize` and //! `Deserialize` `derive`s //! From fd13694904bec7f96aa303afacbeb58f8351d187 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Dec 2022 16:36:18 +0100 Subject: [PATCH 5/7] add PUS service ID enum --- src/ecss.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ecss.rs b/src/ecss.rs index f06b4c7..9ee3494 100644 --- a/src/ecss.rs +++ b/src/ecss.rs @@ -15,6 +15,16 @@ pub type CrcType = u16; pub const CRC_CCITT_FALSE: Crc = Crc::::new(&CRC_16_IBM_3740); pub const CCSDS_HEADER_LEN: usize = size_of::(); +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum PusServiceId { + Verification = 1, + Housekeeping = 3, + Event = 5, + Action = 8, + Test = 17 +} + /// All PUS versions. Only PUS C is supported by this library. #[derive(PartialEq, Eq, Copy, Clone, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] From 9e57ce38722b6f4a6808c376fa36032c1200196f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Dec 2022 17:02:19 +0100 Subject: [PATCH 6/7] cargo fmt --- src/ecss.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecss.rs b/src/ecss.rs index 9ee3494..c3560db 100644 --- a/src/ecss.rs +++ b/src/ecss.rs @@ -22,7 +22,7 @@ pub enum PusServiceId { Housekeeping = 3, Event = 5, Action = 8, - Test = 17 + Test = 17, } /// All PUS versions. Only PUS C is supported by this library. From 4410ee7eecf7fa860fbb8e5a78de213a058ff34f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 20 Dec 2022 16:21:30 +0100 Subject: [PATCH 7/7] bump changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a86827..e3c9487 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Added +- Added PFC enumerations: `ecss::UnsignedPfc` and `ecss::RealPfc`. + PR: https://egit.irs.uni-stuttgart.de/rust/spacepackets/pulls/5 - Added `std::error::Error` implementation for all error enumerations if the `std` feature is enabled. - ACII timestamps as specified in CCSDS 301.0-B-4.