(&self)
| 190 | } |
| 191 | |
| 192 | async fn discover_services(&self) -> Result<()> { |
| 193 | let mut services_internal = HashMap::new(); |
| 194 | let services = self.session.get_services(&self.device).await?; |
| 195 | for service in services { |
| 196 | let characteristics = self.session.get_characteristics(&service.id).await?; |
| 197 | let characteristics = join_all( |
| 198 | characteristics |
| 199 | .into_iter() |
| 200 | .fold( |
| 201 | // Only consider the first characteristic of each UUID |
| 202 | // This "should" be unique, but of course it's not enforced |
| 203 | HashMap::<Uuid, CharacteristicInfo>::new(), |
| 204 | |mut map, characteristic| { |
| 205 | if !map.contains_key(&characteristic.uuid) { |
| 206 | map.insert(characteristic.uuid, characteristic); |
| 207 | } |
| 208 | map |
| 209 | }, |
| 210 | ) |
| 211 | .into_iter() |
| 212 | .map(|mapped_characteristic| async { |
| 213 | let characteristic = mapped_characteristic.1; |
| 214 | let descriptors = self |
| 215 | .session |
| 216 | .get_descriptors(&characteristic.id) |
| 217 | .await |
| 218 | .unwrap_or(Vec::new()) |
| 219 | .into_iter() |
| 220 | .map(|descriptor| (descriptor.uuid, descriptor)) |
| 221 | .collect(); |
| 222 | CharacteristicInternal::new(characteristic, descriptors) |
| 223 | }), |
| 224 | ) |
| 225 | .await; |
| 226 | services_internal.insert( |
| 227 | service.uuid, |
| 228 | ServiceInternal { |
| 229 | info: service, |
| 230 | characteristics: characteristics |
| 231 | .into_iter() |
| 232 | .map(|characteristic| (characteristic.info.uuid, characteristic)) |
| 233 | .collect(), |
| 234 | }, |
| 235 | ); |
| 236 | } |
| 237 | *(self.services.lock().map_err(Into::<Error>::into)?) = services_internal; |
| 238 | Ok(()) |
| 239 | } |
| 240 | |
| 241 | async fn write( |
| 242 | &self, |
nothing calls this directly
no test coverage detected