mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Added data section filter in BLE scanning
PiperOrigin-RevId: 553660098
This commit is contained in:
committed by
Copybara-Service
parent
f18ab07873
commit
5b155f9a4a
@@ -47,6 +47,7 @@
|
||||
#include "winrt/Windows.Devices.Bluetooth.Advertisement.h"
|
||||
#include "winrt/Windows.Devices.Bluetooth.h"
|
||||
#include "winrt/Windows.Foundation.Collections.h"
|
||||
#include "winrt/Windows.Storage.Streams.h" // NOLINT(misc-include-cleaner)
|
||||
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
@@ -68,6 +69,8 @@ using ::winrt::Windows::Devices::Bluetooth::Advertisement::
|
||||
BluetoothLEAdvertisementDataSection;
|
||||
using ::winrt::Windows::Devices::Bluetooth::Advertisement::
|
||||
BluetoothLEAdvertisementDataTypes;
|
||||
using ::winrt::Windows::Devices::Bluetooth::Advertisement::
|
||||
BluetoothLEAdvertisementFilter; // NOLINT(misc-include-cleaner)
|
||||
using ::winrt::Windows::Devices::Bluetooth::Advertisement::
|
||||
BluetoothLEAdvertisementPublisher;
|
||||
using ::winrt::Windows::Devices::Bluetooth::Advertisement::
|
||||
@@ -230,9 +233,19 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
// Active mode indicates that scan request packets will be sent to query for
|
||||
// Scan Response
|
||||
watcher_.ScanningMode(BluetoothLEScanningMode::Active);
|
||||
::winrt::Windows::Devices::Bluetooth::BluetoothSignalStrengthFilter filter;
|
||||
filter.SamplingInterval(TimeSpan(std::chrono::seconds(2)));
|
||||
watcher_.SignalStrengthFilter(filter);
|
||||
|
||||
BluetoothLEAdvertisementDataSection data_section;
|
||||
data_section.DataType(0x16);
|
||||
DataWriter data_writer; // NOLINT(misc-include-cleaner)
|
||||
std::array<char, 16> service_id_data = service_uuid_.data();
|
||||
data_writer.WriteByte(service_id_data[3] & 0xff);
|
||||
data_writer.WriteByte(service_id_data[2] & 0xff);
|
||||
data_section.Data(data_writer.DetachBuffer());
|
||||
BluetoothLEAdvertisement advertisement;
|
||||
advertisement.DataSections().Append(data_section);
|
||||
BluetoothLEAdvertisementFilter advertisement_filter;
|
||||
advertisement_filter.Advertisement(advertisement);
|
||||
watcher_.AdvertisementFilter(advertisement_filter);
|
||||
watcher_.Start();
|
||||
|
||||
is_watcher_started_ = true;
|
||||
|
||||
Reference in New Issue
Block a user