wpan: impl. debug for structs

This commit is contained in:
xoviat 2023-07-20 19:52:36 -05:00
parent 83ff626c47
commit c80c232a72
4 changed files with 50 additions and 8 deletions

View File

@ -23,6 +23,7 @@ pub(crate) trait ParseableMacEvent: Sized {
} }
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug)]
pub enum MacEvent<'a> { pub enum MacEvent<'a> {
MlmeAssociateCnf(&'a AssociateConfirm), MlmeAssociateCnf(&'a AssociateConfirm),
MlmeDisassociateCnf(&'a DisassociateConfirm), MlmeDisassociateCnf(&'a DisassociateConfirm),

View File

@ -10,6 +10,7 @@ use super::typedefs::{
/// MLME ASSOCIATE Indication which will be used by the MAC /// MLME ASSOCIATE Indication which will be used by the MAC
/// to indicate the reception of an association request command /// to indicate the reception of an association request command
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct AssociateIndication { pub struct AssociateIndication {
/// Extended address of the device requesting association /// Extended address of the device requesting association
@ -31,6 +32,7 @@ impl ParseableMacEvent for AssociateIndication {}
/// MLME DISASSOCIATE indication which will be used to send /// MLME DISASSOCIATE indication which will be used to send
/// disassociation indication to the application. /// disassociation indication to the application.
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct DisassociateIndication { pub struct DisassociateIndication {
/// Extended address of the device requesting association /// Extended address of the device requesting association
@ -52,6 +54,7 @@ impl ParseableMacEvent for DisassociateIndication {}
/// MLME BEACON NOTIIFY Indication which is used to send parameters contained /// MLME BEACON NOTIIFY Indication which is used to send parameters contained
/// within a beacon frame received by the MAC to the application /// within a beacon frame received by the MAC to the application
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BeaconNotifyIndication { pub struct BeaconNotifyIndication {
/// he set of octets comprising the beacon payload to be transferred /// he set of octets comprising the beacon payload to be transferred
@ -73,6 +76,7 @@ impl ParseableMacEvent for BeaconNotifyIndication {}
/// MLME COMM STATUS Indication which is used by the MAC to indicate a communications status /// MLME COMM STATUS Indication which is used by the MAC to indicate a communications status
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct CommStatusIndication { pub struct CommStatusIndication {
/// The 16-bit PAN identifier of the device from which the frame /// The 16-bit PAN identifier of the device from which the frame
@ -103,6 +107,7 @@ impl ParseableMacEvent for CommStatusIndication {}
/// MLME GTS Indication indicates that a GTS has been allocated or that a /// MLME GTS Indication indicates that a GTS has been allocated or that a
/// previously allocated GTS has been deallocated /// previously allocated GTS has been deallocated
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct GtsIndication { pub struct GtsIndication {
/// The short address of the device that has been allocated or deallocated a GTS /// The short address of the device that has been allocated or deallocated a GTS
@ -126,6 +131,7 @@ impl ParseableMacEvent for GtsIndication {}
/// MLME ORPHAN Indication which is used by the coordinator to notify the /// MLME ORPHAN Indication which is used by the coordinator to notify the
/// application of the presence of an orphaned device /// application of the presence of an orphaned device
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct OrphanIndication { pub struct OrphanIndication {
/// Extended address of the orphaned device /// Extended address of the orphaned device
@ -147,6 +153,7 @@ impl ParseableMacEvent for OrphanIndication {}
/// MLME SYNC LOSS Indication which is used by the MAC to indicate the loss /// MLME SYNC LOSS Indication which is used by the MAC to indicate the loss
/// of synchronization with the coordinator /// of synchronization with the coordinator
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct SyncLossIndication { pub struct SyncLossIndication {
/// The PAN identifier with which the device lost synchronization or to which it was realigned /// The PAN identifier with which the device lost synchronization or to which it was realigned
@ -172,6 +179,7 @@ impl ParseableMacEvent for SyncLossIndication {}
/// MLME DPS Indication which indicates the expiration of the DPSIndexDuration /// MLME DPS Indication which indicates the expiration of the DPSIndexDuration
/// and the resetting of the DPS values in the PHY /// and the resetting of the DPS values in the PHY
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct DpsIndication { pub struct DpsIndication {
/// byte stuffing to keep 32 bit alignment /// byte stuffing to keep 32 bit alignment
@ -181,6 +189,7 @@ pub struct DpsIndication {
impl ParseableMacEvent for DpsIndication {} impl ParseableMacEvent for DpsIndication {}
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct DataIndication { pub struct DataIndication {
/// Pointer to the set of octets forming the MSDU being indicated /// Pointer to the set of octets forming the MSDU being indicated
@ -244,6 +253,7 @@ impl DataIndication {
/// MLME POLL Indication which will be used for indicating the Data Request /// MLME POLL Indication which will be used for indicating the Data Request
/// reception to upper layer as defined in Zigbee r22 - D.8.2 /// reception to upper layer as defined in Zigbee r22 - D.8.2
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PollIndication { pub struct PollIndication {
/// addressing mode used /// addressing mode used

View File

@ -8,6 +8,7 @@ use super::typedefs::{
/// MLME ASSOCIATE Confirm used to inform of the initiating device whether /// MLME ASSOCIATE Confirm used to inform of the initiating device whether
/// its request to associate was successful or unsuccessful /// its request to associate was successful or unsuccessful
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct AssociateConfirm { pub struct AssociateConfirm {
/// short address allocated by the coordinator on successful association /// short address allocated by the coordinator on successful association
@ -30,6 +31,7 @@ impl ParseableMacEvent for AssociateConfirm {}
/// MLME DISASSOCIATE Confirm used to send disassociation Confirmation to the application. /// MLME DISASSOCIATE Confirm used to send disassociation Confirmation to the application.
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct DisassociateConfirm { pub struct DisassociateConfirm {
/// status of the disassociation attempt /// status of the disassociation attempt
@ -46,6 +48,7 @@ impl ParseableMacEvent for DisassociateConfirm {}
/// MLME GET Confirm which requests information about a given PIB attribute /// MLME GET Confirm which requests information about a given PIB attribute
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct GetConfirm { pub struct GetConfirm {
/// The pointer to the value of the PIB attribute attempted to read /// The pointer to the value of the PIB attribute attempted to read
@ -65,6 +68,7 @@ impl ParseableMacEvent for GetConfirm {}
/// MLME GTS Confirm which eports the results of a request to allocate a new GTS /// MLME GTS Confirm which eports the results of a request to allocate a new GTS
/// or to deallocate an existing GTS /// or to deallocate an existing GTS
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct GtsConfirm { pub struct GtsConfirm {
/// The characteristics of the GTS /// The characteristics of the GTS
@ -79,6 +83,7 @@ impl ParseableMacEvent for GtsConfirm {}
/// MLME RESET Confirm which is used to report the results of the reset operation /// MLME RESET Confirm which is used to report the results of the reset operation
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ResetConfirm { pub struct ResetConfirm {
/// The result of the reset operation /// The result of the reset operation
@ -92,6 +97,7 @@ impl ParseableMacEvent for ResetConfirm {}
/// MLME RX ENABLE Confirm which is used to report the results of the attempt /// MLME RX ENABLE Confirm which is used to report the results of the attempt
/// to enable or disable the receiver /// to enable or disable the receiver
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct RxEnableConfirm { pub struct RxEnableConfirm {
/// Result of the request to enable or disable the receiver /// Result of the request to enable or disable the receiver
@ -104,6 +110,7 @@ impl ParseableMacEvent for RxEnableConfirm {}
/// MLME SCAN Confirm which is used to report the result of the channel scan request /// MLME SCAN Confirm which is used to report the result of the channel scan request
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ScanConfirm { pub struct ScanConfirm {
/// Status of the scan request /// Status of the scan request
@ -130,6 +137,7 @@ impl ParseableMacEvent for ScanConfirm {}
/// MLME SET Confirm which reports the result of an attempt to write a value to a PIB attribute /// MLME SET Confirm which reports the result of an attempt to write a value to a PIB attribute
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct SetConfirm { pub struct SetConfirm {
/// The result of the set operation /// The result of the set operation
@ -145,6 +153,7 @@ impl ParseableMacEvent for SetConfirm {}
/// MLME START Confirm which is used to report the results of the attempt to /// MLME START Confirm which is used to report the results of the attempt to
/// start using a new superframe configuration /// start using a new superframe configuration
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct StartConfirm { pub struct StartConfirm {
/// Result of the attempt to start using an updated superframe configuration /// Result of the attempt to start using an updated superframe configuration
@ -157,6 +166,7 @@ impl ParseableMacEvent for StartConfirm {}
/// MLME POLL Confirm which is used to report the result of a request to poll the coordinator for data /// MLME POLL Confirm which is used to report the result of a request to poll the coordinator for data
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PollConfirm { pub struct PollConfirm {
/// The status of the data request /// The status of the data request
@ -169,6 +179,7 @@ impl ParseableMacEvent for PollConfirm {}
/// MLME DPS Confirm which reports the results of the attempt to enable or disable the DPS /// MLME DPS Confirm which reports the results of the attempt to enable or disable the DPS
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct DpsConfirm { pub struct DpsConfirm {
/// The status of the DPS request /// The status of the DPS request
@ -182,6 +193,7 @@ impl ParseableMacEvent for DpsConfirm {}
/// MLME SOUNDING Confirm which reports the result of a request to the PHY to provide /// MLME SOUNDING Confirm which reports the result of a request to the PHY to provide
/// channel sounding information /// channel sounding information
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct SoundingConfirm { pub struct SoundingConfirm {
/// Results of the sounding measurement /// Results of the sounding measurement
@ -195,6 +207,7 @@ impl ParseableMacEvent for SoundingConfirm {}
/// MLME CALIBRATE Confirm which reports the result of a request to the PHY /// MLME CALIBRATE Confirm which reports the result of a request to the PHY
/// to provide internal propagation path information /// to provide internal propagation path information
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct CalibrateConfirm { pub struct CalibrateConfirm {
/// The status of the attempt to return sounding data /// The status of the attempt to return sounding data
@ -214,6 +227,7 @@ impl ParseableMacEvent for CalibrateConfirm {}
/// MCPS DATA Confirm which will be used for reporting the results of /// MCPS DATA Confirm which will be used for reporting the results of
/// MAC data related requests from the application /// MAC data related requests from the application
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct DataConfirm { pub struct DataConfirm {
/// The handle associated with the MSDU being confirmed /// The handle associated with the MSDU being confirmed
@ -245,6 +259,7 @@ impl ParseableMacEvent for DataConfirm {}
/// MCPS PURGE Confirm which will be used by the MAC to notify the application of /// MCPS PURGE Confirm which will be used by the MAC to notify the application of
/// the status of its request to purge an MSDU from the transaction queue /// the status of its request to purge an MSDU from the transaction queue
#[repr(C)] #[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PurgeConfirm { pub struct PurgeConfirm {
/// Handle associated with the MSDU requested to be purged from the transaction queue /// Handle associated with the MSDU requested to be purged from the transaction queue

View File

@ -1,3 +1,5 @@
use core::fmt::Debug;
use crate::numeric_enum; use crate::numeric_enum;
#[derive(Debug)] #[derive(Debug)]
@ -37,7 +39,7 @@ numeric_enum! {
numeric_enum! { numeric_enum! {
#[repr(u8)] #[repr(u8)]
/// this enum contains all the MAC PIB Ids /// this enum contains all the MAC PIB Ids
#[derive(Default)] #[derive(Default, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum PibId { pub enum PibId {
// PHY // PHY
@ -96,7 +98,7 @@ numeric_enum! {
numeric_enum! { numeric_enum! {
#[repr(u8)] #[repr(u8)]
#[derive(Default, Clone, Copy)] #[derive(Default, Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum AddressMode { pub enum AddressMode {
#[default] #[default]
@ -113,6 +115,18 @@ pub union MacAddress {
pub extended: [u8; 8], pub extended: [u8; 8],
} }
impl Debug for MacAddress {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
unsafe {
write!(
fmt,
"MacAddress {{ short: {:?}, extended: {:?} }}",
self.short, self.extended
)
}
}
}
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
impl defmt::Format for MacAddress { impl defmt::Format for MacAddress {
fn format(&self, fmt: defmt::Formatter) { fn format(&self, fmt: defmt::Formatter) {
@ -159,7 +173,7 @@ pub struct GtsCharacteristics {
/// MAC PAN Descriptor which contains the network details of the device from /// MAC PAN Descriptor which contains the network details of the device from
/// which the beacon is received /// which the beacon is received
#[derive(Default, Clone, Copy)] #[derive(Default, Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PanDescriptor { pub struct PanDescriptor {
/// PAN identifier of the coordinator /// PAN identifier of the coordinator
@ -223,7 +237,7 @@ impl TryFrom<&[u8]> for PanDescriptor {
numeric_enum! { numeric_enum! {
#[repr(u8)] #[repr(u8)]
#[derive(Default, Clone, Copy)] #[derive(Default, Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
/// Building wireless applications with STM32WB series MCUs - Application note 13.10.3 /// Building wireless applications with STM32WB series MCUs - Application note 13.10.3
pub enum MacChannel { pub enum MacChannel {
@ -289,7 +303,7 @@ defmt::bitflags! {
numeric_enum! { numeric_enum! {
#[repr(u8)] #[repr(u8)]
#[derive(Default, Clone, Copy)] #[derive(Default, Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum KeyIdMode { pub enum KeyIdMode {
#[default] #[default]
@ -306,6 +320,7 @@ numeric_enum! {
numeric_enum! { numeric_enum! {
#[repr(u8)] #[repr(u8)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum AssociationStatus { pub enum AssociationStatus {
/// Association successful /// Association successful
@ -319,7 +334,7 @@ numeric_enum! {
numeric_enum! { numeric_enum! {
#[repr(u8)] #[repr(u8)]
#[derive(Clone, Copy)] #[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DisassociationReason { pub enum DisassociationReason {
/// The coordinator wishes the device to leave the PAN. /// The coordinator wishes the device to leave the PAN.
@ -331,7 +346,7 @@ numeric_enum! {
numeric_enum! { numeric_enum! {
#[repr(u8)] #[repr(u8)]
#[derive(Default, Clone, Copy)] #[derive(Default, Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum SecurityLevel { pub enum SecurityLevel {
/// MAC Unsecured Mode Security /// MAC Unsecured Mode Security
@ -346,6 +361,7 @@ numeric_enum! {
numeric_enum! { numeric_enum! {
#[repr(u8)] #[repr(u8)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ScanType { pub enum ScanType {
EdScan = 0x00, EdScan = 0x00,
@ -356,7 +372,7 @@ numeric_enum! {
} }
/// newtype for Pan Id /// newtype for Pan Id
#[derive(Default, Clone, Copy)] #[derive(Default, Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PanId(pub [u8; 2]); pub struct PanId(pub [u8; 2]);