1#ifndef BLUETOE_LINK_LAYER_OPTIONS_HPP
2#define BLUETOE_LINK_LAYER_OPTIONS_HPP
4#include <bluetoe/address.hpp>
5#include <bluetoe/connection_details.hpp>
6#include <bluetoe/ll_meta_types.hpp>
14 struct device_address_meta_type {};
15 struct buffer_sizes_meta_type {};
16 struct desired_connection_parameters_meta_type {};
38 template <
class Radio >
46 details::device_address_meta_type,
47 details::valid_link_layer_option_meta_type {};
56 template < std::u
int8_t A, std::u
int8_t B, std::u
int8_t C, std::u
int8_t D, std::u
int8_t E, std::u
int8_t F >
70 template <
class Radio >
73 static constexpr std::uint8_t addr[] = { F, E, D, C, B, A };
74 return ::bluetoe::link_layer::random_device_address( addr );
79 details::device_address_meta_type,
80 details::valid_link_layer_option_meta_type {};
85 struct sleep_clock_accuracy_meta_type {};
87 template <
unsigned long long SleepClockAccuracyPPM >
88 struct check_sleep_clock_accuracy_ppm {
89 static_assert( SleepClockAccuracyPPM <= 500,
"The highest, possible sleep clock accuracy is 500ppm." );
104 template < unsigned long long SleepClockAccuracyPPM, typename = typename details::check_sleep_clock_accuracy_ppm< SleepClockAccuracyPPM >::type >
110 static constexpr unsigned accuracy_ppm =
static_cast< unsigned >( SleepClockAccuracyPPM );
114 details::sleep_clock_accuracy_meta_type,
115 details::valid_link_layer_option_meta_type {};
122 template < std::
size_t TransmitSize = 61, std::
size_t ReceiveSize = 61 >
127 details::buffer_sizes_meta_type,
128 details::valid_link_layer_option_meta_type {};
144 struct desired_connection_parameters_base
146 static constexpr std::size_t size = 24;
147 static constexpr std::uint8_t ll_control_pdu_code = 3;
148 static constexpr std::uint8_t LL_CONNECTION_PARAM_RSP = 0x10;
164 std::uint16_t Interval_min,
165 std::uint16_t Interval_max,
166 std::uint16_t Latency_min,
167 std::uint16_t Latency_max,
168 std::uint16_t Timeout_min,
169 std::uint16_t Timeout_max >
174 details::desired_connection_parameters_meta_type,
175 details::valid_link_layer_option_meta_type {};
177 template <
class Layout >
178 static void fill_response(
181 const std::uint8_t*
const body = Layout::body( request ).first;
182 std::uint8_t*
const write_body = Layout::body( response ).first;
184 using bluetoe::details::read_16bit;
186 std::uint16_t min_interval = std::max( read_16bit( body + 1 ), Interval_min );
187 std::uint16_t max_interval = std::min( read_16bit( body + 3 ), Interval_max );
188 std::uint16_t latency = read_16bit( body + 5 );
189 std::uint16_t timeout = read_16bit( body + 7 );
191 if ( min_interval > max_interval )
193 min_interval = Interval_min;
194 max_interval = Interval_max;
197 if ( latency < Latency_min || latency > Latency_max )
199 latency = ( Latency_min + Latency_max ) / 2;
202 if ( timeout < Timeout_min || timeout > Timeout_max )
204 timeout = ( Timeout_min + Timeout_max ) / 2;
207 fill< Layout >( response, {
208 ll_control_pdu_code, size,
209 LL_CONNECTION_PARAM_RSP,
210 static_cast< std::uint8_t
>( min_interval ),
211 static_cast< std::uint8_t
>( min_interval >> 8 ),
212 static_cast< std::uint8_t
>( max_interval ),
213 static_cast< std::uint8_t
>( max_interval >> 8 ),
214 static_cast< std::uint8_t
>( latency ),
215 static_cast< std::uint8_t
>( latency >> 8 ),
216 static_cast< std::uint8_t
>( timeout ),
217 static_cast< std::uint8_t
>( timeout >> 8 )
220 std::copy( &body[ 9 ], &body[ size ], &write_body[ 9 ] );
226 struct no_desired_connection_parameters :
private details::desired_connection_parameters_base
229 details::desired_connection_parameters_meta_type,
230 details::valid_link_layer_option_meta_type {};
232 template <
class Layout >
233 static void fill_response(
234 const write_buffer& request, read_buffer response )
236 const std::uint8_t*
const body = Layout::body( request ).first;
237 std::uint8_t*
const write_body = Layout::body( response ).first;
239 fill< Layout >( response, { ll_control_pdu_code, size, LL_CONNECTION_PARAM_RSP } );
241 std::copy( &body[ 1 ], &body[ 1 + size - 1 ], &write_body[ 1 ] );
static random_device_address generate_static_random_address(std::uint32_t seed)
generates a valid static random address out of a given seed value
data type containing a random device address
Definition: address.hpp:244
defines link layer transmit and receive buffer sizes
Definition: ll_options.hpp:124
static constexpr std::size_t transmit_buffer_size
Definition: ll_options.hpp:134
static constexpr std::size_t receive_buffer_size
Definition: ll_options.hpp:139
static, desired connection parameters
Definition: ll_options.hpp:171
defines that the device will use a static random address.
Definition: ll_options.hpp:26
static constexpr bool is_random()
returns true, because this is a random address
Definition: ll_options.hpp:30
static random_device_address address(const Radio &r)
takes a scheduled radio and generates a random static address
Definition: ll_options.hpp:39
type suitable to store the location and size of a chunk of memory that can be used to receive from th...
Definition: buffer.hpp:18
defines the sleep clock accuracy of the device hardware.
Definition: ll_options.hpp:106
static constexpr unsigned accuracy_ppm
configured sleep clock accuracy
Definition: ll_options.hpp:110
defines a defined static random address
Definition: ll_options.hpp:58
static constexpr bool is_random()
returns true, because this is a random address
Definition: ll_options.hpp:62
static random_device_address address(const Radio &)
returns the static, configured address A:B:C:D:E:F
Definition: ll_options.hpp:71
type suitable to store the location and size of a chunk of memory that can be used to transmit to the...
Definition: buffer.hpp:85