From 3045a27d8c927690495819b392d0b3c62370caf0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Mar 2024 13:42:02 +0100 Subject: [PATCH] just add support for everything --- CHANGELOG.md | 1 + Cargo.toml | 2 +- README.md | 2 ++ src/cfdp/lv.rs | 1 + src/cfdp/mod.rs | 12 ++++++++++++ src/cfdp/pdu/ack.rs | 1 + src/cfdp/pdu/eof.rs | 1 + src/cfdp/pdu/finished.rs | 4 ++++ src/cfdp/pdu/metadata.rs | 3 +++ src/cfdp/pdu/mod.rs | 3 +++ src/cfdp/pdu/nak.rs | 3 +++ src/cfdp/tlv/mod.rs | 7 +++++++ src/ecss/hk.rs | 1 + src/ecss/mod.rs | 3 ++- src/ecss/tc.rs | 4 ++++ src/ecss/tm.rs | 3 +++ src/lib.rs | 10 ++++++++-- src/time/cds.rs | 2 ++ src/time/cuc.rs | 2 ++ src/time/mod.rs | 4 ++++ src/util.rs | 2 ++ 21 files changed, 67 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2ef33a..582deb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ to check all the API changes in the **Changed** chapter. - Added basic support conversions to the `time` library. Introduce new `chrono` and `timelib` feature gate. - Added `CcsdsTimeProvider::timelib_date_time`. +- Optional support for `defmt` by adding optional `defmt::Format` derives for common types. ## Changed diff --git a/Cargo.toml b/Cargo.toml index d01ea30..ee3fa20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,7 @@ serde = ["dep:serde", "chrono/serde"] alloc = ["postcard/alloc", "chrono/alloc"] chrono = ["dep:chrono"] timelib = ["dep:time"] -defmt = [] +defmt = ["dep:defmt"] [package.metadata.docs.rs] all-features = true diff --git a/README.md b/README.md index c136b6a..3a0d31e 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ deserializing them with an appropriate `serde` provider like - [`serde`](https://serde.rs/): Adds `serde` support for most types by adding `Serialize` and `Deserialize` `derive`s - [`chrono`](https://crates.io/crates/chrono): Add basic support for the `chrono` time library. - [`timelib`](https://crates.io/crates/time): Add basic support for the `time` time library. + - [`defmt`](https://defmt.ferrous-systems.com/): Add support for the `defmt` by adding the + `defmt::Format` derive on many objects. # Examples diff --git a/src/cfdp/lv.rs b/src/cfdp/lv.rs index 87d386c..7a8877b 100644 --- a/src/cfdp/lv.rs +++ b/src/cfdp/lv.rs @@ -20,6 +20,7 @@ pub const MIN_LV_LEN: usize = 1; /// this will be the lifetime of that data reference. #[derive(Debug, Copy, Clone, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Lv<'data> { data: &'data [u8], // If the LV was generated from a raw bytestream, this will contain the start of the diff --git a/src/cfdp/mod.rs b/src/cfdp/mod.rs index 33ee333..aa9da8a 100644 --- a/src/cfdp/mod.rs +++ b/src/cfdp/mod.rs @@ -18,6 +18,7 @@ pub const CFDP_VERSION_2: u8 = 0b001; #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum PduType { FileDirective = 0, @@ -26,6 +27,7 @@ pub enum PduType { #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum Direction { TowardsReceiver = 0, @@ -34,6 +36,7 @@ pub enum Direction { #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum TransmissionMode { Acknowledged = 0, @@ -42,6 +45,7 @@ pub enum TransmissionMode { #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum CrcFlag { NoCrc = 0, @@ -69,6 +73,7 @@ impl From for bool { /// Always 0 and ignored for File Directive PDUs (CCSDS 727.0-B-5 P.75) #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum SegmentMetadataFlag { NotPresent = 0, @@ -78,6 +83,7 @@ pub enum SegmentMetadataFlag { /// Always 0 and ignored for File Directive PDUs (CCSDS 727.0-B-5 P.75) #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum SegmentationControl { NoRecordBoundaryPreservation = 0, @@ -86,6 +92,7 @@ pub enum SegmentationControl { #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum FaultHandlerCode { NoticeOfCancellation = 0b0001, @@ -96,6 +103,7 @@ pub enum FaultHandlerCode { #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum ConditionCode { /// This is not an error condition for which a faulty handler override can be specified @@ -118,6 +126,7 @@ pub enum ConditionCode { #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum LargeFileFlag { /// 32 bit maximum file size and FSS size @@ -129,6 +138,7 @@ pub enum LargeFileFlag { /// Transaction status for the ACK PDU field according to chapter 5.2.4 of the CFDP standard. #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum TransactionStatus { /// Transaction is not currently active and the CFDP implementation does not retain a @@ -146,6 +156,7 @@ pub enum TransactionStatus { /// [SANA Checksum Types registry](https://sanaregistry.org/r/checksum_identifiers/) #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum ChecksumType { /// Modular legacy checksum @@ -167,6 +178,7 @@ pub const NULL_CHECKSUM_U32: [u8; 4] = [0; 4]; #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum TlvLvError { DataTooLarge(usize), ByteConversion(ByteConversionError), diff --git a/src/cfdp/pdu/ack.rs b/src/cfdp/pdu/ack.rs index 997f40b..8d82375 100644 --- a/src/cfdp/pdu/ack.rs +++ b/src/cfdp/pdu/ack.rs @@ -15,6 +15,7 @@ use serde::{Deserialize, Serialize}; /// For more information, refer to CFDP chapter 5.2.4. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct AckPdu { pdu_header: PduHeader, directive_code_of_acked_pdu: FileDirectiveType, diff --git a/src/cfdp/pdu/eof.rs b/src/cfdp/pdu/eof.rs index af30e9c..eae759e 100644 --- a/src/cfdp/pdu/eof.rs +++ b/src/cfdp/pdu/eof.rs @@ -15,6 +15,7 @@ use super::{CfdpPdu, WritablePduPacket}; /// For more information, refer to CFDP chapter 5.2.2. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct EofPdu { pdu_header: PduHeader, condition_code: ConditionCode, diff --git a/src/cfdp/pdu/finished.rs b/src/cfdp/pdu/finished.rs index 6dd1d0a..ec0124f 100644 --- a/src/cfdp/pdu/finished.rs +++ b/src/cfdp/pdu/finished.rs @@ -14,6 +14,7 @@ use super::{CfdpPdu, WritablePduPacket}; #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum DeliveryCode { Complete = 0, @@ -22,6 +23,7 @@ pub enum DeliveryCode { #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum FileStatus { DiscardDeliberately = 0b00, @@ -34,6 +36,7 @@ pub enum FileStatus { /// /// For more information, refer to CFDP chapter 5.2.3. #[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct FinishedPduCreator<'fs_responses> { pdu_header: PduHeader, condition_code: ConditionCode, @@ -219,6 +222,7 @@ impl<'buf> Iterator for FilestoreResponseIterator<'buf> { #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct FinishedPduReader<'buf> { pdu_header: PduHeader, condition_code: ConditionCode, diff --git a/src/cfdp/pdu/metadata.rs b/src/cfdp/pdu/metadata.rs index 24eb945..4f8ab4d 100644 --- a/src/cfdp/pdu/metadata.rs +++ b/src/cfdp/pdu/metadata.rs @@ -15,6 +15,7 @@ use super::{CfdpPdu, WritablePduPacket}; #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct MetadataGenericParams { pub closure_requested: bool, pub checksum_type: ChecksumType, @@ -55,6 +56,7 @@ pub fn build_metadata_opts_from_vec( /// This abstraction exposes a specialized API for creating metadata PDUs as specified in /// CFDP chapter 5.2.5. #[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct MetadataPduCreator<'src_name, 'dest_name, 'opts> { pdu_header: PduHeader, metadata_params: MetadataGenericParams, @@ -241,6 +243,7 @@ impl<'opts> Iterator for OptionsIter<'opts> { /// involved. #[derive(Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct MetadataPduReader<'buf> { pdu_header: PduHeader, metadata_params: MetadataGenericParams, diff --git a/src/cfdp/pdu/mod.rs b/src/cfdp/pdu/mod.rs index 2fb8516..1ff73a8 100644 --- a/src/cfdp/pdu/mod.rs +++ b/src/cfdp/pdu/mod.rs @@ -18,6 +18,7 @@ pub mod nak; #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum FileDirectiveType { EofPdu = 0x04, @@ -220,6 +221,7 @@ pub trait CfdpPdu { /// same. #[derive(Debug, Copy, Clone, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct CommonPduConfig { source_entity_id: UnsignedByteField, dest_entity_id: UnsignedByteField, @@ -358,6 +360,7 @@ pub const FIXED_HEADER_LEN: usize = 4; /// For detailed information, refer to chapter 5.1 of the CFDP standard. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct PduHeader { pdu_type: PduType, pdu_conf: CommonPduConfig, diff --git a/src/cfdp/pdu/nak.rs b/src/cfdp/pdu/nak.rs index 3a7a38a..472e80e 100644 --- a/src/cfdp/pdu/nak.rs +++ b/src/cfdp/pdu/nak.rs @@ -12,6 +12,7 @@ use super::{ /// Helper type to encapsulate both normal file size segment requests and large file size segment /// requests. #[derive(Debug, PartialEq, Eq, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum SegmentRequests<'a> { U32Pairs(&'a [(u32, u32)]), U64Pairs(&'a [(u64, u64)]), @@ -31,6 +32,7 @@ impl SegmentRequests<'_> { /// It exposes a specialized API which simplifies to generate these NAK PDUs with the /// format according to CFDP chapter 5.2.6. #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct NakPduCreator<'seg_reqs> { pdu_header: PduHeader, start_of_scope: u64, @@ -353,6 +355,7 @@ impl SegmentRequestIter<'_, T> { /// /// The NAK format is expected to be conforming to CFDP chapter 5.2.6. #[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct NakPduReader<'seg_reqs> { pdu_header: PduHeader, start_of_scope: u64, diff --git a/src/cfdp/tlv/mod.rs b/src/cfdp/tlv/mod.rs index 685098d..b71927d 100644 --- a/src/cfdp/tlv/mod.rs +++ b/src/cfdp/tlv/mod.rs @@ -52,6 +52,7 @@ pub trait WritableTlv { #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum TlvType { FilestoreRequest = 0x00, @@ -64,6 +65,7 @@ pub enum TlvType { #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum TlvTypeField { Standard(TlvType), Custom(u8), @@ -71,6 +73,7 @@ pub enum TlvTypeField { #[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum FilestoreActionCode { CreateFile = 0b0000, @@ -118,6 +121,7 @@ impl From for u8 { /// this will be the lifetime of that data reference. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Tlv<'data> { tlv_type_field: TlvTypeField, #[cfg_attr(feature = "serde", serde(borrow))] @@ -224,6 +228,7 @@ pub(crate) fn verify_tlv_type(raw_type: u8, expected_tlv_type: TlvType) -> Resul #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct EntityIdTlv { entity_id: UnsignedByteField, } @@ -348,6 +353,7 @@ pub fn fs_request_has_second_filename(action_code: FilestoreActionCode) -> bool #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] struct FilestoreTlvBase<'first_name, 'second_name> { pub action_code: FilestoreActionCode, #[cfg_attr(feature = "serde", serde(borrow))] @@ -561,6 +567,7 @@ impl GenericTlv for FilestoreRequestTlv<'_, '_> { #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct FilestoreResponseTlv<'first_name, 'second_name, 'fs_msg> { #[cfg_attr(feature = "serde", serde(borrow))] base: FilestoreTlvBase<'first_name, 'second_name>, diff --git a/src/ecss/hk.rs b/src/ecss/hk.rs index 5af3547..7a788f3 100644 --- a/src/ecss/hk.rs +++ b/src/ecss/hk.rs @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Eq, PartialEq, Copy, Clone, IntoPrimitive, TryFromPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub enum Subservice { // Regular HK diff --git a/src/ecss/mod.rs b/src/ecss/mod.rs index e078cdb..a46adcc 100644 --- a/src/ecss/mod.rs +++ b/src/ecss/mod.rs @@ -74,6 +74,7 @@ pub enum PusServiceId { /// All PUS versions. Only PUS C is supported by this library. #[derive(PartialEq, Eq, Copy, Clone, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] pub enum PusVersion { EsaPus = 0, @@ -150,7 +151,7 @@ pub enum PfcReal { #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature="defmt", derive(defmt::Format))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum PusError { VersionNotSupported(PusVersion), ChecksumFailure(u16), diff --git a/src/ecss/tc.rs b/src/ecss/tc.rs index 791ae3f..54f15f7 100644 --- a/src/ecss/tc.rs +++ b/src/ecss/tc.rs @@ -61,6 +61,7 @@ pub trait IsPusTelecommand {} #[derive(Debug, Eq, PartialEq, Copy, Clone, IntoPrimitive, TryFromPrimitive)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] enum AckOpts { Acceptance = 0b1000, @@ -146,6 +147,7 @@ pub mod zc { #[derive(PartialEq, Eq, Copy, Clone, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct PusTcSecondaryHeader { pub service: u8, pub subservice: u8, @@ -548,6 +550,7 @@ pub mod legacy_tc { /// There is no spare bytes support yet. #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct PusTcCreator<'raw_data> { sp_header: SpHeader, pub sec_header: PusTcSecondaryHeader, @@ -750,6 +753,7 @@ impl IsPusTelecommand for PusTcCreator<'_> {} /// * `'raw_data` - Lifetime of the provided raw slice. #[derive(Eq, Copy, Clone, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct PusTcReader<'raw_data> { #[cfg_attr(feature = "serde", serde(skip))] raw_data: &'raw_data [u8], diff --git a/src/ecss/tm.rs b/src/ecss/tm.rs index 1639e7b..e5a95eb 100644 --- a/src/ecss/tm.rs +++ b/src/ecss/tm.rs @@ -116,6 +116,7 @@ pub mod zc { #[derive(PartialEq, Eq, Copy, Clone, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct PusTmSecondaryHeader<'stamp> { pus_version: PusVersion, pub sc_time_ref_status: u8, @@ -539,6 +540,7 @@ pub mod legacy_tm { /// * `'raw_data` - This is the lifetime of the user provided time stamp and source data. #[derive(Eq, Debug, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct PusTmCreator<'raw_data> { pub sp_header: SpHeader, pub sec_header: PusTmSecondaryHeader<'raw_data>, @@ -777,6 +779,7 @@ impl IsPusTelemetry for PusTmCreator<'_> {} /// * `'raw_data` - Lifetime of the raw slice this class is constructed from. #[derive(Eq, Debug, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct PusTmReader<'raw_data> { pub sp_header: SpHeader, pub sec_header: PusTmSecondaryHeader<'raw_data>, diff --git a/src/lib.rs b/src/lib.rs index 46d39f5..fd7a130 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,6 +93,7 @@ pub const MAX_SEQ_COUNT: u16 = 2u16.pow(14) - 1; /// Generic error type when converting to and from raw byte slices. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum ByteConversionError { /// The passed slice is too small. Returns the passed slice length and expected minimum size ToSliceTooSmall { @@ -142,6 +143,7 @@ impl Error for ByteConversionError {} /// CCSDS packet type enumeration. #[derive(Debug, PartialEq, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum PacketType { Tm = 0, Tc = 1, @@ -165,6 +167,7 @@ pub fn packet_type_in_raw_packet_id(packet_id: u16) -> PacketType { #[derive(Debug, PartialEq, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum SequenceFlags { ContinuationSegment = 0b00, FirstSegment = 0b01, @@ -192,6 +195,7 @@ impl TryFrom for SequenceFlags { /// of the first two bytes in the CCSDS primary header. #[derive(Debug, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct PacketId { pub ptype: PacketType, pub sec_header_flag: bool, @@ -303,6 +307,7 @@ impl From for PacketId { /// third and the fourth byte in the CCSDS primary header. #[derive(Debug, PartialEq, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct PacketSequenceCtrl { pub seq_flags: SequenceFlags, seq_count: u16, @@ -463,6 +468,7 @@ pub trait CcsdsPrimaryHeader { /// * `data_len` - Data length field occupies the fifth and the sixth byte of the raw header #[derive(Debug, PartialEq, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct SpHeader { pub version: u8, pub packet_id: PacketId, @@ -798,7 +804,7 @@ pub(crate) mod tests { let id_default = PacketId::default(); assert_eq!(id_default.ptype, PacketType::Tm); assert_eq!(id_default.apid, 0x000); - assert_eq!(id_default.sec_header_flag, false); + assert!(!id_default.sec_header_flag); } #[test] @@ -808,7 +814,7 @@ pub(crate) mod tests { let packet_id = packet_id.unwrap(); assert_eq!(packet_id.apid(), 0x1ff); assert_eq!(packet_id.ptype, PacketType::Tc); - assert_eq!(packet_id.sec_header_flag, true); + assert!(packet_id.sec_header_flag); let packet_id_tc = PacketId::tc(true, 0x1ff); assert!(packet_id_tc.is_some()); let packet_id_tc = packet_id_tc.unwrap(); diff --git a/src/time/cds.rs b/src/time/cds.rs index 5074b92..f196b6c 100644 --- a/src/time/cds.rs +++ b/src/time/cds.rs @@ -78,6 +78,7 @@ impl ProvidesDaysLength for DaysLen24Bits { #[derive(Debug, PartialEq, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum LengthOfDaySegment { Short16Bits = 0, Long24Bits = 1, @@ -94,6 +95,7 @@ pub enum SubmillisPrecision { #[derive(Debug, PartialEq, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum CdsError { /// CCSDS days value exceeds maximum allowed size or is negative InvalidCcsdsDays(i64), diff --git a/src/time/cuc.rs b/src/time/cuc.rs index a14aeb3..362a95c 100644 --- a/src/time/cuc.rs +++ b/src/time/cuc.rs @@ -37,6 +37,7 @@ pub const MAX_CUC_LEN_SMALL_PREAMBLE: usize = 8; #[derive(Copy, Clone, PartialEq, Eq, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum FractionalResolution { /// No fractional part, only second resolution Seconds = 0, @@ -105,6 +106,7 @@ pub fn fractional_part_from_subsec_ns(res: FractionalResolution, ns: u64) -> Fra #[derive(Copy, Clone, PartialEq, Eq, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum CucError { InvalidCounterWidth(u8), /// Invalid counter supplied. diff --git a/src/time/mod.rs b/src/time/mod.rs index dc7ef42..88b3c1a 100644 --- a/src/time/mod.rs +++ b/src/time/mod.rs @@ -33,6 +33,7 @@ pub const NANOS_PER_SECOND: u32 = 1_000_000_000; #[derive(Debug, PartialEq, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum CcsdsTimeCode { CucCcsdsEpoch = 0b001, CucAgencyEpoch = 0b010, @@ -65,6 +66,7 @@ pub fn ccsds_time_code_from_p_field(pfield: u8) -> Result { #[derive(Debug, PartialEq, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct DateBeforeCcsdsEpochError(UnixTime); impl Display for DateBeforeCcsdsEpochError { @@ -78,6 +80,7 @@ impl Error for DateBeforeCcsdsEpochError {} #[derive(Debug, PartialEq, Eq, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[non_exhaustive] pub enum TimestampError { InvalidTimeCode { expected: CcsdsTimeCode, found: u8 }, @@ -262,6 +265,7 @@ pub trait CcsdsTimeProvider { /// similarly to other common time formats and libraries. #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct UnixTime { secs: i64, subsec_nanos: u32, diff --git a/src/util.rs b/src/util.rs index 44f15dd..11c66b6 100644 --- a/src/util.rs +++ b/src/util.rs @@ -131,6 +131,7 @@ impl Error for UnsignedByteFieldError {} /// Type erased variant. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct UnsignedByteField { width: usize, value: u64, @@ -220,6 +221,7 @@ impl UnsignedEnum for UnsignedByteField { #[derive(Debug, Copy, Clone, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct GenericUnsignedByteField> { value: TYPE, }