Skip to content

Commit

Permalink
Merge branch 'deviceplug:master' into add-service-uuid-value-notifica…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
night-crawler committed May 1, 2024
2 parents dbb86ab + 1937ff5 commit 8e151c6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.11.5 (2024-01-10)

## Bugfixes

- Fix issue with Windows failing to read characteristic descriptors

# 0.11.4 (2024-01-01)

## Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "btleplug"
version = "0.11.4"
version = "0.11.5"
authors = ["Nonpolynomial, LLC <[email protected]>"]
license = "MIT/Apache-2.0/BSD-3-Clause"
repository = "https://github.com/deviceplug/btleplug"
Expand Down
30 changes: 21 additions & 9 deletions src/winrtble/ble/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,27 @@ impl BLEDevice {
let async_result = service
.GetCharacteristicsWithCacheModeAsync(BluetoothCacheMode::Uncached)?
.await?;
let status = async_result.Status();
if status == Ok(GattCommunicationStatus::Success) {
let results = async_result.Characteristics()?;
debug!("characteristics {:?}", results.Size());
Ok(results.into_iter().collect())
} else {
Err(Error::Other(
format!("get_characteristics for {:?} failed: {:?}", service, status).into(),
))

match async_result.Status() {
Ok(GattCommunicationStatus::Success) => {
let results = async_result.Characteristics()?;
debug!("characteristics {:?}", results.Size());
Ok(results.into_iter().collect())
}
Ok(GattCommunicationStatus::ProtocolError) => Err(Error::Other(
format!(
"get_characteristics for {:?} encountered a protocol error",
service
)
.into(),
)),
Ok(status) => {
debug!("characteristic read failed due to {:?}", status);
Ok(vec![])
}
Err(e) => Err(Error::Other(
format!("get_characteristics for {:?} failed: {:?}", service, e).into(),
)),
}
}

Expand Down
43 changes: 18 additions & 25 deletions src/winrtble/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{
use async_trait::async_trait;
use dashmap::DashMap;
use futures::stream::Stream;
use log::{error, trace};
use log::{trace, warn};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "serde")]
Expand Down Expand Up @@ -415,29 +415,23 @@ impl ApiPeripheral for Peripheral {
Ok(characteristics) => {
let characteristics =
characteristics.into_iter().map(|characteristic| async {
match BLEDevice::get_characteristic_descriptors(&characteristic)
.await
{
Ok(descriptors) => {
let descriptors: HashMap<Uuid, BLEDescriptor> =
descriptors
.into_iter()
.map(|descriptor| {
let descriptor =
BLEDescriptor::new(descriptor);
(descriptor.uuid(), descriptor)
})
.collect();
Ok((characteristic, descriptors))
}
Err(e) => {
error!("get_characteristic_descriptors_async {:?}", e);
Err(e)
}
}
let c = characteristic.clone();
(
characteristic,
BLEDevice::get_characteristic_descriptors(&c)
.await
.unwrap_or(Vec::new())
.into_iter()
.map(|descriptor| {
let descriptor = BLEDescriptor::new(descriptor);
(descriptor.uuid(), descriptor)
})
.collect(),
)
});
let characteristics = futures::future::try_join_all(characteristics)
.await?

let characteristics = futures::future::join_all(characteristics)
.await
.into_iter()
.map(|(characteristic, descriptors)| {
let characteristic =
Expand All @@ -455,8 +449,7 @@ impl ApiPeripheral for Peripheral {
);
}
Err(e) => {
error!("get_characteristics_async {:?}", e);
return Err(e);
warn!("get_characteristics_async {:?}", e);
}
}
}
Expand Down

0 comments on commit 8e151c6

Please sign in to comment.