Pigweed
 
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
33 public:
34 virtual ~AdvertisedPeripheral2() = default;
35
52 async2::Context& cx) = 0;
53
58 virtual void StopAdvertising() = 0;
59
75
76 private:
80 virtual void Release() = 0;
81
82 public:
86 using Ptr =
87 internal::RaiiPtr<AdvertisedPeripheral2, &AdvertisedPeripheral2::Release>;
88};
89
92 public:
100 uint16_t min = 0x0800;
102 uint16_t max = 0x0800;
103 };
104
111 using ScanResponse = AdvertisingData;
112
118
123 std::optional<ScanResponse> scan_response;
124
126 std::optional<ConnectionOptions> connection_options;
127 };
128
133 struct Anonymous {};
134
138 std::variant<std::monostate, ScanResponse, ConnectionOptions, Anonymous>
140
144 std::optional<int8_t> tx_power;
145
149 Phy primary_phy = Phy::k1Megabit;
150
154 Phy secondary_phy = Phy::k1Megabit;
155 };
156
157 using AdvertisingProcedure =
158 std::variant<LegacyAdvertising, ExtendedAdvertising>;
159
164 AdvertisingData data;
165
168
173 std::optional<Address::Type> address_type;
174
177 AdvertisingProcedure procedure;
178 };
179
181 enum class AdvertiseError {
184 kNotSupported = 1,
185
189
193
196
200
202 kFailed = 6,
203 };
204
205 using AdvertiseResult =
206 pw::expected<AdvertisedPeripheral2::Ptr, AdvertiseError>;
207
208 virtual ~Peripheral2() = default;
209
226 const AdvertisingParameters& parameters) = 0;
227};
228
229} // namespace pw::bluetooth::low_energy
Definition: dispatcher_base.h:52
Definition: once_sender.h:41
Definition: poll.h:54
AdvertisedPeripheral instances are valid for the duration of advertising.
Definition: peripheral2.h:32
virtual async2::Poll< pw::Status > PendStop(async2::Context &cx)=0
virtual async2::Poll< Connection2::Ptr > PendConnection(async2::Context &cx)=0
internal::RaiiPtr< AdvertisedPeripheral2, &AdvertisedPeripheral2::Release > Ptr
Definition: peripheral2.h:87
Represents the LE Peripheral role, which advertises and is connected to.
Definition: peripheral2.h:91
AdvertiseError
Errors returned by Advertise.
Definition: peripheral2.h:181
@ kInvalidParameters
The requested parameters are invalid.
@ kFailed
Advertising could not be initiated due to a hardware or system error.
virtual async2::OnceReceiver< AdvertiseResult > Advertise(const AdvertisingParameters &parameters)=0
AdvertisingData ScanResponse
Definition: peripheral2.h:111
Represents parameters that are set on a per-connection basis.
Definition: connection2.h:109
uint16_t min
Default: 1.28s.
Definition: peripheral2.h:100
uint16_t max
Default: 1.28s.
Definition: peripheral2.h:102
Represents the parameters for configuring advertisements.
Definition: peripheral2.h:161
AdvertisingIntervalRange interval_range
See AdvertisingIntervalRange documentation.
Definition: peripheral2.h:167
AdvertisingData data
Definition: peripheral2.h:164
std::optional< Address::Type > address_type
Definition: peripheral2.h:173
AdvertisingProcedure procedure
Definition: peripheral2.h:177
Anonymous advertisements do not include the address.
Definition: peripheral2.h:133
std::variant< std::monostate, ScanResponse, ConnectionOptions, Anonymous > configuration
Definition: peripheral2.h:139
std::optional< int8_t > tx_power
Definition: peripheral2.h:144
std::optional< ScanResponse > scan_response
See ScanResponse documentation.
Definition: peripheral2.h:123
std::optional< ConnectionOptions > connection_options
See ConnectionOptions documentation.
Definition: peripheral2.h:126