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 | |
| parent | 7c465465c1a97234c3fbeb18154bfd7f79ab07f2 (diff) | |
wpan/mac: use lifetimes to control events
Diffstat (limited to 'examples/stm32wb/src/bin')
| -rw-r--r-- | examples/stm32wb/src/bin/mac_ffd.rs | 46 | ||||
| -rw-r--r-- | examples/stm32wb/src/bin/mac_rfd.rs | 55 |
2 files changed, 64 insertions, 37 deletions
diff --git a/examples/stm32wb/src/bin/mac_ffd.rs b/examples/stm32wb/src/bin/mac_ffd.rs index f8c8ba288..86413ea0f 100644 --- a/examples/stm32wb/src/bin/mac_ffd.rs +++ b/examples/stm32wb/src/bin/mac_ffd.rs | |||
| @@ -73,8 +73,10 @@ async fn main(spawner: Spawner) { | |||
| 73 | }) | 73 | }) |
| 74 | .await | 74 | .await |
| 75 | .unwrap(); | 75 | .unwrap(); |
| 76 | let evt = mbox.mac_subsystem.read().await; | 76 | { |
| 77 | defmt::info!("{:#x}", evt); | 77 | let evt = mbox.mac_subsystem.read().await; |
| 78 | defmt::info!("{:#x}", evt.mac_event()); | ||
| 79 | } | ||
| 78 | 80 | ||
| 79 | info!("setting extended address"); | 81 | info!("setting extended address"); |
| 80 | let extended_address: u64 = 0xACDE480000000001; | 82 | let extended_address: u64 = 0xACDE480000000001; |
| @@ -85,8 +87,10 @@ async fn main(spawner: Spawner) { | |||
| 85 | }) | 87 | }) |
| 86 | .await | 88 | .await |
| 87 | .unwrap(); | 89 | .unwrap(); |
| 88 | let evt = mbox.mac_subsystem.read().await; | 90 | { |
| 89 | defmt::info!("{:#x}", evt); | 91 | let evt = mbox.mac_subsystem.read().await; |
| 92 | defmt::info!("{:#x}", evt.mac_event()); | ||
| 93 | } | ||
| 90 | 94 | ||
| 91 | info!("setting short address"); | 95 | info!("setting short address"); |
| 92 | let short_address: u16 = 0x1122; | 96 | let short_address: u16 = 0x1122; |
| @@ -97,8 +101,10 @@ async fn main(spawner: Spawner) { | |||
| 97 | }) | 101 | }) |
| 98 | .await | 102 | .await |
| 99 | .unwrap(); | 103 | .unwrap(); |
| 100 | let evt = mbox.mac_subsystem.read().await; | 104 | { |
| 101 | defmt::info!("{:#x}", evt); | 105 | let evt = mbox.mac_subsystem.read().await; |
| 106 | defmt::info!("{:#x}", evt.mac_event()); | ||
| 107 | } | ||
| 102 | 108 | ||
| 103 | info!("setting association permit"); | 109 | info!("setting association permit"); |
| 104 | let association_permit: bool = true; | 110 | let association_permit: bool = true; |
| @@ -109,8 +115,10 @@ async fn main(spawner: Spawner) { | |||
| 109 | }) | 115 | }) |
| 110 | .await | 116 | .await |
| 111 | .unwrap(); | 117 | .unwrap(); |
| 112 | let evt = mbox.mac_subsystem.read().await; | 118 | { |
| 113 | defmt::info!("{:#x}", evt); | 119 | let evt = mbox.mac_subsystem.read().await; |
| 120 | defmt::info!("{:#x}", evt.mac_event()); | ||
| 121 | } | ||
| 114 | 122 | ||
| 115 | info!("setting TX power"); | 123 | info!("setting TX power"); |
| 116 | let transmit_power: i8 = 2; | 124 | let transmit_power: i8 = 2; |
| @@ -121,8 +129,10 @@ async fn main(spawner: Spawner) { | |||
| 121 | }) | 129 | }) |
| 122 | .await | 130 | .await |
| 123 | .unwrap(); | 131 | .unwrap(); |
| 124 | let evt = mbox.mac_subsystem.read().await; | 132 | { |
| 125 | defmt::info!("{:#x}", evt); | 133 | let evt = mbox.mac_subsystem.read().await; |
| 134 | defmt::info!("{:#x}", evt.mac_event()); | ||
| 135 | } | ||
| 126 | 136 | ||
| 127 | info!("starting FFD device"); | 137 | info!("starting FFD device"); |
| 128 | mbox.mac_subsystem | 138 | mbox.mac_subsystem |
| @@ -137,8 +147,10 @@ async fn main(spawner: Spawner) { | |||
| 137 | }) | 147 | }) |
| 138 | .await | 148 | .await |
| 139 | .unwrap(); | 149 | .unwrap(); |
| 140 | let evt = mbox.mac_subsystem.read().await; | 150 | { |
| 141 | defmt::info!("{:#x}", evt); | 151 | let evt = mbox.mac_subsystem.read().await; |
| 152 | defmt::info!("{:#x}", evt.mac_event()); | ||
| 153 | } | ||
| 142 | 154 | ||
| 143 | info!("setting RX on when idle"); | 155 | info!("setting RX on when idle"); |
| 144 | let rx_on_while_idle: bool = true; | 156 | let rx_on_while_idle: bool = true; |
| @@ -149,14 +161,16 @@ async fn main(spawner: Spawner) { | |||
| 149 | }) | 161 | }) |
| 150 | .await | 162 | .await |
| 151 | .unwrap(); | 163 | .unwrap(); |
| 152 | let evt = mbox.mac_subsystem.read().await; | 164 | { |
| 153 | defmt::info!("{:#x}", evt); | 165 | let evt = mbox.mac_subsystem.read().await; |
| 166 | defmt::info!("{:#x}", evt.mac_event()); | ||
| 167 | } | ||
| 154 | 168 | ||
| 155 | loop { | 169 | loop { |
| 156 | let evt = mbox.mac_subsystem.read().await; | 170 | let evt = mbox.mac_subsystem.read().await; |
| 157 | defmt::info!("{:#x}", evt); | 171 | defmt::info!("{:#x}", evt.mac_event()); |
| 158 | 172 | ||
| 159 | if let Ok(evt) = evt { | 173 | if let Ok(evt) = evt.mac_event() { |
| 160 | match evt { | 174 | match evt { |
| 161 | MacEvent::MlmeAssociateInd(association) => mbox | 175 | MacEvent::MlmeAssociateInd(association) => mbox |
| 162 | .mac_subsystem | 176 | .mac_subsystem |
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 | } |
