diff options
| author | goueslati <[email protected]> | 2023-07-12 16:49:37 +0100 |
|---|---|---|
| committer | goueslati <[email protected]> | 2023-07-12 16:49:37 +0100 |
| commit | eccd2ecebf01753e70705a6ca1e21bc83b2c204c (patch) | |
| tree | ef355c98cce0872969eadeacc568c56acbe6ccea /examples/stm32wb | |
| parent | d5a4457b5e3a95a12f249315fb1d9b6a577307f2 (diff) | |
change MacAddress to a union instead of an enum
Diffstat (limited to 'examples/stm32wb')
| -rw-r--r-- | examples/stm32wb/src/bin/mac_ffd.rs | 18 | ||||
| -rw-r--r-- | examples/stm32wb/src/bin/mac_rfd.rs | 94 |
2 files changed, 67 insertions, 45 deletions
diff --git a/examples/stm32wb/src/bin/mac_ffd.rs b/examples/stm32wb/src/bin/mac_ffd.rs index 18b29362b..4e2578a21 100644 --- a/examples/stm32wb/src/bin/mac_ffd.rs +++ b/examples/stm32wb/src/bin/mac_ffd.rs | |||
| @@ -66,7 +66,7 @@ async fn main(spawner: Spawner) { | |||
| 66 | 66 | ||
| 67 | info!("resetting"); | 67 | info!("resetting"); |
| 68 | mbox.mac_subsystem | 68 | mbox.mac_subsystem |
| 69 | .send_command(ResetRequest { set_default_pib: true }) | 69 | .send_command(&ResetRequest { set_default_pib: true }) |
| 70 | .await | 70 | .await |
| 71 | .unwrap(); | 71 | .unwrap(); |
| 72 | let evt = mbox.mac_subsystem.read().await; | 72 | let evt = mbox.mac_subsystem.read().await; |
| @@ -75,7 +75,7 @@ async fn main(spawner: Spawner) { | |||
| 75 | info!("setting extended address"); | 75 | info!("setting extended address"); |
| 76 | let extended_address: u64 = 0xACDE480000000001; | 76 | let extended_address: u64 = 0xACDE480000000001; |
| 77 | mbox.mac_subsystem | 77 | mbox.mac_subsystem |
| 78 | .send_command(SetRequest { | 78 | .send_command(&SetRequest { |
| 79 | pib_attribute_ptr: &extended_address as *const _ as *const u8, | 79 | pib_attribute_ptr: &extended_address as *const _ as *const u8, |
| 80 | pib_attribute: PibId::ExtendedAddress, | 80 | pib_attribute: PibId::ExtendedAddress, |
| 81 | }) | 81 | }) |
| @@ -87,7 +87,7 @@ async fn main(spawner: Spawner) { | |||
| 87 | info!("setting short address"); | 87 | info!("setting short address"); |
| 88 | let short_address: u16 = 0x1122; | 88 | let short_address: u16 = 0x1122; |
| 89 | mbox.mac_subsystem | 89 | mbox.mac_subsystem |
| 90 | .send_command(SetRequest { | 90 | .send_command(&SetRequest { |
| 91 | pib_attribute_ptr: &short_address as *const _ as *const u8, | 91 | pib_attribute_ptr: &short_address as *const _ as *const u8, |
| 92 | pib_attribute: PibId::ShortAddress, | 92 | pib_attribute: PibId::ShortAddress, |
| 93 | }) | 93 | }) |
| @@ -99,7 +99,7 @@ async fn main(spawner: Spawner) { | |||
| 99 | info!("setting association permit"); | 99 | info!("setting association permit"); |
| 100 | let association_permit: bool = true; | 100 | let association_permit: bool = true; |
| 101 | mbox.mac_subsystem | 101 | mbox.mac_subsystem |
| 102 | .send_command(SetRequest { | 102 | .send_command(&SetRequest { |
| 103 | pib_attribute_ptr: &association_permit as *const _ as *const u8, | 103 | pib_attribute_ptr: &association_permit as *const _ as *const u8, |
| 104 | pib_attribute: PibId::AssociationPermit, | 104 | pib_attribute: PibId::AssociationPermit, |
| 105 | }) | 105 | }) |
| @@ -111,7 +111,7 @@ async fn main(spawner: Spawner) { | |||
| 111 | info!("setting TX power"); | 111 | info!("setting TX power"); |
| 112 | let transmit_power: i8 = 2; | 112 | let transmit_power: i8 = 2; |
| 113 | mbox.mac_subsystem | 113 | mbox.mac_subsystem |
| 114 | .send_command(SetRequest { | 114 | .send_command(&SetRequest { |
| 115 | pib_attribute_ptr: &transmit_power as *const _ as *const u8, | 115 | pib_attribute_ptr: &transmit_power as *const _ as *const u8, |
| 116 | pib_attribute: PibId::TransmitPower, | 116 | pib_attribute: PibId::TransmitPower, |
| 117 | }) | 117 | }) |
| @@ -122,7 +122,8 @@ async fn main(spawner: Spawner) { | |||
| 122 | 122 | ||
| 123 | info!("starting FFD device"); | 123 | info!("starting FFD device"); |
| 124 | mbox.mac_subsystem | 124 | mbox.mac_subsystem |
| 125 | .send_command(StartRequest { | 125 | .send_command(&StartRequest { |
| 126 | pan_id: [0xAA, 0x1A], | ||
| 126 | channel_number: MacChannel::Channel16, | 127 | channel_number: MacChannel::Channel16, |
| 127 | beacon_order: 0x0F, | 128 | beacon_order: 0x0F, |
| 128 | superframe_order: 0x0F, | 129 | superframe_order: 0x0F, |
| @@ -138,7 +139,7 @@ async fn main(spawner: Spawner) { | |||
| 138 | info!("setting RX on when idle"); | 139 | info!("setting RX on when idle"); |
| 139 | let rx_on_while_idle: bool = true; | 140 | let rx_on_while_idle: bool = true; |
| 140 | mbox.mac_subsystem | 141 | mbox.mac_subsystem |
| 141 | .send_command(SetRequest { | 142 | .send_command(&SetRequest { |
| 142 | pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8, | 143 | pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8, |
| 143 | pib_attribute: PibId::RxOnWhenIdle, | 144 | pib_attribute: PibId::RxOnWhenIdle, |
| 144 | }) | 145 | }) |
| @@ -151,7 +152,4 @@ async fn main(spawner: Spawner) { | |||
| 151 | let evt = mbox.mac_subsystem.read().await; | 152 | let evt = mbox.mac_subsystem.read().await; |
| 152 | defmt::info!("{:#x}", evt); | 153 | defmt::info!("{:#x}", evt); |
| 153 | } | 154 | } |
| 154 | |||
| 155 | info!("Test OK"); | ||
| 156 | cortex_m::asm::bkpt(); | ||
| 157 | } | 155 | } |
diff --git a/examples/stm32wb/src/bin/mac_rfd.rs b/examples/stm32wb/src/bin/mac_rfd.rs index 8042a3704..e5f8d54c9 100644 --- a/examples/stm32wb/src/bin/mac_rfd.rs +++ b/examples/stm32wb/src/bin/mac_rfd.rs | |||
| @@ -6,7 +6,8 @@ use defmt::*; | |||
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::bind_interrupts; | 7 | use embassy_stm32::bind_interrupts; |
| 8 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; | 8 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; |
| 9 | use embassy_stm32_wpan::sub::mac::commands::{AssociateRequest, ResetRequest, SetRequest, StartRequest}; | 9 | use embassy_stm32_wpan::sub::mac::commands::{AssociateRequest, GetRequest, ResetRequest, SetRequest}; |
| 10 | use embassy_stm32_wpan::sub::mac::event::MacEvent; | ||
| 10 | use embassy_stm32_wpan::sub::mac::typedefs::{ | 11 | use embassy_stm32_wpan::sub::mac::typedefs::{ |
| 11 | AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PibId, SecurityLevel, | 12 | AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PibId, SecurityLevel, |
| 12 | }; | 13 | }; |
| @@ -67,52 +68,75 @@ async fn main(spawner: Spawner) { | |||
| 67 | info!("initialized mac: {}", result); | 68 | info!("initialized mac: {}", result); |
| 68 | 69 | ||
| 69 | info!("resetting"); | 70 | info!("resetting"); |
| 70 | let response = mbox | 71 | mbox.mac_subsystem |
| 71 | .mac_subsystem | 72 | .send_command(&ResetRequest { set_default_pib: true }) |
| 72 | .send_command(ResetRequest { set_default_pib: true }) | 73 | .await |
| 73 | .await; | 74 | .unwrap(); |
| 74 | info!("{}", response); | 75 | let evt = mbox.mac_subsystem.read().await; |
| 76 | info!("{:#x}", evt); | ||
| 75 | 77 | ||
| 76 | info!("setting extended address"); | 78 | info!("setting extended address"); |
| 77 | let extended_address: u64 = 0xACDE480000000002; | 79 | let extended_address: u64 = 0xACDE480000000002; |
| 78 | let response = mbox | 80 | mbox.mac_subsystem |
| 79 | .mac_subsystem | 81 | .send_command(&SetRequest { |
| 80 | .send_command(SetRequest { | ||
| 81 | pib_attribute_ptr: &extended_address as *const _ as *const u8, | 82 | pib_attribute_ptr: &extended_address as *const _ as *const u8, |
| 82 | pib_attribute: PibId::ExtendedAddress, | 83 | pib_attribute: PibId::ExtendedAddress, |
| 83 | }) | 84 | }) |
| 84 | .await; | 85 | .await |
| 85 | info!("{}", response); | 86 | .unwrap(); |
| 87 | let evt = mbox.mac_subsystem.read().await; | ||
| 88 | info!("{:#x}", evt); | ||
| 89 | |||
| 90 | info!("getting extended address"); | ||
| 91 | mbox.mac_subsystem | ||
| 92 | .send_command(&GetRequest { | ||
| 93 | pib_attribute: PibId::ExtendedAddress, | ||
| 94 | }) | ||
| 95 | .await | ||
| 96 | .unwrap(); | ||
| 97 | let evt = mbox.mac_subsystem.read().await; | ||
| 98 | info!("{:#x}", evt); | ||
| 99 | |||
| 100 | if let Ok(MacEvent::MlmeGetCnf(evt)) = evt { | ||
| 101 | if evt.pib_attribute_value_len == 8 { | ||
| 102 | let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) }; | ||
| 103 | |||
| 104 | info!("value {:#x}", value) | ||
| 105 | } | ||
| 106 | } | ||
| 86 | 107 | ||
| 87 | info!("assocation request"); | 108 | info!("assocation request"); |
| 88 | let response = mbox | 109 | let a = AssociateRequest { |
| 89 | .mac_subsystem | 110 | channel_number: MacChannel::Channel16, |
| 90 | .send_command(AssociateRequest { | 111 | channel_page: 0, |
| 91 | channel_number: MacChannel::Channel16, | 112 | coord_addr_mode: AddressMode::Short, |
| 92 | channel_page: 0, | 113 | coord_address: MacAddress { short: [34, 17] }, |
| 93 | coord_addr_mode: AddressMode::Short, | 114 | capability_information: Capabilities::ALLOCATE_ADDRESS, |
| 94 | coord_address: MacAddress::Short([0x22, 0x11]), | 115 | coord_pan_id: [0xAA, 0x1A], |
| 95 | capability_information: Capabilities::ALLOCATE_ADDRESS, | 116 | security_level: SecurityLevel::Unsecure, |
| 96 | coord_pan_id: [0xAA, 0x1A], | 117 | key_id_mode: KeyIdMode::Implicite, |
| 97 | security_level: SecurityLevel::Unsecure, | 118 | key_source: [0; 8], |
| 98 | key_id_mode: KeyIdMode::Implicite, | 119 | key_index: 152, |
| 99 | key_source: [0; 8], | 120 | }; |
| 100 | key_index: 0, | 121 | info!("{}", a); |
| 101 | }) | 122 | mbox.mac_subsystem.send_command(&a).await.unwrap(); |
| 102 | .await; | 123 | let evt = mbox.mac_subsystem.read().await; |
| 103 | info!("{}", response); | 124 | info!("{:#x}", evt); |
| 104 | 125 | ||
| 105 | info!("setting short address"); | 126 | info!("setting short address"); |
| 106 | let short: u64 = 0xACDE480000000002; | 127 | let short: u64 = 0xACDE480000000002; |
| 107 | let response = mbox | 128 | mbox.mac_subsystem |
| 108 | .mac_subsystem | 129 | .send_command(&SetRequest { |
| 109 | .send_command(SetRequest { | ||
| 110 | pib_attribute_ptr: &short as *const _ as *const u8, | 130 | pib_attribute_ptr: &short as *const _ as *const u8, |
| 111 | pib_attribute: PibId::ShortAddress, | 131 | pib_attribute: PibId::ShortAddress, |
| 112 | }) | 132 | }) |
| 113 | .await; | 133 | .await |
| 114 | info!("{}", response); | 134 | .unwrap(); |
| 115 | 135 | let evt = mbox.mac_subsystem.read().await; | |
| 116 | info!("Test OK"); | 136 | info!("{:#x}", evt); |
| 117 | cortex_m::asm::bkpt(); | 137 | |
| 138 | loop { | ||
| 139 | let evt = mbox.mac_subsystem.read().await; | ||
| 140 | info!("{:#x}", evt); | ||
| 141 | } | ||
| 118 | } | 142 | } |
