Skip to content

Commit

Permalink
Enable all events
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernQ committed Dec 12, 2023
1 parent 6efde2a commit eff4c3d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
11 changes: 11 additions & 0 deletions bleps/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{AdvertisingParameters, Data};

pub const CONTROLLER_OGF: u8 = 0x03;
pub const RESET_OCF: u16 = 0x03;
pub const SET_EVENT_MASK_OCF: u16 = 0x01;

pub const LE_OGF: u8 = 0x08;
pub const SET_ADVERTISING_PARAMETERS_OCF: u16 = 0x06;
Expand Down Expand Up @@ -64,6 +65,7 @@ pub enum Command<'a> {
Disconnect { connection_handle: u16, reason: u8 },
LeLongTermKeyRequestReply { handle: u16, ltk: u128 },
ReadBrAddr,
SetEventMask { events: [u8; 8] },
}

impl<'a> Command<'a> {
Expand Down Expand Up @@ -160,6 +162,15 @@ impl<'a> Command<'a> {
.write_into(&mut data[1..]);
Data::new(&data)
}
Command::SetEventMask { events } => {
log::info!("command set event mask");
let mut data = [0u8; 12];
data[0] = 0x01;
CommandHeader::from_ogf_ocf(CONTROLLER_OGF, SET_EVENT_MASK_OCF, 0x08)
.write_into(&mut data[1..]);
data[4..].copy_from_slice(&events);
Data::new(&data)
}
}
}
}
28 changes: 26 additions & 2 deletions bleps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::cell::RefCell;
use acl::AclPacket;
use command::{
opcode, Command, INFORMATIONAL_OGF, LONG_TERM_KEY_REQUEST_REPLY_OCF, READ_BD_ADDR_OCF,
SET_ADVERTISE_ENABLE_OCF, SET_ADVERTISING_DATA_OCF, SET_SCAN_RSP_DATA_OCF,
SET_ADVERTISE_ENABLE_OCF, SET_ADVERTISING_DATA_OCF, SET_EVENT_MASK_OCF, SET_SCAN_RSP_DATA_OCF,
};
use command::{LE_OGF, SET_ADVERTISING_PARAMETERS_OCF};
use embedded_io_blocking::{Read, Write};
Expand Down Expand Up @@ -250,6 +250,7 @@ impl<'a> Ble<'a> {
Self: Sized,
{
self.cmd_reset()?;
self.cmd_set_event_mask([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])?;
Ok(())
}

Expand All @@ -262,6 +263,15 @@ impl<'a> Ble<'a> {
.check_command_completed()
}

pub fn cmd_set_event_mask(&mut self, events: [u8; 8]) -> Result<EventType, Error>
where
Self: Sized,
{
self.write_bytes(Command::SetEventMask { events }.encode().as_slice());
self.wait_for_command_complete(CONTROLLER_OGF, SET_EVENT_MASK_OCF)?
.check_command_completed()
}

pub fn cmd_set_le_advertising_parameters(&mut self) -> Result<EventType, Error>
where
Self: Sized,
Expand Down Expand Up @@ -542,7 +552,10 @@ pub mod asynch {
where
Self: Sized,
{
Ok(self.cmd_reset().await?)
let res = self.cmd_reset().await?;
self.cmd_set_event_mask([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])
.await?;
Ok(res)
}

pub async fn cmd_reset(&mut self) -> Result<EventType, Error>
Expand All @@ -555,6 +568,17 @@ pub mod asynch {
.check_command_completed()
}

pub async fn cmd_set_event_mask(&mut self, events: [u8; 8]) -> Result<EventType, Error>
where
Self: Sized,
{
self.write_bytes(Command::SetEventMask { events }.encode().as_slice())
.await;
self.wait_for_command_complete(CONTROLLER_OGF, SET_EVENT_MASK_OCF)
.await?
.check_command_completed()
}

pub async fn cmd_set_le_advertising_parameters(&mut self) -> Result<EventType, Error>
where
Self: Sized,
Expand Down

0 comments on commit eff4c3d

Please sign in to comment.