diff options
| author | xoviat <[email protected]> | 2023-07-16 15:09:30 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-07-16 15:09:30 -0500 |
| commit | 28b419d65ede6ff29c79dbcaa27145f1c3458a57 (patch) | |
| tree | 318a614bc7ddb86f53af7029928d96201a793f5d /examples/stm32wb/src/bin/mac_rfd.rs | |
| parent | 7c465465c1a97234c3fbeb18154bfd7f79ab07f2 (diff) | |
wpan/mac: use lifetimes to control events
Diffstat (limited to 'examples/stm32wb/src/bin/mac_rfd.rs')
| -rw-r--r-- | examples/stm32wb/src/bin/mac_rfd.rs | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/examples/stm32wb/src/bin/mac_rfd.rs b/examples/stm32wb/src/bin/mac_rfd.rs index b0eb91061..7cb401d89 100644 --- a/examples/stm32wb/src/bin/mac_rfd.rs +++ b/examples/stm32wb/src/bin/mac_rfd.rs | |||
| @@ -75,8 +75,10 @@ async fn main(spawner: Spawner) { | |||
| 75 | }) | 75 | }) |
| 76 | .await | 76 | .await |
| 77 | .unwrap(); | 77 | .unwrap(); |
| 78 | let evt = mbox.mac_subsystem.read().await; | 78 | { |
| 79 | info!("{:#x}", evt); | 79 | let evt = mbox.mac_subsystem.read().await; |
| 80 | defmt::info!("{:#x}", evt.mac_event()); | ||
| 81 | } | ||
| 80 | 82 | ||
| 81 | info!("setting extended address"); | 83 | info!("setting extended address"); |
| 82 | let extended_address: u64 = 0xACDE480000000002; | 84 | let extended_address: u64 = 0xACDE480000000002; |
| @@ -87,8 +89,10 @@ async fn main(spawner: Spawner) { | |||
| 87 | }) | 89 | }) |
| 88 | .await | 90 | .await |
| 89 | .unwrap(); | 91 | .unwrap(); |
| 90 | let evt = mbox.mac_subsystem.read().await; | 92 | { |
| 91 | info!("{:#x}", evt); | 93 | let evt = mbox.mac_subsystem.read().await; |
| 94 | defmt::info!("{:#x}", evt.mac_event()); | ||
| 95 | } | ||
| 92 | 96 | ||
| 93 | info!("getting extended address"); | 97 | info!("getting extended address"); |
| 94 | mbox.mac_subsystem | 98 | mbox.mac_subsystem |
| @@ -98,14 +102,17 @@ async fn main(spawner: Spawner) { | |||
| 98 | }) | 102 | }) |
| 99 | .await | 103 | .await |
| 100 | .unwrap(); | 104 | .unwrap(); |
| 101 | let evt = mbox.mac_subsystem.read().await; | ||
| 102 | info!("{:#x}", evt); | ||
| 103 | 105 | ||
| 104 | if let Ok(MacEvent::MlmeGetCnf(evt)) = evt { | 106 | { |
| 105 | if evt.pib_attribute_value_len == 8 { | 107 | let evt = mbox.mac_subsystem.read().await; |
| 106 | let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) }; | 108 | info!("{:#x}", evt.mac_event()); |
| 109 | |||
| 110 | if let Ok(MacEvent::MlmeGetCnf(evt)) = evt.mac_event() { | ||
| 111 | if evt.pib_attribute_value_len == 8 { | ||
| 112 | let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) }; | ||
| 107 | 113 | ||
| 108 | info!("value {:#x}", value) | 114 | info!("value {:#x}", value) |
| 115 | } | ||
| 109 | } | 116 | } |
| 110 | } | 117 | } |
| 111 | 118 | ||
| @@ -124,13 +131,15 @@ async fn main(spawner: Spawner) { | |||
| 124 | }; | 131 | }; |
| 125 | info!("{}", a); | 132 | info!("{}", a); |
| 126 | mbox.mac_subsystem.send_command(&a).await.unwrap(); | 133 | mbox.mac_subsystem.send_command(&a).await.unwrap(); |
| 127 | let evt = mbox.mac_subsystem.read().await; | 134 | let short_addr = { |
| 128 | info!("{:#x}", evt); | 135 | let evt = mbox.mac_subsystem.read().await; |
| 136 | info!("{:#x}", evt.mac_event()); | ||
| 129 | 137 | ||
| 130 | let short_addr = if let Ok(MacEvent::MlmeAssociateCnf(conf)) = evt { | 138 | if let Ok(MacEvent::MlmeAssociateCnf(conf)) = evt.mac_event() { |
| 131 | conf.assoc_short_address | 139 | conf.assoc_short_address |
| 132 | } else { | 140 | } else { |
| 133 | defmt::panic!() | 141 | defmt::panic!() |
| 142 | } | ||
| 134 | }; | 143 | }; |
| 135 | 144 | ||
| 136 | info!("setting short address"); | 145 | info!("setting short address"); |
| @@ -141,8 +150,10 @@ async fn main(spawner: Spawner) { | |||
| 141 | }) | 150 | }) |
| 142 | .await | 151 | .await |
| 143 | .unwrap(); | 152 | .unwrap(); |
| 144 | let evt = mbox.mac_subsystem.read().await; | 153 | { |
| 145 | info!("{:#x}", evt); | 154 | let evt = mbox.mac_subsystem.read().await; |
| 155 | info!("{:#x}", evt.mac_event()); | ||
| 156 | } | ||
| 146 | 157 | ||
| 147 | info!("sending data"); | 158 | info!("sending data"); |
| 148 | let data = b"Hello from embassy!"; | 159 | let data = b"Hello from embassy!"; |
| @@ -163,11 +174,13 @@ async fn main(spawner: Spawner) { | |||
| 163 | ) | 174 | ) |
| 164 | .await | 175 | .await |
| 165 | .unwrap(); | 176 | .unwrap(); |
| 166 | let evt = mbox.mac_subsystem.read().await; | 177 | { |
| 167 | info!("{:#x}", evt); | 178 | let evt = mbox.mac_subsystem.read().await; |
| 179 | info!("{:#x}", evt.mac_event()); | ||
| 180 | } | ||
| 168 | 181 | ||
| 169 | loop { | 182 | loop { |
| 170 | let evt = mbox.mac_subsystem.read().await; | 183 | let evt = mbox.mac_subsystem.read().await; |
| 171 | info!("{:#x}", evt); | 184 | info!("{:#x}", evt.mac_event()); |
| 172 | } | 185 | } |
| 173 | } | 186 | } |
