(
service: &GattDeviceService,
)
| 129 | } |
| 130 | |
| 131 | pub async fn get_characteristics( |
| 132 | service: &GattDeviceService, |
| 133 | ) -> Result<Vec<GattCharacteristic>> { |
| 134 | let async_result = match timeout( |
| 135 | GATT_CACHE_TIMEOUT, |
| 136 | service |
| 137 | .GetCharacteristicsWithCacheModeAsync(BluetoothCacheMode::Uncached)? |
| 138 | .into_future(), |
| 139 | ) |
| 140 | .await |
| 141 | { |
| 142 | Ok(result) => result?, |
| 143 | Err(_) => { |
| 144 | warn!("Uncached characteristic discovery timed out, falling back to cached mode"); |
| 145 | service |
| 146 | .GetCharacteristicsWithCacheModeAsync(BluetoothCacheMode::Cached)? |
| 147 | .await? |
| 148 | } |
| 149 | }; |
| 150 | |
| 151 | match async_result.Status() { |
| 152 | Ok(GattCommunicationStatus::Success) => { |
| 153 | let results = async_result.Characteristics()?; |
| 154 | debug!("characteristics {:?}", results.Size()); |
| 155 | Ok(results.into_iter().collect()) |
| 156 | } |
| 157 | Ok(GattCommunicationStatus::ProtocolError) => Err(Error::Other( |
| 158 | format!( |
| 159 | "get_characteristics for {:?} encountered a protocol error", |
| 160 | service |
| 161 | ) |
| 162 | .into(), |
| 163 | )), |
| 164 | Ok(status) => { |
| 165 | debug!("characteristic read failed due to {:?}", status); |
| 166 | Ok(vec![]) |
| 167 | } |
| 168 | Err(e) => Err(Error::Other( |
| 169 | format!("get_characteristics for {:?} failed: {:?}", service, e).into(), |
| 170 | )), |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | pub async fn get_characteristic_descriptors( |
| 175 | characteristic: &GattCharacteristic, |
no test coverage detected