Example, showing all possible alternatives to bind functions as read or write handler to a bluetooth characteristic.
#include <bluetoe/server.hpp>
#include <bluetoe/service.hpp>
#include <bluetoe/codes.hpp>
std::uint8_t read_blob_handler( std::size_t offset, std::size_t, std::uint8_t* out_buffer, std::size_t& out_size )
{
if ( offset == 0 )
{
*out_buffer = 42;
out_size = 1;
}
}
std::uint8_t read_handler( std::size_t, std::uint8_t* out_buffer, std::size_t& out_size )
{
*out_buffer = 42;
out_size = 1;
}
std::uint8_t write_blob_handler( std::size_t, std::size_t, const std::uint8_t* )
{
}
std::uint8_t write_handler( std::size_t, const std::uint8_t* )
{
}
struct static_handler {
static constexpr std::uint8_t code_word[] = { 'a', 'b', 'c' };
static std::uint8_t read( std::size_t offset, std::size_t read_size, std::uint8_t* out_buffer, std::size_t& out_size )
{
if ( offset > sizeof( code_word ) )
out_size = std::min( read_size, sizeof( code_word ) - offset );
std::copy( &code_word[ offset ], &code_word[ offset + out_size], out_buffer );
}
static std::uint8_t write( std::size_t, std::size_t, const std::uint8_t* )
{
}
};
struct handler {
std::uint8_t read_blob( std::size_t, std::size_t, std::uint8_t*, std::size_t& )
{
}
std::uint8_t write_blob( std::size_t, std::size_t, const std::uint8_t* )
{
}
std::uint8_t read_blob_c( std::size_t offset, std::size_t read_size, std::uint8_t* out_buffer, std::size_t& out_size ) const;
std::uint8_t read_blob_v( std::size_t offset, std::size_t read_size, std::uint8_t* out_buffer, std::size_t& out_size ) volatile;
std::uint8_t read_blob_vc( std::size_t offset, std::size_t read_size, std::uint8_t* out_buffer, std::size_t& out_size ) const volatile;
} handler_instance;
>,
>,
>,
>
>
> gatt_server;
A characteristic is a typed value that is accessable by a GATT client hosted by a GATT server.
Definition: characteristic.hpp:160
Root of the declaration of a GATT server.
Definition: server.hpp:85
a 128-Bit UUID used to identify a service.
Definition: service.hpp:57
a service with zero or more characteristics
Definition: service.hpp:150
@ invalid_offset
Definition: codes.hpp:189
@ success
Definition: codes.hpp:154
@ write_not_permitted
Definition: codes.hpp:169
binds a free function as a write handler for the given characteristic
Definition: characteristic_value.hpp:815
binds a free function as a read handler for the given characteristic
Definition: characteristic_value.hpp:692
binds a free function as a read handler for the given characteristic
Definition: characteristic_value.hpp:735
binds a free function as a write handler for the given characteristic
Definition: characteristic_value.hpp:778
Definition: characteristic_value.hpp:831
Definition: characteristic_value.hpp:951