C/C++ API Reference
Loading...
Searching...
No Matches
peripheral2.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 <cstdint>
17#include <memory>
18
19#include "pw_async2/dispatcher.h"
20#include "pw_async2/once_sender.h"
21#include "pw_bluetooth/internal/raii_ptr.h"
22#include "pw_bluetooth/low_energy/advertising_data.h"
23#include "pw_bluetooth/low_energy/connection2.h"
24#include "pw_bluetooth/low_energy/phy.h"
25#include "pw_bluetooth/types.h"
26#include "pw_function/function.h"
27#include "pw_result/expected.h"
28
29namespace pw::bluetooth::low_energy {
30
32
35 public:
36 virtual ~AdvertisedPeripheral2() = default;
37
54 async2::Context& cx) = 0;
55
60 virtual void StopAdvertising() = 0;
61
71
72 private:
76 virtual void Release() = 0;
77
78 public:
82 using Ptr =
83 internal::RaiiPtr<AdvertisedPeripheral2, &AdvertisedPeripheral2::Release>;
84};
85
88 public:
96 uint16_t min = 0x0800;
98 uint16_t max = 0x0800;
99 };
100
107 using ScanResponse = AdvertisingData;
108
114
119 std::optional<ScanResponse> scan_response;
120
122 std::optional<ConnectionOptions> connection_options;
123 };
124
129 struct Anonymous {};
130
134 std::variant<std::monostate, ScanResponse, ConnectionOptions, Anonymous>
136
140 std::optional<int8_t> tx_power;
141
145 Phy primary_phy = Phy::k1Megabit;
146
150 Phy secondary_phy = Phy::k1Megabit;
151 };
152
153 using AdvertisingProcedure =
154 std::variant<LegacyAdvertising, ExtendedAdvertising>;
155
160 AdvertisingData data;
161
164
169 std::optional<Address::Type> address_type;
170
173 AdvertisingProcedure procedure;
174 };
175
177 enum class AdvertiseError {
180 kNotSupported = 1,
181
185
189
192
196
198 kFailed = 6,
199 };
200
201 using AdvertiseResult =
202 pw::expected<AdvertisedPeripheral2::Ptr, AdvertiseError>;
203
204 virtual ~Peripheral2() = default;
205
222 const AdvertisingParameters& parameters) = 0;
223};
224
225} // namespace pw::bluetooth::low_energy
Definition: context.h:55
Definition: once_sender.h:43
Definition: poll.h:60
AdvertisedPeripheral instances are valid for the duration of advertising.
Definition: peripheral2.h:34
Represents the LE Peripheral role, which advertises and is connected to.
Definition: peripheral2.h:87
uint16_t min
Default: 1.28s.
Definition: peripheral2.h:96
std::variant< std::monostate, ScanResponse, ConnectionOptions, Anonymous > configuration
Definition: peripheral2.h:135
AdvertiseError
Errors returned by Advertise.
Definition: peripheral2.h:177
AdvertisingIntervalRange interval_range
See AdvertisingIntervalRange documentation.
Definition: peripheral2.h:163
AdvertisingData data
Definition: peripheral2.h:160
std::optional< Address::Type > address_type
Definition: peripheral2.h:169
uint16_t max
Default: 1.28s.
Definition: peripheral2.h:98
AdvertisingProcedure procedure
Definition: peripheral2.h:173
virtual async2::Poll< pw::Status > PendStop(async2::Context &cx)=0
std::optional< int8_t > tx_power
Definition: peripheral2.h:140
std::optional< ScanResponse > scan_response
See ScanResponse documentation.
Definition: peripheral2.h:119
virtual async2::Poll< Connection2::Ptr > PendConnection(async2::Context &cx)=0
virtual async2::OnceReceiver< AdvertiseResult > Advertise(const AdvertisingParameters &parameters)=0
std::optional< ConnectionOptions > connection_options
See ConnectionOptions documentation.
Definition: peripheral2.h:122
internal::RaiiPtr< AdvertisedPeripheral2, &AdvertisedPeripheral2::Release > Ptr
Definition: peripheral2.h:83
AdvertisingData ScanResponse
Definition: peripheral2.h:107
@ kInvalidParameters
The requested parameters are invalid.
@ kFailed
Advertising could not be initiated due to a hardware or system error.
Represents parameters that are set on a per-connection basis.
Definition: connection2.h:111
Represents the parameters for configuring advertisements.
Definition: peripheral2.h:157
Anonymous advertisements do not include the address.
Definition: peripheral2.h:129