Skip to content

Commit

Permalink
Merge pull request #53 from oleander/feature/can_notify
Browse files Browse the repository at this point in the history
Add notification check and properties to BLE characteristic
  • Loading branch information
taks authored Nov 26, 2023
2 parents fbbf6b5 + d4b3ec8 commit d117666
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/ble_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ fn main() {

let uuid = uuid128!("a3c87500-8ed3-4bdf-8a39-a01bebede295");
let characteristic = service.get_characteristic(uuid).await.unwrap();

if !characteristic.can_notify() {
return ::log::error!("characteristic can't notify: {:?}", uuid);
}

::log::info!("subscribe {:?}", uuid);
characteristic
.on_notify(|data| {
Expand Down
36 changes: 36 additions & 0 deletions src/client/ble_remote_characteristic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,42 @@ impl BLERemoteCharacteristic {
self
}

pub fn can_notify(&self) -> bool {
self
.properties()
.contains(GattCharacteristicProperties::NOTIFY)
}

pub fn can_indicate(&self) -> bool {
self
.properties()
.contains(GattCharacteristicProperties::INDICATE)
}

pub fn can_read(&self) -> bool {
self
.properties()
.contains(GattCharacteristicProperties::READ)
}

pub fn can_write(&self) -> bool {
self
.properties()
.contains(GattCharacteristicProperties::WRITE)
}

pub fn can_write_no_response(&self) -> bool {
self
.properties()
.contains(GattCharacteristicProperties::WRITE_NO_RSP)
}

pub fn can_broadcast(&self) -> bool {
self
.properties()
.contains(GattCharacteristicProperties::BROADCAST)
}

pub(crate) unsafe fn notify(&mut self, om: *mut esp_idf_sys::os_mbuf) {
if let Some(no_notify) = self.state.on_notify.as_mut() {
let data = unsafe { core::slice::from_raw_parts((*om).om_data, (*om).om_len as _) };
Expand Down

0 comments on commit d117666

Please sign in to comment.