C/C++ API Reference
Loading...
Searching...
No Matches
central2.h
1// Copyright 2024 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include <optional>
17
18#include "pw_async2/once_sender.h"
19#include "pw_bluetooth/internal/raii_ptr.h"
20#include "pw_bluetooth/low_energy/connection2.h"
21#include "pw_bluetooth/low_energy/phy.h"
22#include "pw_bluetooth/types.h"
23#include "pw_chrono/system_clock.h"
24#include "pw_result/expected.h"
25
26namespace pw::bluetooth::low_energy {
27
29
31class Central2 {
32 public:
35 struct ScanFilter {
37 std::optional<Uuid> service_uuid;
38
40 std::optional<Uuid> service_data_uuid;
41
48 std::optional<uint16_t> manufacturer_id;
49
54 std::optional<bool> connectable;
55
59 std::optional<std::string_view> name;
60
72 std::optional<int8_t> max_path_loss;
73
75 std::optional<Uuid> solicitation_uuid;
76 };
77
78 enum class ScanType : uint8_t {
79 kPassive,
86 };
87
89 struct ScanOptions {
96
100 uint16_t interval;
101
106 uint16_t window;
107
111
114 Phy phys = Phy::k1Megabit;
115 };
116
117 struct ScanResult {
119 PeerId peer_id;
120
124
131 std::optional<uint8_t> rssi;
132
135
141 std::optional<InlineString<22>> name;
142
144 chrono::SystemClock::time_point last_updated;
145 };
146
149 public:
151 virtual ~ScanHandle() = default;
152
166
167 private:
170 virtual void Release() = 0;
171
172 public:
175 using Ptr = internal::RaiiPtr<ScanHandle, &ScanHandle::Release>;
176 };
177
179 enum class ConnectError : uint8_t {
182
185
188
193 };
194
195 enum class StartScanError : uint8_t {
201 kInternal,
202 };
203
205 using ConnectResult = pw::expected<Connection2::Ptr, ConnectError>;
206
208 using ScanStartResult = pw::expected<ScanHandle::Ptr, StartScanError>;
209
210 virtual ~Central2() = default;
211
228 PeerId peer_id, Connection2::ConnectionOptions options) = 0;
229
245 const ScanOptions& options) = 0;
246};
247
248} // namespace pw::bluetooth::low_energy
Definition: context.h:55
Definition: once_sender.h:43
Definition: poll.h:60
Represents an ongoing LE scan.
Definition: central2.h:148
Represents the LE central role. Used to scan and connect to peripherals.
Definition: central2.h:31
Definition: multibuf_v1.h:248
Definition: span_impl.h:235
PeerId peer_id
Uniquely identifies this peer on the current system.
Definition: central2.h:119
virtual async2::OnceReceiver< ConnectResult > Connect(PeerId peer_id, Connection2::ConnectionOptions options)=0
ScanType
Definition: central2.h:78
pw::span< const ScanFilter > filters
Definition: central2.h:95
virtual ~ScanHandle()=default
Stops the scan.
std::optional< Uuid > service_data_uuid
Filter based on service data containing the given UUID.
Definition: central2.h:40
std::optional< Uuid > service_uuid
Filter based on advertised service UUID.
Definition: central2.h:37
std::optional< Uuid > solicitation_uuid
Require that a peer solicits support for a service UUID.
Definition: central2.h:75
std::optional< uint16_t > manufacturer_id
Definition: central2.h:48
uint16_t window
Definition: central2.h:106
virtual async2::PollResult< ScanResult > PendResult(async2::Context &cx)=0
ConnectError
Possible errors returned by Connect.
Definition: central2.h:179
bool connectable
Definition: central2.h:123
pw::expected< ScanHandle::Ptr, StartScanError > ScanStartResult
The result type returned by Scan().
Definition: central2.h:208
virtual async2::OnceReceiver< ScanStartResult > Scan(const ScanOptions &options)=0
chrono::SystemClock::time_point last_updated
Timestamp of when the information in this ScanResult was last updated.
Definition: central2.h:144
std::optional< bool > connectable
Definition: central2.h:54
pw::expected< Connection2::Ptr, ConnectError > ConnectResult
The result type returned by Connect().
Definition: central2.h:205
std::optional< int8_t > max_path_loss
Definition: central2.h:72
internal::RaiiPtr< ScanHandle, &ScanHandle::Release > Ptr
Definition: central2.h:175
uint16_t interval
Definition: central2.h:100
pw::multibuf::MultiBuf data
This contains the advertising data last received from the peer.
Definition: central2.h:134
StartScanError
Definition: central2.h:195
std::optional< InlineString< 22 > > name
Definition: central2.h:141
std::optional< uint8_t > rssi
Definition: central2.h:131
ScanType scan_type
Definition: central2.h:110
std::optional< std::string_view > name
Definition: central2.h:59
@ kActiveUseRandomAddress
Send scanning PDUs with the random address.
@ kActiveUsePublicAddress
Send scanning PDUs with the public address.
@ kActiveUseResolvablePrivateAddress
Send scanning PDUs with a generated Resolvable Private Address.
@ kInvalidOptions
The ConnectionOptions were invalid.
@ kAlreadyExists
A connection to the peer already exists.
@ kInvalidParameters
Some of the scan options are invalid.
@ kScanInProgress
A scan is already in progress. Only 1 scan may be active at a time.
@ kInternal
An internal error occurred and a scan could not be started.
Parameters used during a scan.
Definition: central2.h:89
Represents parameters that are set on a per-connection basis.
Definition: connection2.h:111