BlueToe
an alternative GATT/BLE implementation
Loading...
Searching...
No Matches
priorities_example.cpp

This examples shows, how to define priorities for charactertic notifications and indications.

#include <bluetoe/server.hpp>
#include <bluetoe/service.hpp>
#include <bluetoe/characteristic.hpp>
#include <bluetoe/outgoing_priority.hpp>
#include <cstdint>
// the enumeration of the possible axis
enum class axis {
X, Y, Z
};
// a handler that will use a sensor depending on the axis X
template < axis X >
struct acceleration_measurement_handler
{
/*
* This handler function will respond to requests to the acceleration sensors value or,
* when the server was requested to send a notification of this characteristic.
*/
std::uint8_t read_sensor_value( std::size_t, std::uint8_t* out_buffer, std::size_t& out_size );
/*
* This handler function will be called to fill the content of a temperatur alarm notification
* and is thus more important to reach a GATT client than the characteristic above.
*/
std::uint8_t temperature_alarm( std::size_t, std::uint8_t* out_buffer, std::size_t& out_size );
};
// the definition of a service that provides access to the value of a given access
template < class UUID, axis X >
using acceleration_measurement_service = bluetoe::service<
UUID,
acceleration_measurement_handler< X >,
&acceleration_measurement_handler< X >::read_sensor_value >,
>,
acceleration_measurement_handler< X >,
&acceleration_measurement_handler< X >::temperature_alarm >,
>,
// make sure, that temperature alarms are send out with higher priority
>
>;
/*
* A server with 3 similar acceleration services.
*/
using helicopter = bluetoe::server<
acceleration_measurement_service<
axis::X
>,
// this service messures the altitude and is thus more important than the other
// axis.
>,
acceleration_measurement_service<
axis::Y
>,
acceleration_measurement_service<
axis::Z
>
>;
int main()
{}
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
a 128-Bit UUID used to identify a characteristic.
Definition: characteristic.hpp:62
Defines priorities of notified or indicated characteristics.
Definition: outgoing_priority.hpp:160
Definition: characteristic_value.hpp:1071
class to be mixed into the server instance
Definition: mixin.hpp:78
adds the ability to notify this characteristic.
Definition: characteristic_value.hpp:89