Pixels Plugin for Unity
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
9{
10 class Scanner;
11
18 {
19 uint16_t _companyId{};
20 std::vector<uint8_t> _data{};
21
22 public:
28 uint16_t companyId() const { return _companyId; }
29
35 const std::vector<uint8_t>& data() const { return _data; }
36
37 private:
38 friend Scanner;
39
40 // Initializes a new instance of ManufacturerData with the company id and a WinRT data buffer
41 ManufacturerData(uint16_t companyId, winrt::Windows::Storage::Streams::IBuffer data)
42 : _companyId{ companyId }, _data{ Internal::dataBufferToBytesVector(data) } {}
43 };
44
51 {
52 uint16_t _shortUuid{};
53 std::vector<uint8_t> _data{};
54
55 public:
61 uint16_t shortUuid() const { return _shortUuid; }
62
68 const std::vector<uint8_t>& data() const { return _data; }
69
70 private:
71 friend Scanner;
72
73 // Initializes a new instance of ServiceData with a WinRT data buffer first containing the service short UUID
74 ServiceData(winrt::Windows::Storage::Streams::IBuffer data)
75 : _shortUuid(0), _data{ Internal::dataBufferToBytesVector(data) }
76 {
77 if (_data.size() >= 2)
78 {
79 _shortUuid = _data[0] | ((uint16_t)_data[1] << 8);
80 _data.erase(_data.begin(), _data.begin() + 2);
81 }
82 }
83 };
84
91 {
92 uint8_t _dataType{};
93 std::vector<uint8_t> _data{};
94
95 public:
101 uint8_t dataType() const { return _dataType; }
102
108 const std::vector<uint8_t>& data() const { return _data; }
109
110 private:
111 friend Scanner;
112
113 // Initializes a new instance of AdvertisementData with the advertisement data type and a WinRT data buffer
114 AdvertisementData(uint8_t dataType, winrt::Windows::Storage::Streams::IBuffer data)
115 : _dataType{ dataType }, _data{ Internal::dataBufferToBytesVector(data) } {}
116 };
117
131 {
132 using DateTime = winrt::Windows::Foundation::DateTime;
133
134 DateTime _timestamp{};
135 bluetooth_address_t _address{};
136 std::wstring _name{};
137 bool _isConnectable{};
138 int _rssi{};
139 int _txPowerLevel{};
140 std::vector<winrt::guid> _services{};
141 std::vector<ManufacturerData> _manufacturersData{};
142 std::vector<ServiceData> _servicesData{};
143 std::vector<AdvertisementData> _advertisingData{};
144
145 public:
152 const DateTime& timestamp() const { return _timestamp; }
153
162 bluetooth_address_t address() const{ return _address; }
163
173 const std::wstring& name() const { return _name; }
174
183 bool isConnectable() const { return _isConnectable; }
184
194 int rssi() const { return _rssi; }
195
205 int txPowerLevel() const { return _txPowerLevel; }
206
215 const std::vector<winrt::guid>& services() const { return _services; }
216
225 const std::vector<ManufacturerData>& manufacturersData() const { return _manufacturersData; }
226
235 const std::vector<ServiceData>& servicesData() const { return _servicesData; }
236
245 const std::vector<AdvertisementData>& advertisingData() const { return _advertisingData; }
246
247 private:
248 friend Scanner;
249
251 const DateTime& timestamp,
253 const std::wstring& name,
254 bool isConnectable,
255 int rssi,
256 int txPowerLevel,
257 const std::vector<winrt::guid>& services,
258 const std::vector<ManufacturerData>& manufacturersData,
259 const std::vector<ServiceData>& servicesData,
260 const std::vector<AdvertisementData>& advertisingData)
261 :
262 _timestamp{ timestamp },
263 _address{ address },
264 _name{ name },
265 _isConnectable{ isConnectable },
266 _rssi{ rssi },
267 _txPowerLevel{ txPowerLevel },
268 _services{ services },
269 _manufacturersData{ manufacturersData },
270 _servicesData{ servicesData },
271 _advertisingData{ advertisingData } {}
272
273 ScannedPeripheral(
274 const DateTime& timestamp,
275 const ScannedPeripheral& peripheral,
276 std::wstring& name,
277 int rssi,
278 int txPowerLevel,
279 const std::vector<winrt::guid>& services,
280 const std::vector<ManufacturerData>& manufacturersData,
281 const std::vector<ServiceData>& servicesData,
282 const std::vector<AdvertisementData>& advertisingData)
283 :
284 _timestamp{ timestamp },
285 _address{ peripheral.address() },
286 _name{ name.empty() ? peripheral._name : name },
287 _isConnectable{ peripheral.isConnectable() },
288 _rssi{ rssi },
289 _txPowerLevel{ txPowerLevel },
290 _services{ concat(peripheral._services, services) },
291 _manufacturersData{ concat(peripheral._manufacturersData, manufacturersData) },
292 _servicesData{ concat(peripheral._servicesData, servicesData) },
293 _advertisingData{ concat(peripheral._advertisingData, advertisingData) } {}
294
295 template <typename T>
296 std::vector<T> concat(const std::vector<T> a, const std::vector<T>& b)
297 {
298 std::vector<T> out{ a };
299 out.insert(out.end(), b.begin(), b.end());
300 return out;
301 }
302 };
303}
Stores an advertisement packet data type and it's associated binary data.
Definition ScannedPeripheral.h:91
uint8_t dataType() const
Gets this advertisement packet data type.
Definition ScannedPeripheral.h:101
const std::vector< uint8_t > & data() const
Gets this advertisement packet binary data.
Definition ScannedPeripheral.h:108
Stores a company id and it's associated binary data.
Definition ScannedPeripheral.h:18
const std::vector< uint8_t > & data() const
Gets the binary data associated with the company id.
Definition ScannedPeripheral.h:35
uint16_t companyId() const
Gets the company id.
Definition ScannedPeripheral.h:28
Holds the information from advertisement packet(s) received from a peripheral.
Definition ScannedPeripheral.h:131
const DateTime & timestamp() const
Gets the time at which the last advertisement packet used for initializing this instance was received...
Definition ScannedPeripheral.h:152
int txPowerLevel() const
Gets the received transmit power of the advertisement packet.
Definition ScannedPeripheral.h:205
const std::vector< AdvertisementData > & advertisingData() const
Gets the list of binary advertisement data contained in the advertisement packet(s).
Definition ScannedPeripheral.h:245
const std::vector< winrt::guid > & services() const
Gets the list of services contained in the advertisement packet(s).
Definition ScannedPeripheral.h:215
bool isConnectable() const
Indicates whether the received advertisement is connectable.
Definition ScannedPeripheral.h:183
bluetooth_address_t address() const
Gets the Bluetooth address of the peripheral that send the advertisement packet(s).
Definition ScannedPeripheral.h:162
int rssi() const
Gets the received signal strength indicator (RSSI) value, in dBm, of the advertisement packet.
Definition ScannedPeripheral.h:194
const std::vector< ManufacturerData > & manufacturersData() const
Gets the list of manufacturer data contained in the advertisement packet(s).
Definition ScannedPeripheral.h:225
const std::wstring & name() const
The name of the peripheral as advertised.
Definition ScannedPeripheral.h:173
const std::vector< ServiceData > & servicesData() const
Gets the list of service data contained in the advertisement packet(s).
Definition ScannedPeripheral.h:235
Implements scanning of Bluetooth Low Energy (BLE) peripherals. It stores and notifies of discovered p...
Definition Scanner.h:23
Stores a company id and it's associated binary data.
Definition ScannedPeripheral.h:51
uint16_t shortUuid() const
Gets the service short id (16 bits).
Definition ScannedPeripheral.h:61
const std::vector< uint8_t > & data() const
Gets the binary data associated with the service.
Definition ScannedPeripheral.h:68
A collection of C++ classes that provides a simplified access to Bluetooth Low Energy peripherals.
Definition bletypes.h:36
std::uint64_t bluetooth_address_t
Type for a Bluetooth address.
Definition bletypes.h:54