• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace bt::hci_spec {
18 
19 namespace {
20 
21 // The length of a timeslice in the parameters, in milliseconds.
22 constexpr static float kTimesliceMs = 1.25f;
23 
24 }  // namespace
25 
LEConnectionParameters(uint16_t interval,uint16_t latency,uint16_t supervision_timeout)26 LEConnectionParameters::LEConnectionParameters(uint16_t interval,
27                                                uint16_t latency,
28                                                uint16_t supervision_timeout)
29     : interval_(interval),
30       latency_(latency),
31       supervision_timeout_(supervision_timeout) {}
32 
LEConnectionParameters()33 LEConnectionParameters::LEConnectionParameters()
34     : interval_(0), latency_(0), supervision_timeout_(0) {}
35 
operator ==(const hci_spec::LEConnectionParameters & other) const36 bool hci_spec::LEConnectionParameters::operator==(
37     const hci_spec::LEConnectionParameters& other) const {
38   return interval_ == other.interval_ && latency_ == other.latency_ &&
39          supervision_timeout_ == other.supervision_timeout_;
40 }
41 
ToString() const42 std::string hci_spec::LEConnectionParameters::ToString() const {
43   return bt_lib_cpp_string::StringPrintf(
44       "interval: %.2f ms, latency: %.2f ms, timeout: %u ms",
45       static_cast<float>(interval_) * kTimesliceMs,
46       static_cast<float>(latency_) * kTimesliceMs,
47       supervision_timeout_ * 10u);
48 }
49 
LEPreferredConnectionParameters(uint16_t min_interval,uint16_t max_interval,uint16_t max_latency,uint16_t supervision_timeout)50 LEPreferredConnectionParameters::LEPreferredConnectionParameters(
51     uint16_t min_interval,
52     uint16_t max_interval,
53     uint16_t max_latency,
54     uint16_t supervision_timeout)
55     : min_interval_(min_interval),
56       max_interval_(max_interval),
57       max_latency_(max_latency),
58       supervision_timeout_(supervision_timeout) {}
59 
LEPreferredConnectionParameters()60 LEPreferredConnectionParameters::LEPreferredConnectionParameters()
61     : min_interval_(0),
62       max_interval_(0),
63       max_latency_(0),
64       supervision_timeout_(0) {}
65 
operator ==(const LEPreferredConnectionParameters & other) const66 bool LEPreferredConnectionParameters::operator==(
67     const LEPreferredConnectionParameters& other) const {
68   return min_interval_ == other.min_interval_ &&
69          max_interval_ == other.max_interval_ &&
70          max_latency_ == other.max_latency_ &&
71          supervision_timeout_ == other.supervision_timeout_;
72 }
73 
74 }  // namespace bt::hci_spec
75