Skip to content

Commit 13d87ea

Browse files
committed
add defmt support
1 parent abaf2ae commit 13d87ea

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ readme = "README.md"
1212
categories = ["embedded", "network-programming", "no-std"]
1313
keywords = ["WPAN"]
1414

15+
[features]
16+
1517

1618
[badges]
1719
travis-ci = { repository = "braun-robotics/ieee802154" }
@@ -21,3 +23,4 @@ travis-ci = { repository = "braun-robotics/ieee802154" }
2123
byteorder = { version = "1", default-features = false }
2224
hash32 = "0.1"
2325
hash32-derive = "0.1"
26+
defmt = { version = "0.2.1", optional = true }

src/mac/beacon.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::mac::{DecodeError, ExtendedAddress, ShortAddress};
99

1010
/// Beacon order is used to calculate the beacon interval
1111
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
12+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1213
pub enum BeaconOrder {
1314
/// Used to calculate at which interval beacons are sent
1415
///
@@ -40,6 +41,7 @@ impl From<BeaconOrder> for u8 {
4041

4142
/// Superframe order, amount of time during wich this superframe is active
4243
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
44+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
4345
pub enum SuperframeOrder {
4446
/// Ammount of time that the superframe is active
4547
///
@@ -74,6 +76,7 @@ impl From<SuperframeOrder> for u8 {
7476
/// The superframe specification describes the organisation of frames in the
7577
/// air when using superframes and/or periodical beacons.
7678
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
79+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
7780
pub struct SuperframeSpecification {
7881
/// Beacon order, 0-15, where 15 is on demand.
7982
///
@@ -170,6 +173,7 @@ impl SuperframeSpecification {
170173

171174
/// Direction of data
172175
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
176+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
173177
enum Direction {
174178
/// Receive data
175179
Receive,
@@ -179,6 +183,7 @@ enum Direction {
179183

180184
/// Descriptor of the guaranteed time slots (GTSs)
181185
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
186+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
182187
pub struct GuaranteedTimeSlotDescriptor {
183188
/// Device short address used by this slot
184189
short_address: ShortAddress,
@@ -266,6 +271,7 @@ const PERMIT: u8 = 0b1000_0000;
266271

267272
/// Information of the guaranteed time slots (GTSs)
268273
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
274+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
269275
pub struct GuaranteedTimeSlotInformation {
270276
/// Permit GTS
271277
pub permit: bool,
@@ -395,6 +401,7 @@ const EXTENDED_MASK: u8 = 0b0111_0000;
395401
/// ```
396402
///
397403
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
404+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
398405
pub struct PendingAddress {
399406
short_address_count: usize,
400407
short_addresses: [ShortAddress; 7],
@@ -504,6 +511,7 @@ impl PendingAddress {
504511
}
505512
/// Beacon frame
506513
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
514+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
507515
pub struct Beacon {
508516
/// Superframe specification
509517
pub superframe_spec: SuperframeSpecification,

src/mac/command.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const CAP_ALLOCATE_ADDRESS: u8 = 0x80;
3838
///
3939
/// Sent with association request to report the capabilities of the device.
4040
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
41+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
4142
pub struct CapabilityInformation {
4243
/// Full-function device (FFD) or a reduced-function device (RFD)
4344
/// RFD and FFD have different function sets.
@@ -119,6 +120,7 @@ extended_enum!(
119120
///
120121
/// Changes to the PAN sent by the coordinator.
121122
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
123+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
122124
pub struct CoordinatorRealignmentData {
123125
/// PAN id that the coordinator will use
124126
pub pan_id: PanId,
@@ -211,6 +213,7 @@ const GTSC_ALLOCATION: u8 = 0x20;
211213
///
212214
/// GTS configuration requested with the guaranteed time slot request command.
213215
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
216+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
214217
pub struct GuaranteedTimeSlotCharacteristics {
215218
/// Number of slots requested
216219
pub count: u8,
@@ -247,6 +250,7 @@ impl From<GuaranteedTimeSlotCharacteristics> for u8 {
247250

248251
/// MAC commands
249252
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
253+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
250254
pub enum Command {
251255
/// Association request, request association to a PAN
252256
AssociationRequest(CapabilityInformation),

src/mac/frame.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::mac::command::Command;
2525
/// [decode]: #method.decode
2626
/// [encode]: #method.encode
2727
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
28+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
2829
pub struct Frame<'p> {
2930
/// Header
3031
pub header: Header,
@@ -225,6 +226,7 @@ pub enum WriteFooter {
225226

226227
/// MAC frame header
227228
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
229+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
228230
pub struct Header {
229231
/// Frame Type
230232
pub frame_type: FrameType,
@@ -485,6 +487,7 @@ impl Header {
485487
///
486488
/// Part of [`Header`].
487489
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
490+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
488491
pub enum FrameType {
489492
/// Beacon
490493
Beacon = 0b000,
@@ -538,6 +541,7 @@ impl FrameType {
538541
/// Part of [`Header`]. Auxiliary security headers are currently unsupported by
539542
/// this implementation.
540543
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
544+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
541545
pub enum Security {
542546
/// No auxiliary security header is present
543547
None = 0b0,
@@ -567,6 +571,7 @@ impl Security {
567571

568572
/// Defines version information for a frame
569573
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
574+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
570575
pub enum FrameVersion {
571576
/// A frame conforming to the 802.15.4-2003 standard
572577
Ieee802154_2003 = 0b00,
@@ -602,6 +607,7 @@ impl FrameVersion {
602607

603608
/// Defines the type of Address
604609
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
610+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
605611
pub enum AddressMode {
606612
/// PAN identifier and address field are not present
607613
None = 0b00,
@@ -647,6 +653,7 @@ impl AddressMode {
647653
/// let pan_id = PanId(0x0123);
648654
/// ```
649655
#[derive(Clone, Copy, Debug, Eq, Hash, Hash32, PartialEq)]
656+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
650657
pub struct PanId(pub u16);
651658

652659
impl PanId {
@@ -732,6 +739,7 @@ impl PanId {
732739
/// let short_address = ShortAddress(0x0123);
733740
/// ```
734741
#[derive(Clone, Copy, Debug, Eq, Hash, Hash32, PartialEq)]
742+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
735743
pub struct ShortAddress(pub u16);
736744

737745
impl ShortAddress {
@@ -822,6 +830,7 @@ impl ShortAddress {
822830
/// let ext_address = ExtendedAddress(0x0123456789abcdef);
823831
/// ```
824832
#[derive(Clone, Copy, Debug, Eq, Hash, Hash32, PartialEq)]
833+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
825834
pub struct ExtendedAddress(pub u64);
826835

827836
impl ExtendedAddress {
@@ -851,6 +860,7 @@ impl ExtendedAddress {
851860

852861
/// An address that might contain an PAN ID and address
853862
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
863+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
854864
pub enum Address {
855865
/// No address
856866
None,
@@ -964,6 +974,7 @@ impl Address {
964974

965975
/// Content of a frame
966976
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
977+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
967978
pub enum FrameContent
968979
{
969980
/// Beacon frame content
@@ -1017,6 +1028,7 @@ impl FrameContent {
10171028

10181029
/// Signals an error that occured while decoding bytes
10191030
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
1031+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
10201032
pub enum DecodeError {
10211033
/// Buffer does not contain enough bytes
10221034
NotEnoughBytes,

src/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ macro_rules! extended_enum {
1515

1616
$(#[$outer])*
1717
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
18+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1819
pub enum $name {
1920
$(
2021
$(#[$inner])*

0 commit comments

Comments
 (0)