1 // Copyright 2023 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
15 #include "pw_bluetooth_sapphire/internal/host/hci-spec/le_connection_parameters.h"
16
17 #include <cpp-string/string_printf.h>
18
19 namespace bt::hci_spec {
20
21 namespace {
22
23 // The length of a timeslice in the parameters, in milliseconds.
24 constexpr static float kTimesliceMs = 1.25f;
25
26 } // namespace
27
LEConnectionParameters(uint16_t interval,uint16_t latency,uint16_t supervision_timeout)28 LEConnectionParameters::LEConnectionParameters(uint16_t interval,
29 uint16_t latency,
30 uint16_t supervision_timeout)
31 : interval_(interval),
32 latency_(latency),
33 supervision_timeout_(supervision_timeout) {}
34
LEConnectionParameters()35 LEConnectionParameters::LEConnectionParameters()
36 : interval_(0), latency_(0), supervision_timeout_(0) {}
37
operator ==(const hci_spec::LEConnectionParameters & other) const38 bool hci_spec::LEConnectionParameters::operator==(
39 const hci_spec::LEConnectionParameters& other) const {
40 return interval_ == other.interval_ && latency_ == other.latency_ &&
41 supervision_timeout_ == other.supervision_timeout_;
42 }
43
ToString() const44 std::string hci_spec::LEConnectionParameters::ToString() const {
45 return bt_lib_cpp_string::StringPrintf(
46 "interval: %.2f ms, latency: %.2f ms, timeout: %u ms",
47 static_cast<float>(interval_) * kTimesliceMs,
48 static_cast<float>(latency_) * kTimesliceMs,
49 supervision_timeout_ * 10u);
50 }
51
LEPreferredConnectionParameters(uint16_t min_interval,uint16_t max_interval,uint16_t max_latency,uint16_t supervision_timeout)52 LEPreferredConnectionParameters::LEPreferredConnectionParameters(
53 uint16_t min_interval,
54 uint16_t max_interval,
55 uint16_t max_latency,
56 uint16_t supervision_timeout)
57 : min_interval_(min_interval),
58 max_interval_(max_interval),
59 max_latency_(max_latency),
60 supervision_timeout_(supervision_timeout) {}
61
LEPreferredConnectionParameters()62 LEPreferredConnectionParameters::LEPreferredConnectionParameters()
63 : min_interval_(0),
64 max_interval_(0),
65 max_latency_(0),
66 supervision_timeout_(0) {}
67
operator ==(const LEPreferredConnectionParameters & other) const68 bool LEPreferredConnectionParameters::operator==(
69 const LEPreferredConnectionParameters& other) const {
70 return min_interval_ == other.min_interval_ &&
71 max_interval_ == other.max_interval_ &&
72 max_latency_ == other.max_latency_ &&
73 supervision_timeout_ == other.supervision_timeout_;
74 }
75
76 } // namespace bt::hci_spec
77