C++ Pixels Library For Windows
Enable communications with Pixels dice using Bluetooth Low Energy.
Loading...
Searching...
No Matches
ScannedPeripheral.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "BleTypes.h"
9
11{
12 class Scanner;
13
20 {
21 uint16_t _companyId{};
22 std::vector<uint8_t> _data{};
23
24 public:
30 uint16_t companyId() const { return _companyId; }
31
37 const std::vector<uint8_t>& data() const { return _data; }
38
39 private:
40 friend Scanner;
41
42 // Initializes a new instance of ManufacturerData with the company id and a WinRT data buffer
43 ManufacturerData(uint16_t companyId, winrt::Windows::Storage::Streams::IBuffer data)
44 : _companyId{ companyId }, _data{ Internal::dataBufferToBytesVector(data) } {}
45 };
46
53 {
54 uint16_t _shortUuid{};
55 std::vector<uint8_t> _data{};
56
57 public:
63 uint16_t shortUuid() const { return _shortUuid; }
64
70 const std::vector<uint8_t>& data() const { return _data; }
71
72 private:
73 friend Scanner;
74
75 // Initializes a new instance of ServiceData with a WinRT data buffer first containing the service short UUID
76 ServiceData(winrt::Windows::Storage::Streams::IBuffer data)
77 : _shortUuid(0), _data{ Internal::dataBufferToBytesVector(data) }
78 {
79 if (_data.size() >= 2)
80 {
81 _shortUuid = _data[0] | ((uint16_t)_data[1] << 8);
82 _data.erase(_data.begin(), _data.begin() + 2);
83 }
84 }
85 };
86
93 {
94 uint8_t _dataType{};
95 std::vector<uint8_t> _data{};
96
97 public:
103 uint8_t dataType() const { return _dataType; }
104
110 const std::vector<uint8_t>& data() const { return _data; }
111
112 private:
113 friend Scanner;
114
115 // Initializes a new instance of AdvertisementData with the advertisement data type and a WinRT data buffer
116 AdvertisementData(uint8_t dataType, winrt::Windows::Storage::Streams::IBuffer data)
117 : _dataType{ dataType }, _data{ Internal::dataBufferToBytesVector(data) } {}
118 };
119
133 {
134 using DateTime = winrt::Windows::Foundation::DateTime;
135
136 DateTime _timestamp{};
137 bluetooth_address_t _address{};
138 std::wstring _name{};
139 bool _isConnectable{};
140 int _rssi{};
141 int _txPowerLevel{};
142 std::vector<winrt::guid> _services{};
143 std::vector<ManufacturerData> _manufacturersData{};
144 std::vector<ServiceData> _servicesData{};
145 std::vector<AdvertisementData> _advertisingData{};
146
147 public:
154 const DateTime& timestamp() const { return _timestamp; }
155
164 bluetooth_address_t address() const { return _address; }
165
175 const std::wstring& name() const { return _name; }
176
185 bool isConnectable() const { return _isConnectable; }
186
196 int rssi() const { return _rssi; }
197
207 int txPowerLevel() const { return _txPowerLevel; }
208
217 const std::vector<winrt::guid>& services() const { return _services; }
218
227 const std::vector<ManufacturerData>& manufacturersData() const { return _manufacturersData; }
228
237 const std::vector<ServiceData>& servicesData() const { return _servicesData; }
238
247 const std::vector<AdvertisementData>& advertisingData() const { return _advertisingData; }
248
249 private:
250 friend Scanner;
251
253 const DateTime& timestamp,
255 const std::wstring& name,
256 bool isConnectable,
257 int rssi,
258 int txPowerLevel,
259 const std::vector<winrt::guid>& services,
260 const std::vector<ManufacturerData>& manufacturersData,
261 const std::vector<ServiceData>& servicesData,
262 const std::vector<AdvertisementData>& advertisingData)
263 :
264 _timestamp{ timestamp },
265 _address{ address },
266 _name{ name },
267 _isConnectable{ isConnectable },
268 _rssi{ rssi },
269 _txPowerLevel{ txPowerLevel },
270 _services{ services },
271 _manufacturersData{ manufacturersData },
272 _servicesData{ servicesData },
273 _advertisingData{ advertisingData } {}
274
275 ScannedPeripheral(
276 const DateTime& timestamp,
277 const ScannedPeripheral& peripheral,
278 std::wstring& name,
279 int rssi,
280 int txPowerLevel,
281 const std::vector<winrt::guid>& services,
282 const std::vector<ManufacturerData>& manufacturersData,
283 const std::vector<ServiceData>& servicesData,
284 const std::vector<AdvertisementData>& advertisingData)
285 :
286 _timestamp{ timestamp },
287 _address{ peripheral.address() },
288 _name{ name.empty() ? peripheral._name : name },
289 _isConnectable{ peripheral.isConnectable() },
290 _rssi{ rssi },
291 _txPowerLevel{ txPowerLevel },
292 _services{ concat(peripheral._services, services) },
293 _manufacturersData{ concat(peripheral._manufacturersData, manufacturersData) },
294 _servicesData{ concat(peripheral._servicesData, servicesData) },
295 _advertisingData{ concat(peripheral._advertisingData, advertisingData) } {}
296
297 template <typename T>
298 std::vector<T> concat(const std::vector<T> a, const std::vector<T>& b)
299 {
300 std::vector<T> out{ a };
301 out.insert(out.end(), b.begin(), b.end());
302 return out;
303 }
304 };
305}
Common types used across the Systemic::BluetoothLE namespace.
Stores an advertisement packet data type and it's associated binary data.
Definition: ScannedPeripheral.h:93
uint8_t dataType() const
Gets this advertisement packet data type.
Definition: ScannedPeripheral.h:103
const std::vector< uint8_t > & data() const
Gets this advertisement packet binary data.
Definition: ScannedPeripheral.h:110
Stores a company id and it's associated binary data.
Definition: ScannedPeripheral.h:20
const std::vector< uint8_t > & data() const
Gets the binary data associated with the company id.
Definition: ScannedPeripheral.h:37
uint16_t companyId() const
Gets the company id.
Definition: ScannedPeripheral.h:30
Holds the information from advertisement packet(s) received from a peripheral.
Definition: ScannedPeripheral.h:133
const DateTime & timestamp() const
Gets the time at which the last advertisement packet used for initializing this instance was received...
Definition: ScannedPeripheral.h:154
int txPowerLevel() const
Gets the received transmit power of the advertisement packet.
Definition: ScannedPeripheral.h:207
const std::vector< AdvertisementData > & advertisingData() const
Gets the list of binary advertisement data contained in the advertisement packet(s).
Definition: ScannedPeripheral.h:247
const std::vector< winrt::guid > & services() const
Gets the list of services contained in the advertisement packet(s).
Definition: ScannedPeripheral.h:217
bool isConnectable() const
Indicates whether the received advertisement is connectable.
Definition: ScannedPeripheral.h:185
bluetooth_address_t address() const
Gets the Bluetooth address of the peripheral that send the advertisement packet(s).
Definition: ScannedPeripheral.h:164
int rssi() const
Gets the received signal strength indicator (RSSI) value, in dBm, of the advertisement packet.
Definition: ScannedPeripheral.h:196
const std::vector< ManufacturerData > & manufacturersData() const
Gets the list of manufacturer data contained in the advertisement packet(s).
Definition: ScannedPeripheral.h:227
const std::wstring & name() const
The name of the peripheral as advertised.
Definition: ScannedPeripheral.h:175
const std::vector< ServiceData > & servicesData() const
Gets the list of service data contained in the advertisement packet(s).
Definition: ScannedPeripheral.h:237
Implements scanning of Bluetooth Low Energy (BLE) peripherals. It stores and notifies of discovered p...
Definition: Scanner.h:21
Stores a company id and it's associated binary data.
Definition: ScannedPeripheral.h:53
uint16_t shortUuid() const
Gets the service short id (16 bits).
Definition: ScannedPeripheral.h:63
const std::vector< uint8_t > & data() const
Gets the binary data associated with the service.
Definition: ScannedPeripheral.h:70
A collection of C++ classes that provides a simplified access to Bluetooth Low Energy peripherals.
Definition: BleTypes.h:38
std::uint64_t bluetooth_address_t
Type for a Bluetooth address.
Definition: BleTypes.h:40