diff --git a/CHANGELOG.md b/CHANGELOG.md index 16b598eb..5dd7f1bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Cargo.toml b/Cargo.toml index 6b788a53..8897c430 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "btleplug" -version = "0.11.4" +version = "0.11.5" authors = ["Nonpolynomial, LLC "] license = "MIT/Apache-2.0/BSD-3-Clause" repository = "https://github.com/deviceplug/btleplug" diff --git a/src/winrtble/ble/device.rs b/src/winrtble/ble/device.rs index 560203c6..9fd2707f 100644 --- a/src/winrtble/ble/device.rs +++ b/src/winrtble/ble/device.rs @@ -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(), + )), } } diff --git a/src/winrtble/peripheral.rs b/src/winrtble/peripheral.rs index 5dc97480..f86071d1 100644 --- a/src/winrtble/peripheral.rs +++ b/src/winrtble/peripheral.rs @@ -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")] @@ -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 = - 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 = @@ -455,8 +449,7 @@ impl ApiPeripheral for Peripheral { ); } Err(e) => { - error!("get_characteristics_async {:?}", e); - return Err(e); + warn!("get_characteristics_async {:?}", e); } } }