1#ifndef BLUTOE_SERVICES_BAS_HPP
3#include <bluetoe/service.hpp>
4#include <bluetoe/mixin.hpp>
14 using service_uuid = service_uuid16< 0x180F >;
19 using level_uuid = characteristic_uuid16< 0x2A19 >;
23 struct handler_tag {};
24 struct no_battery_level_notifications_tag {};
25 struct valid_bas_service_option_tag {};
27 template <
typename Handler >
30 struct read_handler : bluetoe::details::value_handler_base
32 template <
class Server >
33 static std::uint8_t call_read_handler( std::size_t offset, std::size_t, std::uint8_t* out_buffer, std::size_t& out_size,
void* server )
38 Handler& handler =
static_cast< Handler&
>( *
static_cast< Server*
>( server ) );
40 const int value = handler.read_battery_level();
44 *out_buffer =
static_cast< std::uint8_t
>( value );
51 bluetoe::details::value_handler_base::meta_type,
52 bluetoe::details::characteristic_value_read_handler_meta_type {};
55 template <
typename Server >
56 void notifiy_battery_level( Server& srv )
58 srv.template notify< level_uuid >();
62 template <
typename,
typename >
65 template <
typename Handler,
typename ... Options >
66 struct service_impl< Handler, std::tuple< Options... > >
73 typename handler_impl< Handler >::read_handler,
83 template <
typename ... Options >
84 struct calculate_service {
85 using handler =
typename bluetoe::details::find_by_meta_type< handler_tag, Options... >::type;
87 static_assert( !std::is_same< handler, bluetoe::details::no_such_type >::value,
"bas::handler<> is required" );
89 using other_args =
typename bluetoe::details::find_all_by_not_meta_type<
90 details::valid_bas_service_option_tag, Options... >::type;
92 using type =
typename service_impl< typename handler::type, other_args >::type;
107 struct meta_type : details::no_battery_level_notifications_tag
108 , details::valid_bas_service_option_tag {};
123 template <
typename Handler >
126 using type = Handler;
128 struct meta_type : details::handler_tag
129 , details::valid_bas_service_option_tag {};
149 template <
typename ... Options >
150 using battery_level =
typename bas::details::calculate_service< Options... >::type;
A characteristic is a typed value that is accessable by a GATT client hosted by a GATT server.
Definition: characteristic.hpp:160
a service with zero or more characteristics
Definition: service.hpp:150
@ success
Definition: codes.hpp:154
@ attribute_not_long
Definition: codes.hpp:209
pass a handler to the service
Definition: bas.hpp:124
indicates no support for battery level notifications
Definition: bas.hpp:105
class to be mixed into the server instance
Definition: mixin.hpp:78
queues a notification of a characteristic as soon, as it was configured for notification.
Definition: characteristic_value.hpp:127
adds the ability to notify this characteristic.
Definition: characteristic_value.hpp:89