Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore failed descriptor reads on Windows #362

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading