[fp-rs] Updating Fast Pair Seeker to filter out non-FP advertisements.

This commit is contained in:
Lucas Silva Shepard
2023-07-29 17:18:46 -07:00
parent 81592cc4c5
commit 7730a0f1db
+26 -19
View File
@@ -28,34 +28,41 @@ fn main() -> Result<(), Box<dyn Error>> {
while let Ok(ble_device) = adapter.next_device().await {
let name = ble_device.name()?;
if name.contains("LE_WF-1000XM3") {
println!("FOUND {} ", name);
for service_data in ble_device.service_data() {
let uuid = service_data.uuid();
let addr: Address = ble_device.address();
// This is a Fast Pair device.
if uuid == 0x2cfe {
if name.contains("LE_WF-1000XM3") {
println!("FOUND {} ", name);
// Dynamic dispatch is necessary here because `BleDevice` and
// `ClassicDevice` share the `Device` trait (and thus must have
// the same return type for `address()` method). This can be
// changed later if `Device` trait should exclusively define
// shared cross-platform behavior.
let classic_addr = match addr {
Address::Ble(ble) => ClassicAddress::try_from(ble),
Address::Classic(_) => unreachable!(
let addr: Address = ble_device.address();
// Dynamic dispatch is necessary here because `BleDevice` and
// `ClassicDevice` share the `Device` trait (and thus must have
// the same return type for `address()` method). This can be
// changed later if `Device` trait should exclusively define
// shared cross-platform behavior.
let classic_addr = match addr {
Address::Ble(ble) => ClassicAddress::try_from(ble),
Address::Classic(_) => panic!(
"Address should come from BLE Device, therefore \
shouldn't be Classic."
),
}?;
}?;
let classic_device =
bluetooth::new_classic_device(classic_addr).await?;
let classic_device =
bluetooth::new_classic_device(classic_addr).await?;
match classic_device.pair().await {
Ok(_) => {
println!("Pairing success!");
match classic_device.pair().await {
Ok(_) => {
println!("Pairing success!");
}
Err(err) => println!("Error {}", err),
}
break;
}
Err(err) => println!("Error {}", err),
}
break;
}
}
println!("Done scanning");