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
77
78 private:
82 virtual void Release() = 0;
83
84 public:
88 using Ptr =
89 internal::RaiiPtr<AdvertisedPeripheral2, &AdvertisedPeripheral2::Release>;
90};
91
94 public:
102 uint16_t min = 0x0800;
104 uint16_t max = 0x0800;
105 };
106
113 using ScanResponse = AdvertisingData;
114
120
125 std::optional<ScanResponse> scan_response;
126
128 std::optional<ConnectionOptions> connection_options;
129 };
130
135 struct Anonymous {};
136
140 std::variant<std::monostate, ScanResponse, ConnectionOptions, Anonymous>
142
146 std::optional<int8_t> tx_power;
147
151 Phy primary_phy = Phy::k1Megabit;
152
156 Phy secondary_phy = Phy::k1Megabit;
157 };
158
159 using AdvertisingProcedure =
160 std::variant<LegacyAdvertising, ExtendedAdvertising>;
161
166 AdvertisingData data;
167
170
175 std::optional<Address::Type> address_type;
176
179 AdvertisingProcedure procedure;
180 };
181
183 enum class AdvertiseError {
186 kNotSupported = 1,
187
191
195
198
202
204 kFailed = 6,
205 };
206
207 using AdvertiseResult =
208 pw::expected<AdvertisedPeripheral2::Ptr, AdvertiseError>;
209
210 virtual ~Peripheral2() = default;
211
228 const AdvertisingParameters& parameters) = 0;
229};
230
231} // 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:93
uint16_t min
Default: 1.28s.
Definition: peripheral2.h:102
std::variant< std::monostate, ScanResponse, ConnectionOptions, Anonymous > configuration
Definition: peripheral2.h:141
AdvertiseError
Errors returned by Advertise.
Definition: peripheral2.h:183
AdvertisingIntervalRange interval_range
See AdvertisingIntervalRange documentation.
Definition: peripheral2.h:169
AdvertisingData data
Definition: peripheral2.h:166
std::optional< Address::Type > address_type
Definition: peripheral2.h:175
uint16_t max
Default: 1.28s.
Definition: peripheral2.h:104
AdvertisingProcedure procedure
Definition: peripheral2.h:179
virtual async2::Poll< pw::Status > PendStop(async2::Context &cx)=0
std::optional< int8_t > tx_power
Definition: peripheral2.h:146
std::optional< ScanResponse > scan_response
See ScanResponse documentation.
Definition: peripheral2.h:125
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:128
internal::RaiiPtr< AdvertisedPeripheral2, &AdvertisedPeripheral2::Release > Ptr
Definition: peripheral2.h:89
AdvertisingData ScanResponse
Definition: peripheral2.h:113
@ 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:163
Anonymous advertisements do not include the address.
Definition: peripheral2.h:135