19 #ifndef __BLE_HEALTH_THERMOMETER_SERVICE_H__ 20 #define __BLE_HEALTH_THERMOMETER_SERVICE_H__ 24 #include "ble/GattServer.h" 26 #if BLE_FEATURE_GATT_SERVER 61 valueBytes(initialTemp),
68 ble.gattServer().addService(hrmService);
79 valueBytes.updateTemperature(temperature);
80 ble.gattServer().write(tempMeasurement.
getValueHandle(), valueBytes.getPointer(),
sizeof(TemperatureValueBytes));
89 ble.gattServer().write(tempLocation.
getValueHandle(),
reinterpret_cast<uint8_t *
>(&loc),
sizeof(uint8_t));
94 struct TemperatureValueBytes {
95 static const unsigned OFFSET_OF_FLAGS = 0;
96 static const unsigned OFFSET_OF_VALUE = OFFSET_OF_FLAGS +
sizeof(uint8_t);
97 static const unsigned SIZEOF_VALUE_BYTES =
sizeof(uint8_t) +
sizeof(
float);
99 static const unsigned TEMPERATURE_UNITS_FLAG_POS = 0;
100 static const unsigned TIMESTAMP_FLAG_POS = 1;
101 static const unsigned TEMPERATURE_TYPE_FLAG_POS = 2;
103 static const uint8_t TEMPERATURE_UNITS_CELSIUS = 0;
104 static const uint8_t TEMPERATURE_UNITS_FAHRENHEIT = 1;
106 TemperatureValueBytes(
float initialTemperature) : bytes() {
108 bytes[OFFSET_OF_FLAGS] = (TEMPERATURE_UNITS_CELSIUS << TEMPERATURE_UNITS_FLAG_POS) |
109 (
false << TIMESTAMP_FLAG_POS) |
110 (
false << TEMPERATURE_TYPE_FLAG_POS);
115 uint32_t temp_ieee11073 = quick_ieee11073_from_float(temp);
116 memcpy(&bytes[OFFSET_OF_VALUE], &temp_ieee11073,
sizeof(
float));
119 uint8_t *getPointer() {
123 const uint8_t *getPointer()
const {
133 static uint32_t quick_ieee11073_from_float(
float temperature) {
134 uint8_t exponent = 0xFE;
135 uint32_t mantissa = (uint32_t)(temperature * 100);
137 return (((uint32_t)exponent) << 24) | mantissa;
143 uint8_t bytes[SIZEOF_VALUE_BYTES];
148 TemperatureValueBytes valueBytes;
153 #endif // BLE_FEATURE_GATT_SERVER void updateTemperature(float temperature)
Update the temperature being broadcast.
UUID of the health thermometer.
GattAttribute::Handle_t getValueHandle() const
Get the characteristic's value attribute handle in the ATT table.
SensorLocation_t
Location of sensor on the body.
BLE Health Thermometer Service.
Representation of a GattServer characteristic.
void updateLocation(SensorLocation_t loc)
Update the location.
Representation of a GattServer service.
Entry namespace for all BLE API definitions.
Abstract away BLE-capable radio transceivers or SOCs.
HealthThermometerService(BLE &_ble, float initialTemp, uint8_t _location)
Add the Health Thermometer Service to an existing BLE object, initialize with temperature and locatio...