1#ifndef BLUETOE_CLIENT_CHARACTERISTIC_CONFIGURATION_HPP
2#define BLUETOE_CLIENT_CHARACTERISTIC_CONFIGURATION_HPP
16 class client_characteristic_configuration
19 constexpr client_characteristic_configuration()
24 constexpr explicit client_characteristic_configuration( std::uint8_t* data, std::size_t )
29 std::uint16_t flags( std::size_t index )
const
33 return ( data_[ index / 4 ] >> shift( index ) ) & 0x3;
36 void flags( std::size_t index, std::uint16_t new_flags )
41 data_[ index / 4 ] = ( data_[ index / 4 ] & ~mask( index ) ) | ( ( new_flags & 0x03 ) << shift( index ) );
44 static constexpr std::size_t bits_per_config = 2;
47 static constexpr std::size_t shift( std::size_t index )
49 return ( index % 4 ) * bits_per_config;
52 static constexpr std::uint8_t mask( std::size_t index )
54 return 0x03 << shift( index );
65 template < std::
size_t Size >
66 class client_characteristic_configurations
73 static constexpr std::size_t number_of_characteristics_with_configuration = Size;
75 client_characteristic_configurations()
77 std::fill( std::begin( configs_ ), std::end( configs_ ), 0 );
80 client_characteristic_configuration client_configurations()
82 return client_characteristic_configuration( &configs_[ 0 ], Size );
90 const std::uint8_t* serialized_cccds_begin()
const
92 return std::begin( configs_ );
100 const std::uint8_t* serialized_cccds_end()
const
102 return std::end( configs_ );
110 std::uint8_t* serialized_cccds_begin()
112 return std::begin( configs_ );
120 std::uint8_t* serialized_cccds_end()
122 return std::end( configs_ );
126 std::uint8_t configs_[ ( Size * client_characteristic_configuration::bits_per_config + 7 ) / 8 ];
130 class client_characteristic_configurations< 0 >
133 client_characteristic_configuration client_configurations()
135 return client_characteristic_configuration();